Example #1
0
        public static void StartSession()
        {
            if (!Directory.Exists(HttpContext.Current.Server.MapPath("~/OneCSyncArch/")))
            {
                Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/OneCSyncArch/"));
            }

            var dataFile   = HttpContext.Current.Server.MapPath("~/OneCSyncArch/" + FileName);
            var writer     = new System.Xml.Serialization.XmlSerializer(typeof(XmlToOneC));
            var xml        = new XmlToOneC();
            var fileWriter = File.Create(dataFile);

            writer.Serialize(fileWriter, xml);
            fileWriter.Close();
        }
Example #2
0
        public static string GenerateCsv(string idListString, string invoiceNumber, string invoiceSeries, string invoiceDate)
        {
            var result        = String.Empty;
            var dm            = new DataManager();
            var idListToMySql = idListString.Split('-').ToList().Aggregate(String.Empty, (current, id) => current + "T.ID = " + id + " OR ");

            //читаем старый файл
            if (!Directory.Exists(HttpContext.Current.Server.MapPath("~/OneCSyncArch/")))
            {
                Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/OneCSyncArch/"));
            }

            var dataFile = HttpContext.Current.Server.MapPath("~/OneCSyncArch/" + FileName);
            var reader   = new System.Xml.Serialization.XmlSerializer(typeof(XmlToOneC));
            var xml      = new XmlToOneC
            {
                Invoices = new List <Invoice>()
            };

            if (File.Exists(dataFile))
            {
                var fileReaded = new StreamReader(dataFile);
                xml = (XmlToOneC)reader.Deserialize(fileReaded);
                fileReaded.Close();
            }
            //читаем старый файл

            var invoices = new Invoice
            {
                InvoiceNumber = invoiceNumber,
                InvoiceSeries = invoiceSeries,
                InvoiceDate   = invoiceDate,
                CustomOrders  = new List <CustomOrderToOneC>()
            };
            var fullSqlString = "SELECT * FROM `tickets` as T " +
                                "WHERE ((" + idListToMySql.Remove(idListToMySql.Length - 3) +
                                ") AND T.PrintNakl = '1' AND T.NotPrintInPril2 ='0') ";
            var rows = dm.QueryWithReturnDataSet(fullSqlString).Tables[0].Rows;

            foreach (DataRow row in rows)
            {
                var customOrderCost = row["AssessedCost"].ToString();
                if (!String.IsNullOrEmpty(row["AgreedCost"].ToString()) && Convert.ToInt32(row["AgreedCost"]) != 0)
                {
                    customOrderCost = row["AgreedCost"].ToString();
                }
                if (!String.IsNullOrEmpty(row["Pril2Cost"].ToString()) && Convert.ToInt32(row["Pril2Cost"]) != 0)
                {
                    customOrderCost = row["Pril2Cost"].ToString();
                }

                var customOrder = new CustomOrderToOneC
                {
                    CustomOrderSecureId = row["SecureID"].ToString(),
                    CustomOrderCost     = Convert.ToDecimal(customOrderCost),
                    CustomOrderDate     = OtherMethods.DateConvertWithDot(row["AdmissionDate"].ToString())
                };
                invoices.CustomOrders.Add(customOrder);
            }

            xml.Invoices.Add(invoices);

            var writer     = new System.Xml.Serialization.XmlSerializer(typeof(XmlToOneC));
            var fileWriter = File.Create(dataFile);

            writer.Serialize(fileWriter, xml);
            fileWriter.Close();


            return(result);
        }