public static bool LoadFromFile(string fileName, out stockType obj) { System.Exception exception = null; return LoadFromFile(fileName, out obj, out exception); }
public static bool LoadFromFile(string fileName, out stockType obj, out System.Exception exception) { return LoadFromFile(fileName, Encoding.UTF8, out obj, out exception); }
/// <summary> /// Deserializes xml markup from file into an stockType object /// </summary> /// <param name="fileName">string xml file to load and deserialize</param> /// <param name="obj">Output stockType object</param> /// <param name="exception">output Exception value if deserialize failed</param> /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns> public static bool LoadFromFile(string fileName, System.Text.Encoding encoding, out stockType obj, out System.Exception exception) { exception = null; obj = default(stockType); try { obj = LoadFromFile(fileName, encoding); return true; } catch (System.Exception ex) { exception = ex; return false; } }
public static bool Deserialize(string xml, out stockType obj) { System.Exception exception = null; return Deserialize(xml, out obj, out exception); }
/// <summary> /// Deserializes workflow markup into an stockType object /// </summary> /// <param name="xml">string workflow markup to deserialize</param> /// <param name="obj">Output stockType object</param> /// <param name="exception">output Exception value if deserialize failed</param> /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns> public static bool Deserialize(string xml, out stockType obj, out System.Exception exception) { exception = null; obj = default(stockType); try { obj = Deserialize(xml); return true; } catch (System.Exception ex) { exception = ex; return false; } }
void StoreStock() { //var prodDS = GetProductsDS(); var prodDS = UniqueStocks(); if (prodDS == null) return; var outDir = txtOutDir.Text + "/" + StockDir + "/"; if (!Directory.Exists(outDir)) Directory.CreateDirectory(outDir); dataPackType dp = new dataPackType(); dp.version = dataPackVersionType.Item20; dp.note = "Export ActiveStyle"; dp.id = "stock_" + DateTime.Now.Ticks + ".xml"; dp.ico = Properties.Settings.Default.ActiveStyle_ICO; dp.application = "MessageImporter"; List<dataPackItemType> dataPacks = new List<dataPackItemType>(); List<dataPackItemType> prijemky = new List<dataPackItemType>(); List<dataPackItemType> invoices = new List<dataPackItemType>(); List<prijemkaItemType> prijItems = new List<prijemkaItemType>(); List<invoiceItemType> invItems = new List<invoiceItemType>(); bool GBP_part = false; // referencna polozka StockItem refProd = null; var allProds = new List<StockItem>(); //allProds.AddRange(WaitingToUpdate); // waiting nepojdu do stock, iba invoice.. allProds.AddRange(prodDS); /////////////////////////////////////////////// UPDATE POLOZIEK /*foreach (var prod in toUpdate) { if (!prod.EquippedInv && prod.State != StockItemState.Waiting) // do exportu len produkty z vybavenych objednavok continue; var code = prod.ProductCode; if (string.IsNullOrEmpty(prod.Sklad) || string.IsNullOrEmpty(prod.FictivePrice)) { MessageBox.Show(this, "Not all 'Sklad' and/or 'Fiktívna cena' are filled! Missing in product with code: " + code, "Missing fields", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } dataPackItemType newDatapack = new dataPackItemType(); newDatapack.id = code+"_update"; newDatapack.ItemElementName = ItemChoiceType4.stock; newDatapack.version = dataPackItemVersionType.Item20; stockType stock = new stockType(); stock.version = stkVersionType.Item20; // header stock.stockHeader = new stockHeaderType(); // zakomentovane kvoli waiting produktom z DB, ktore tuto cenu nemaju //stock.stockHeader.purchasingPriceSpecified = true; //stock.stockHeader.purchasingPrice = prod.PriceEURnoTax; stock.stockHeader.sellingPrice = Common.GetPrice(prod.FictivePrice); stock.stockHeader.name = prod.Description; stock.stockHeader.nameComplement = prod.SizeInv; stock.stockHeader.isSalesSpecified = true; stock.stockHeader.isSales = boolean.@true; stock.stockHeader.orderName = prod.OrderDate.ToString("dd.MM.yyyy ") + prod.FromFile.ToString(); stock.stockHeader.isInternetSpecified = true; stock.stockHeader.isInternet = boolean.@true; stock.stockHeader.sellingRateVAT = vatRateType.high; stock.stockHeader.stockTypeSpecified = true; stock.stockHeader.stockType = stockTypeType.card; stock.stockHeader.code = code; stock.stockHeader.typePrice = new refType(); stock.stockHeader.typePrice.ids = Properties.Settings.Default.TypePrice; stock.stockHeader.storage = new refTypeStorage(); stock.stockHeader.storage.ids = prod.Sklad; // action type - update stock.actionType = new actionTypeType1(); stock.actionType.Item = new requestStockType(); stock.actionType.ItemElementName = ItemChoiceType3.update; stock.actionType.Item.filter = new filterStocksType(); stock.actionType.Item.filter.code = code; newDatapack.Item = stock; dataPacks.Add(newDatapack); }*/ /////////////////////////////////////////////// STORE POLOZIEK /*Fix pre opakujuce sa order number (alternativa by boli maily)*/ // MiKo zakomentovane 29.3.14 - waiting po novom.. /*foreach (var inv in AllInvoices) { foreach (var invItem in inv.InvoiceItems) { if (invItem.FromDB) { // var orderNum = (string.IsNullOrEmpty(invItem.Parent.OrderNumber.WaitingOrderNum) ? Common.ModifyOrderNumber2(prod.PairProduct.Parent.OrderNumber) : prod.WaitingOrderNum); var update = string.Format("UPDATE {0} SET VALID = \"-1\" WHERE ORDER_NUMBER=\"{1}\" AND INV_SKU = \"{2}\"", DBProvider.T_WAIT_STOCK, invItem.Parent.OrderNumber,invItem.invSKU);//prod.PairProduct.invSKU DBProvider.ExecuteNonQuery(update); } } }*/ foreach (var prod in allProds) { // referencny produkt bude prvy korektny if (refProd == null) refProd = prod; if (!prod.EquippedInv && prod.State != StockItemState.Waiting) // do exportu len produkty z vybavenych objednavok continue; /////////////////////////////////////////////////// stock item //var code = prod.ProductCode.Replace("/", ""); var code = prod.ProductCode; if (string.IsNullOrEmpty(prod.Sklad) || string.IsNullOrEmpty(prod.FictivePrice)) { MessageBox.Show(this, "Not all 'Sklad' and/or 'Fiktívna cena' are filled! Missing in product with code: " + code, "Missing fields", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } dataPackItemType newDatapack = new dataPackItemType(); newDatapack.id = code; newDatapack.ItemElementName = ItemChoiceType4.stock; newDatapack.version = dataPackItemVersionType.Item20; stockType stock = new stockType(); stock.version = stkVersionType.Item20; // defaultna akcia add stock.actionType = new actionTypeType1(); stock.actionType.Item = new requestStockType(); stock.actionType.Item.add = boolean.@true; stock.actionType.ItemElementName = ItemChoiceType3.update; // filter pridany 13.3.2014 stock.actionType.Item.filter = new filterStocksType(); stock.actionType.Item.filter.code = code; stock.actionType.Item.filter.store = new refType(); stock.actionType.Item.filter.store.ids = prod.Sklad; // header stock.stockHeader = new stockHeaderType(); stock.stockHeader.stockTypeSpecified = true; stock.stockHeader.stockType = stockTypeType.card; stock.stockHeader.code = code; stock.stockHeader.EAN = code; stock.stockHeader.isSalesSpecified = true; stock.stockHeader.isSales = boolean.@true; stock.stockHeader.isInternetSpecified = true; stock.stockHeader.isInternet = boolean.@true; stock.stockHeader.name = prod.Description; stock.stockHeader.nameComplement = prod.ItemNameInv; stock.stockHeader.unit = "ks"; stock.stockHeader.description = prod.Description; stock.stockHeader.description2 = prod.ItemNameInv; stock.stockHeader.storage = new refTypeStorage(); stock.stockHeader.storage.ids = prod.Sklad; // MiKo 29.3.14 - waiting sa ukladaju hned pri kliknuti na Waiting /*if (prod.State == StockItemState.Waiting) { try { var orderNum = (string.IsNullOrEmpty(prod.WaitingOrderNum) ? Common.ModifyOrderNumber2(prod.PairProduct.Parent.OrderNumber) : prod.WaitingOrderNum); var update = string.Format("UPDATE {0} SET ORDER_NUMBER = \"{1}\" WHERE INV_SKU=\"{2}\"", DBProvider.T_WAIT_STOCK, orderNum, prod.PairProduct.invSKU); DBProvider.ExecuteNonQuery(update); // ulozenie produktu do DB var insert = string.Format("INSERT INTO " + DBProvider.T_WAIT_STOCK + " VALUES ({0},\"{1}\",\"{2}\",\"{3}\",\"{4}\",{5})", "null", orderNum, prod.PairProduct.invSKU, prod.ProductCode, prod.Description, 1); log(insert); DBProvider.ExecuteNonQuery(insert); if (prod.PairProduct != null) DBProvider.InsertWaitingInvoice(prod.PairProduct); } catch (System.Exception ex) { MessageBox.Show(this, "Exception during inserting waiting product into database: " + ex.ToString(), "Execute insert", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }*/ stock.stockHeader.typePrice = new refType(); stock.stockHeader.typePrice.ids = Properties.Settings.Default.TypePrice; stock.stockHeader.purchasingPriceSpecified = true; stock.stockHeader.purchasingPrice = prod.PriceEURnoTax; stock.stockHeader.sellingPrice = Common.GetPrice(prod.SellPriceEUR); stock.stockHeader.limitMin = 0; stock.stockHeader.limitMax = 0; stock.stockHeader.orderName = prod.OrderDate.ToString("dd.MM.yyyy ") + prod.FromFile.ToString(); stock.stockHeader.orderQuantitySpecified = true; stock.stockHeader.orderQuantity = prod.Ord_Qty; stock.stockHeader.shortName = code; stock.stockHeader.guaranteeType = guaranteeTypeType.year; stock.stockHeader.guaranteeTypeSpecified = true; stock.stockHeader.guarantee = "2"; stock.stockHeader.yield = "604000"; //stock.stockHeader.note = prod.FictivePrice; stock.stockHeader.sellingPrice = Common.GetPrice(prod.FictivePrice); stock.stockHeader.nameComplement = prod.SizeInv; stock.stockHeader.sellingRateVAT = vatRateType.high; stock.stockHeader.acc = "132100"; newDatapack.Item = stock; dataPacks.Add(newDatapack); /////////////////////////////////////////////////// prijemky polozky prijemkaItemType prijItem = new prijemkaItemType(); prijItem.code = code; /*prijItem.quantitySpecified = true; prijItem.quantity = prod.Disp_Qty; prijItem.unit = "ks"; prijItem.stockItem = new stockItemType(); prijItem.stockItem.stockItem = new stockRefType(); prijItem.stockItem.stockItem.ids = code;*/ prijItems.Add(prijItem); /////////////////////////////////////////////////// faktura polozky invoiceItemType xmlItem = new invoiceItemType(); xmlItem.code = code; xmlItem.text = code; xmlItem.stockItem = new stockItemType(); xmlItem.stockItem.stockItem = new stockRefType(); xmlItem.stockItem.stockItem.ids = code; xmlItem.quantitySpecified = true; xmlItem.quantity = prod.Disp_Qty; invItems.Add(xmlItem); // GBP cast pojde ak existuje subor MSG s kurzom inym ako 1 if (!GBP_part && prod.FromFile.ExchRate != 1.0) GBP_part = true; } var ticks = DateTime.Now.Ticks; // zabalenie prijemok dataPackItemType prijmekaDatapack = new dataPackItemType(); prijmekaDatapack.id = "prijemka_" + ticks; prijmekaDatapack.ItemElementName = ItemChoiceType4.prijemka; prijmekaDatapack.version = dataPackItemVersionType.Item20; prijemkaType prijemka = new prijemkaType(); prijemka.version = priVersionType.Item20; prijemka.prijemkaHeader = new prijemkaHeaderType(); prijemka.prijemkaDetail = prijItems.ToArray(); prijemka.prijemkaSummary = new prijemkaSummaryType(); prijmekaDatapack.Item = prijemka; prijemky.Add(prijmekaDatapack); /////////////////////////////////////////////////// invoice dataPackItemType invDatapack = new dataPackItemType(); invDatapack.id = "invoice_" + ticks; invDatapack.ItemElementName = ItemChoiceType4.invoice; invDatapack.version = dataPackItemVersionType.Item20; invoiceType newInv = new invoiceType(); newInv.version = invVersionType.Item20; newInv.invoiceHeader = new invoiceHeaderType(); newInv.invoiceHeader.invoiceType = invoiceTypeType.receivedInvoice; newInv.invoiceHeader.dateAccounting = dtInvDate.Value; newInv.invoiceHeader.dateAccountingSpecified = true; newInv.invoiceHeader.dateOrder = DateTime.Now; newInv.invoiceHeader.dateOrderSpecified = true; newInv.invoiceHeader.dateTax = dtInvDate.Value; newInv.invoiceHeader.dateTaxSpecified = true; newInv.invoiceHeader.dateDue = dtInvDate.Value;// DateTime.Now.AddDays(Properties.Settings.Default.DueDateAdd); newInv.invoiceHeader.dateDueSpecified = true; newInv.invoiceHeader.dateDeliverySpecified = true; newInv.invoiceHeader.dateDelivery = dtInvDate.Value; newInv.invoiceHeader.accounting = new accountingType(); newInv.invoiceHeader.accounting.ids = "1 GBP"; newInv.invoiceHeader.classificationVAT = new classificationVATType(); newInv.invoiceHeader.classificationVAT.ids = "PN"; newInv.invoiceHeader.classificationVAT.classificationVATType1 = classificationVATTypeClassificationVATType.inland; newInv.invoiceHeader.text = refProd.FromFile.Type.ToString() + "_" + (allMessages.Count > 0 ? allMessages[0].OrderReference : "<err>"); newInv.invoiceHeader.partnerIdentity = new address(); switch (refProd.FromFile.Type) { case MSG_TYPE.SPORTS_DIRECT: newInv.invoiceHeader.partnerIdentity.id = Properties.Settings.Default.PartnerSports; break; case MSG_TYPE.MANDM_DIRECT: newInv.invoiceHeader.partnerIdentity.id = Properties.Settings.Default.PartnerMandM; break; case MSG_TYPE.GETTHELABEL: newInv.invoiceHeader.partnerIdentity.id = Properties.Settings.Default.PartnerLabel; break; default: newInv.invoiceHeader.partnerIdentity.id = "24"; break; } // polozky z faktury.. zatial fiktivne if (refProd.FromFile != null) { newInv.invoiceHeader.symVar = refProd.FromFile.OrderNumber; newInv.invoiceHeader.symPar = refProd.FromFile.OrderNumber; } newInv.invoiceHeader.numberOrder = "numOrder"; newInv.invoiceHeader.dateSpecified = true; newInv.invoiceHeader.date = dtInvDate.Value; newInv.invoiceHeader.paymentType = new paymentType(); newInv.invoiceHeader.paymentType.ids = "cashondelivery"; newInv.invoiceDetail = invItems.ToArray(); if (GBP_part) { newInv.invoiceSummary = new invoiceSummaryType(); newInv.invoiceSummary.foreignCurrency = new typeCurrencyForeign(); newInv.invoiceSummary.foreignCurrency.currency = new refType(); newInv.invoiceSummary.foreignCurrency.currency.ids = "GBP"; } // naplnenie cudzej meny ak je zadana if (refProd.FromFile != null && !string.IsNullOrEmpty(refProd.FromFile.Currency)) { if (newInv.invoiceSummary == null) { newInv.invoiceSummary = new invoiceSummaryType(); newInv.invoiceSummary.foreignCurrency = new typeCurrencyForeign(); newInv.invoiceSummary.foreignCurrency.currency = new refType(); } newInv.invoiceSummary.foreignCurrency.currency.ids = refProd.FromFile.Currency; } invDatapack.Item = newInv; invoices.Add(invDatapack); // polozky do xml //dataPacks.AddRange(prijemky); // 6.11.2012 prijemky nejdu do exportu dataPacks.AddRange(invoices); // datapack doprava pre faktury zo sportsdirect dataPackItemType shippingDatapack = null; if (refProd.FromFile.Type == MSG_TYPE.SPORTS_DIRECT) { shippingDatapack = new dataPackItemType(); shippingDatapack.id = "shipping_" + ticks; shippingDatapack.ItemElementName = ItemChoiceType4.invoice; shippingDatapack.version = dataPackItemVersionType.Item20; newInv = new invoiceType(); newInv.version = invVersionType.Item20; newInv.invoiceHeader = new invoiceHeaderType(); newInv.invoiceHeader.invoiceType = invoiceTypeType.receivedInvoice; newInv.invoiceHeader.dateAccounting = dtInvDate.Value; newInv.invoiceHeader.dateAccountingSpecified = true; newInv.invoiceHeader.dateOrder = dtInvDate.Value; newInv.invoiceHeader.dateOrderSpecified = true; newInv.invoiceHeader.dateTax = dtInvDate.Value; newInv.invoiceHeader.dateTaxSpecified = true; newInv.invoiceHeader.dateDue = DateTime.Now.AddDays(Properties.Settings.Default.DueDateAdd); newInv.invoiceHeader.dateDueSpecified = true; newInv.invoiceHeader.dateDeliverySpecified = true; newInv.invoiceHeader.dateDelivery = dtInvDate.Value; newInv.invoiceHeader.accounting = new accountingType(); newInv.invoiceHeader.accounting.ids = "1 GBP"; newInv.invoiceHeader.classificationVAT = new classificationVATType(); newInv.invoiceHeader.classificationVAT.ids = "PN"; newInv.invoiceHeader.classificationVAT.classificationVATType1 = classificationVATTypeClassificationVATType.inland; newInv.invoiceHeader.text = "SportsDirect_doprava_" + (allMessages.Count > 0 ? allMessages[0].OrderReference : "<err>"); newInv.invoiceHeader.partnerIdentity = new address(); newInv.invoiceHeader.partnerIdentity.id = "23"; // polozky z faktury.. zatial fiktivne if (refProd.FromFile != null) { newInv.invoiceHeader.symVar = refProd.FromFile.OrderNumber; newInv.invoiceHeader.symPar = refProd.FromFile.OrderNumber; } newInv.invoiceHeader.numberOrder = "numOrder"; newInv.invoiceHeader.dateSpecified = true; newInv.invoiceHeader.date = dtInvDate.Value; newInv.invoiceHeader.paymentType = new paymentType(); newInv.invoiceHeader.paymentType.ids = "cashondelivery"; // summary newInv.invoiceSummary = new invoiceSummaryType(); newInv.invoiceSummary.foreignCurrency = new typeCurrencyForeign(); if (refProd != null && refProd.FromFile != null) { newInv.invoiceSummary.foreignCurrency.currency = new refType(); newInv.invoiceSummary.foreignCurrency.currency.ids = refProd.FromFile.Currency; } // detail List<invoiceItemType> details = new List<invoiceItemType>(); invoiceItemType xmlItem = new invoiceItemType(); xmlItem.text = "doprava"; xmlItem.quantity = 1; xmlItem.quantitySpecified = true; /* presunute do summary ako foreign currency xmlItem.homeCurrency = new typeCurrencyHomeItem(); xmlItem.homeCurrency.unitPriceSpecified = true; xmlItem.homeCurrency.unitPrice = refProd.FromFile.Delivery; */ details.Add(xmlItem); newInv.invoiceDetail = details.ToArray(); shippingDatapack.Item = newInv; } if (shippingDatapack != null) dataPacks.Add(shippingDatapack); // datapack doprava dp.dataPackItem = dataPacks.ToArray(); try { // ulozenie zmien do xml var fname = outDir + dp.id; dp.SaveToFile(fname); if (!ValidateXML(fname)) { //File.Delete(fname); MessageBox.Show(this, "Validation failed! Generated xml file is not valid!", "Stock generation", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); return; } MessageBox.Show("Stock XML(s) generated!", "Save XML", MessageBoxButtons.OK, MessageBoxIcon.Information); }