public DetailReceipt(DetailReceipt model) { idReceipt = model.idReceipt; idCustomer = model.idCustomer; idProduct = model.idProduct; idTypeProduct = model.idTypeProduct; quantity = model.quantity; unitPriceSell = model.unitPriceSell; size = model.size; idDiscount = model.idDiscount; persentageDiscount = model.persentageDiscount; unitBonusScore = model.unitBonusScore; datePay = model.datePay; interest = model.interest; }
public DetailReceiptViewModel(DetailReceipt model, int order) : base(model) { DataClasses1DataContext dc = new DataClasses1DataContext(Properties.Settings.Default.ManagementProjectConnectionString); CustomerDb customer = (from p in dc.CustomerDbs where p.id == this.idCustomer select p).Single(); ProductDb product = (from p in dc.ProductDbs where p.id == this.idProduct select p).Single(); nameProduct = product.nameProduct; this.unitPriceSell = product.priceSell; this.unitBonusScore = product.bonusScore; this.sumScore = quantity * (int)unitBonusScore; this.order = order; this.stringUnitPrice = Unity.formatMoney((long)unitPriceSell); this.idProduct = product.id; this.idTypeProduct = product.category; //get discount, idTypeCustomer=1 mean all customer, idProduct=6 means all type product if (this.idDiscount == -1) { this.nameDiscount = "(Không có)"; } else { var discount = (from p in dc.DiscountDbs where p.id == this.idDiscount select p).Single(); this.nameDiscount = discount.nameDiscount; this.discountString = discount.percentageDiscount + "%"; } var x = (long)(quantity * (long)unitPriceSell) * (100.0 - persentageDiscount) / 100.0; this.sumMoney = (long)x; var y = sumMoney - product.priceImport * quantity; this.interest = (long)y; this.stringSumMoney = Unity.formatMoney(sumMoney); }
private void btnPay_Click(object sender, RoutedEventArgs e) { var customer = comboBoxCustomer.SelectedItem as CustomerDb; if (customer == null) { customer = (from p in dc.CustomerDbs where p.id == idUnregistedCustomer select p).Single(); // customer who unregist information } Receipt receipt = new Receipt(customer.id, DateTime.Now, sumMoney, sumScore); dc.Receipts.InsertOnSubmit(receipt); //insert new receipt try { dc.SubmitChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); } //get id of receipt has just inserted Receipt x = (from p in dc.Receipts where p.idCustomer == receipt.idCustomer && p.datePay == receipt.datePay && p.sumMoney == receipt.sumMoney && p.sumScore == receipt.sumScore select p).Single(); //add detail receipt into database for (int i = 0; i < listDetailReciept.Count; i++) { listDetailReciept[i].addInforDetailReceiptWhenPay(x.id, (int)x.idCustomer, x.datePay); //add more information DetailReceipt model = new DetailReceipt(listDetailReciept[i]); try { dc.DetailReceipts.InsertOnSubmit(model); //insert detail receipt dc.SubmitChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } //decrease quantity product, decrease sumProduct decreaseQuantityProductsInDb(); //increase bonus score and check type of customer increaseBonusScoreCustomerInDb(customer.id); try { dc.SubmitChanges(); reloadData(); dialogReceipt.IsOpen = false; } catch (Exception ex) { MessageBox.Show(ex.Message); } listDetailReciept = null; }