private void btn_AddMark_Click(object sender, EventArgs e) { Model.CustomerMarks mark = new Book.Model.CustomerMarks(); mark.CustomerMarksId = Guid.NewGuid().ToString(); mark.InvoicePackingId = this._invoicePacking.InvoicePackingId; this._invoicePacking.Marks.Add(mark); this.bindingSourceMarks.Position = this.bindingSourceMarks.IndexOf(mark); this.gridControl2.RefreshDataSource(); }
/// <summary> /// 添加客户订单 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void simpleButton1_Click(object sender, EventArgs e) { XS.SearcharInvoiceXSForm f = new Book.UI.Invoices.XS.SearcharInvoiceXSForm(); Model.CustomerProducts cp = null; if (f.ShowDialog(this) == DialogResult.OK) { if (f.key != null && f.key.Count > 0) { Model.CustomerMarks mark = null; Model.InvoicePackingDetail packingDetail = null; //if (this._invoicePacking.Details != null && this._invoicePacking.Details.Count > 1) //Id = 65 + this._invoicePacking.Details.Count; foreach (Model.InvoiceXODetail detail in f.key) { if (this._invoicePacking.Details.Where(d => d.InvoiceXODetailId == detail.InvoiceXODetailId).ToList().Count > 0) { MessageBox.Show("已存在相同的訂單!", this.Text, MessageBoxButtons.OK); continue; } packingDetail = new Book.Model.InvoicePackingDetail(); //packingDetail.InvoicePackingDetailId = this._invoicePackingDetailManager.GetId(); //this._invoicePackingDetailManager.TiGuiExists(packingDetail); packingDetail.InvoicePackingDetailId = Guid.NewGuid().ToString(); packingDetail.InvoicePackingId = this._invoicePacking.InvoicePackingId; packingDetail.HandbookId = detail.HandbookId; packingDetail.HandbookProductId = detail.HandbookProductId; packingDetail.Product = detail.Product; packingDetail.ProductId = detail.ProductId; packingDetail.Customer = detail.Invoice.Customer; packingDetail.CustomerId = detail.Invoice.CustomerId; packingDetail.XOCustomer = detail.Invoice.xocustomer; packingDetail.XOCustomerId = detail.Invoice.xocustomerId; packingDetail.UnitPrice = detail.InvoiceXODetailPrice; packingDetail.InvoiceXOQuantity = detail.InvoiceXODetailQuantity0 == null ? 0 : detail.InvoiceXODetailQuantity0; packingDetail.PackingNum = packingDetail.InvoiceXOQuantity; packingDetail.HasFPQuantity = 0; packingDetail.Amount = Convert.ToDecimal(packingDetail.PackingNum) * packingDetail.UnitPrice; packingDetail.InvoiceXOId = detail.InvoiceId; packingDetail.InvoiceXODetailId = detail.InvoiceXODetailId; packingDetail.ProductUnit = detail.InvoiceProductUnit; packingDetail.WeightUnit = "KGS"; packingDetail.PriceUnit = "USD"; packingDetail.BGHandBookProduct = new BL.BGHandbookDetail1Manager().SelectProName(detail.HandbookId, detail.HandbookProductId); if (detail.Invoice.CustomerMarks != null && this._invoicePacking.Marks.Where(d => d.CustomerMarksName == detail.Invoice.CustomerMarks).ToList().Count < 1) { mark = new Book.Model.CustomerMarks(); mark.CustomerMarksId = Guid.NewGuid().ToString(); mark.InvoicePackingId = this._invoicePacking.InvoicePackingId; mark.CustomerMarksName = detail.Invoice.CustomerMarks; this._invoicePacking.Marks.Add(mark); } if (packingDetail.Product != null && !(string.IsNullOrEmpty(packingDetail.Product.CustomerProductName)) && !(string.IsNullOrEmpty(packingDetail.Product.CustomerId))) { cp = new BL.CustomerProductsManager().SelectByCustomerProductProceId(packingDetail.ProductId); } if (cp != null) { packingDetail.BLong = cp.BLong; packingDetail.BWidth = cp.BWide; packingDetail.BHeight = cp.BHigh; packingDetail.UnitJWeight = cp.JWeight; packingDetail.UnitMWeight = cp.MWeight; packingDetail.UnitCaiji = cp.Caiji; packingDetail.UnitNum = cp.PackingSpecification; if (packingDetail.UnitNum > packingDetail.InvoiceXOQuantity) { packingDetail.BoxNum = 1; packingDetail.AllJweight = Math.Round((double)(packingDetail.UnitJWeight * packingDetail.InvoiceXOQuantity / packingDetail.UnitNum), 4); packingDetail.AllMWeight = Math.Round((double)(packingDetail.UnitMWeight * packingDetail.InvoiceXOQuantity / packingDetail.UnitNum), 4); packingDetail.AllCaiji = Math.Round((double)(packingDetail.UnitCaiji * packingDetail.InvoiceXOQuantity / packingDetail.UnitNum), 4); packingDetail.PackingNum = packingDetail.InvoiceXOQuantity == null ? 0 : packingDetail.InvoiceXOQuantity; packingDetail.Amount = Convert.ToDecimal(packingDetail.PackingNum) * packingDetail.UnitPrice; } else { packingDetail.BoxNum = Convert.ToInt32(Math.Truncate(Convert.ToDouble(detail.InvoiceXODetailQuantity0 / packingDetail.UnitNum))); packingDetail.AllJweight = packingDetail.UnitJWeight * packingDetail.BoxNum; packingDetail.AllMWeight = packingDetail.UnitMWeight * packingDetail.BoxNum; packingDetail.AllCaiji = packingDetail.UnitCaiji * packingDetail.BoxNum; packingDetail.PackingNum = (packingDetail.UnitNum * packingDetail.BoxNum) == null ? packingDetail.InvoiceXOQuantity : packingDetail.UnitNum * packingDetail.BoxNum; packingDetail.Amount = Convert.ToDecimal(packingDetail.PackingNum) * packingDetail.UnitPrice; } } //if (packingDetail.UnitNum == 0 || packingDetail.UnitNum == null) //{ // MessageBox.Show("請設置該產品的成箱數量!\r" + (packingDetail.Product == null ? null : packingDetail.Product), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); // //return; //} //else //{ // packingDetail.BoxNum = (int)(detail.InvoiceXODetailQuantity0 / this.PackingSpecification); // //packingDetail.HandPackingId = Convert.ToChar(Id).ToString() + " 1" + "-" + packingDetail.BoxNum.ToString(); // packingDetail.PackingNum = this.PackingSpecification * packingDetail.BoxNum; // packingDetail.AllJweight = packingDetail.UnitJWeight * packingDetail.BoxNum; // packingDetail.AllMWeight = packingDetail.UnitMWeight * packingDetail.BoxNum; // packingDetail.AllCaiji = packingDetail.UnitCaiji * packingDetail.BoxNum; //} this._invoicePacking.Details.Add(packingDetail); if (packingDetail.UnitNum > 0 && packingDetail.InvoiceXOQuantity % packingDetail.UnitNum != 0 && packingDetail.UnitNum < packingDetail.InvoiceXOQuantity) { Model.InvoicePackingDetail invoicePackingDetail = new Book.Model.InvoicePackingDetail(); //invoicePackingDetail.InvoicePackingDetailId = this._invoicePackingDetailManager.GetId(); //this._invoicePackingDetailManager.TiGuiExists(invoicePackingDetail); invoicePackingDetail.InvoicePackingDetailId = Guid.NewGuid().ToString(); invoicePackingDetail.InvoicePackingId = this._invoicePacking.InvoicePackingId; invoicePackingDetail.HandbookId = detail.HandbookId; invoicePackingDetail.HandbookProductId = detail.HandbookProductId; invoicePackingDetail.Product = packingDetail.Product; invoicePackingDetail.ProductId = packingDetail.ProductId; invoicePackingDetail.Customer = packingDetail.Customer; invoicePackingDetail.CustomerId = packingDetail.CustomerId; invoicePackingDetail.XOCustomer = packingDetail.XOCustomer; invoicePackingDetail.XOCustomerId = packingDetail.XOCustomerId; invoicePackingDetail.UnitPrice = packingDetail.UnitPrice; invoicePackingDetail.InvoiceXOQuantity = detail.InvoiceXODetailQuantity0 == null ? 0 : detail.InvoiceXODetailQuantity0; invoicePackingDetail.PackingNum = invoicePackingDetail.InvoiceXOQuantity % packingDetail.UnitNum; invoicePackingDetail.HasFPQuantity = 0; invoicePackingDetail.Amount = Convert.ToDecimal(invoicePackingDetail.PackingNum) * invoicePackingDetail.UnitPrice; invoicePackingDetail.ProductUnit = packingDetail.ProductUnit; invoicePackingDetail.BoxNum = 1; invoicePackingDetail.BLong = packingDetail.BLong; invoicePackingDetail.BWidth = packingDetail.BWidth; invoicePackingDetail.BHeight = packingDetail.BHeight; invoicePackingDetail.UnitJWeight = Math.Round((double)(packingDetail.UnitJWeight * invoicePackingDetail.PackingNum / packingDetail.UnitNum), 4); invoicePackingDetail.UnitMWeight = Math.Round((double)(packingDetail.UnitMWeight * invoicePackingDetail.PackingNum / packingDetail.UnitNum), 4); invoicePackingDetail.UnitCaiji = Math.Round((double)(packingDetail.UnitCaiji * invoicePackingDetail.PackingNum / packingDetail.UnitNum), 4); invoicePackingDetail.AllJweight = invoicePackingDetail.UnitJWeight; invoicePackingDetail.AllMWeight = invoicePackingDetail.UnitMWeight; invoicePackingDetail.AllCaiji = invoicePackingDetail.UnitCaiji; invoicePackingDetail.WeightUnit = "KGS"; invoicePackingDetail.PriceUnit = "USD"; invoicePackingDetail.BGHandBookProduct = packingDetail.BGHandBookProduct; this._invoicePacking.Details.Add(invoicePackingDetail); } } } double amount = 0; foreach (var item in this._invoicePacking.Details) { amount += Convert.ToDouble(item.Amount); } this.txt_TotalAmount.Text = amount.ToString(); this.bindingSourceDetail.DataSource = _invoicePacking.Details; this.gridControl1.RefreshDataSource(); this.bindingSourceDetail.MoveLast(); } }