public static bool generateDeliveryNoteXml(DeliveryNotes deliveryNotes, string pathToXmlFile) { XmlSerializer xs = new XmlSerializer(typeof(DeliveryNotes)); MemoryStream memory = new MemoryStream(); xs.Serialize(memory, deliveryNotes); FileStream fs = null; try { fs = new FileStream(@pathToXmlFile, FileMode.Create); memory.WriteTo(fs); fs.Flush(); return(true); } catch (Exception) { return(false); } finally { //fs.Close(); memory.Close(); } }
public bool Insert(phieuxuat obj) { using (CTyPHSachEntities db = new CTyPHSachEntities()) { try { int id = db.DeliveryNotes.Max(x => x.DeliveryNoteID) + 10; var ob = new DeliveryNotes(); ob.DeliveryNoteID = id; ob.deliverName = obj.nguoigia; ob.receiverName = obj.nguoitao; ob.totalPrice = obj.giatri; ob.AgencyID = obj.id_dl; ob.endeliverdate = obj.hanthanhtoan; ob.deliverDateCreated = obj.ngayxuat; db.DeliveryNotes.Add(ob); List <DeliveryDetails> rd = new List <DeliveryDetails>(); foreach (var item in obj.chitiet) { var ct = new DeliveryDetails(); var s = db.Books.Find(item.masach); s.amount = s.amount - item.sl; ct.BookID = item.masach; ct.DeliveryNoteID = id; ct.amount = item.sl; ct.price = s.receiptPrice; rd.Add(ct); } db.DeliveryDetails.AddRange(rd); if (obj.thanhtoan > 0) { var tt = new Debts(); tt.DeliveryNoteID = id; tt.dateCreated = obj.ngayxuat; tt.thanhtoan = obj.thanhtoan; tt.id_dl = obj.id_dl; tt.creatorName = obj.nguoitao; db.Debts.Add(tt); } db.SaveChanges(); return(true); } catch (Exception ex) { return(false); } } }
public virtual int _GetUniqueIdentifier() { var hashCode = 399326290; hashCode = hashCode * -1521134295 + (Id?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (Orders.GetHashCode()); hashCode = hashCode * -1521134295 + (DeliveryNotes.GetHashCode()); hashCode = hashCode * -1521134295 + (CustomsDocuments.GetHashCode()); hashCode = hashCode * -1521134295 + (IntermediaryLogistics.GetHashCode()); hashCode = hashCode * -1521134295 + (Invoices.GetHashCode()); hashCode = hashCode * -1521134295 + (PoDs.GetHashCode()); hashCode = hashCode * -1521134295 + (PaymentData.GetHashCode()); return(hashCode); }
private void btnConvert_Click(object sender, EventArgs e) { if (!File.Exists(txtCustomerDataFilePath.Text)) { MessageBox.Show(string.Format("Cannot find the customer data file {0}.\n\nPlease, make sure the path is correct and try again.", txtCustomerDataFilePath.Text), "Customer data file not found", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (CodeManager.rtfDocumentIsAlreadyOpen(txtRtfSource.Text)) { MessageBox.Show(string.Format("Impossible to complete the task because the selected file: {0}, is currently opened in Microsoft Word.\n\nPlease, close Microsoft Word or the file and try again.", txtRtfSource.Text), "RTF document is currently open", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { try { toggleGuiState(false); RtfParser parser = new RtfParser(@txtRtfSource.Text); DeliveryNotes deliveryNotesXml = new DeliveryNotes(); //<?xml version="1.0"?> //<DeliveryNotes // xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" // xmlns:xsd="http://www.w3.org/2001/XMLSchema"> //<DeliveryNotes> // <Company> deliveryNotesXml.Company.Name = parser.Company["Name"].ToString(); // <Address><Address/> deliveryNotesXml.Company.Address = parser.Company["Address"].ToString(); // <Postcode></Postcode> deliveryNotesXml.Company.Zip = parser.Company["Zip"].ToString(); // <City></City> deliveryNotesXml.Company.City = parser.Company["City"].ToString(); // <Province></Province> deliveryNotesXml.Company.State = parser.Company["State"].ToString(); // <Country></Country> deliveryNotesXml.Company.Country = parser.Company["Country"].ToString(); // <FiscalCode><FiscalCode/> //fattDocumentXml.Company.FiscalCode = parser.Company["FiscalCode"].ToString(); // <VatCode></VatCode> // </Company> //fattDocumentXml.Company.VatCode = parser.Company["VatCode"].ToString(); // <Documents> foreach (Dictionary <string, string> d in parser.Documents) { // <Document> Document document = new Document(); // <CustomerCode></CustomerCode> document.CustomerCode = d["CustomerCode"]; // <CustomerName><CustomerName/> document.SoldToName = d["CustomerName"]; // <DeliveryName></DeliveryName> document.ShipToName = d["DeliveryName"]; // <DeliveryAddress></DeliveryAddress> document.ShipToAddress = d["DeliveryAddress"]; // <DeliveryPostcode></DeliveryPostcode> document.ShipToZip = d["DeliveryZip"]; // <DeliveryCity></DeliveryCity> document.ShipToCity = d["DeliveryCity"]; // <DeliveryProvince></DeliveryProvince> document.ShipToState = d["DeliveryState"]; // <Date></Date> document.Date = d["Date"]; // <Number></Number> document.Number = d["Number"]; //document.TransportReason = d["TransportReason"]; //document.TransportDateTime = d["TransportDateTime"]; bool messageAlreadyShown = false; // <Rows> foreach (Dictionary <string, string> r in parser.Rows) { //<Row> Row row = new Row(); // <Code></Code> row.Code = r["Code"]; // <Description></Description> row.Description = r["Description"]; // <Qty></Qty> row.Qty = r["Qty"].Split(',')[0]; if (r["Discounts"] != string.Empty) { if (r["Discounts"] == "CUSTOMER_NOT_FOUND") { if (!messageAlreadyShown) { MessageBox.Show("Warning: could not read discount for this customer because he/she was not found in the customer data file. \n\nThe XML file will be generated anyway.", "Customer not found", MessageBoxButtons.OK, MessageBoxIcon.Warning); messageAlreadyShown = true; } } else { //<"Discounts></"Discounts> row.Discounts = r["Discounts"]; } } // </Row> //</Rows> document.Rows.Add(row); } //</Document> deliveryNotesXml.Documents.Add(document); } if (CodeManager.generateDeliveryNoteXml(deliveryNotesXml, txtXmlDestination.Text)) { MessageBox.Show("XML file succesfully created", "Conversion finished", MessageBoxButtons.OK, MessageBoxIcon.Information); toggleGuiState(true); } else { MessageBox.Show("An error has occurred while saving the XML file. The application will now close.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } } catch (Exception ex) { MessageBox.Show( string.Format("The following error has occurred: {0}. The application will now close.", ex.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } } // End if (CodeManager.rtfDocumentIsAlreadyOpen(txtRtfSource.Text)) } // End private void btnConvert_Click(object sender, EventArgs e)