using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Data.SqlTypes;
using DataAccessLayer;
namespace BusinessLayer
{
public class clsSalesHistory
{
public Messagers.Response TransferData(string strShop_ID,string strShop_Group_ID,string strSan_ID,string[] strISBN, double[] dUnit_Price, double[] dCost_Price,
double[] dSelling_Price,double[] dRR_Price,double[] dDiscount,double[] dSales_Tax,double[] dQuantity_Sold)
{
string strXML;
SqlParameter Param;
List
UTF8Encoding encoding = new UTF8Encoding();
MemoryStream mem = new MemoryStream();
XmlTextWriter xWriter = new XmlTextWriter(mem, Encoding.UTF8);
xWriter.Formatting = Formatting.Indented;
xWriter.WriteProcessingInstruction("xml", "version=\"1.0\" ");
GenerateInfo[] PassCollect = new GenerateInfo[strISBN.Length];
clsDbConnectivity objDataAccess = new clsDbConnectivity();
Messagers.Response objResponse = new BusinessLayer.Messagers.Response();
try
{
for (int i = 0; i <= strISBN.Length - 1; i++)
{
PassCollect[i].ISBN = strISBN[i];
PassCollect[i].Unit_Price = dUnit_Price[i];
PassCollect[i].Cost_Price = dCost_Price[i];
PassCollect[i].Selling_Price = dSelling_Price[i];
PassCollect[i].RR_Price = dRR_Price[i];
PassCollect[i].Discount = dDiscount[i];
PassCollect[i].Sales_Tax = dSales_Tax[i];
PassCollect[i].Quantity_Sold = dQuantity_Sold[i];
}
XmlSerializer xSerializer = new XmlSerializer(typeof(GenerateInfo[]));
XmlSerializerNamespaces xSeNameSpace = new XmlSerializerNamespaces();
xSeNameSpace.Add(string.Empty, string.Empty);
xSerializer.Serialize(xWriter, PassCollect,xSeNameSpace);
mem = (MemoryStream)xWriter.BaseStream;
strXML = encoding.GetString(mem.ToArray());
mem.Close();
Param = new SqlParameter("@vcShop_ID", SqlDbType.VarChar, 100);
Param.Value =strShop_ID;
ParamCollection.Add(Param);
Param = new SqlParameter("@vcShop_Group_ID", SqlDbType.VarChar, 100);
Param.Value =strShop_Group_ID;
ParamCollection.Add(Param);
Param = new SqlParameter("@vcSan_ID", SqlDbType.VarChar, 100);
Param.Value =strSan_ID;
ParamCollection.Add(Param);
Param = new SqlParameter("@xmlParam", SqlDbType.NText);
Param.Value = strXML;
ParamCollection.Add(Param);
objDataAccess.CommandName = "spSaveSalesBulkInfo";
objDataAccess.CommandParamCollection = ParamCollection;
if (objDataAccess.ExecuteSqlCommand())
{
objResponse.Acknowledgment = true;
}
else
{
objResponse.Acknowledgment = false;
}
}
catch
{
objResponse.Acknowledgment = false;
objResponse.AckMessage = objDataAccess.AcknowledgmentMsg;
}
return objResponse;
}
public struct GenerateInfo
{
public string ISBN;
public double Unit_Price;
public double Cost_Price;
public double Selling_Price;
public double RR_Price;
public double Discount;
public double Sales_Tax;
public double Quantity_Sold;
}
}
Excellent post.
ReplyDeleteThis is really helpful when we required customizing XmlSerializer output for different formats/systems.