//muiBtnOK_Click private void muiBtnOK_Click(object sender, RoutedEventArgs e) { if (StaticClass.GeneralClass.list_ec_tb_order_general.Count == 0) { tblNotification.Text = FindResource("select_least_order").ToString(); } else { if (thread_delete != null && thread_delete.ThreadState == ThreadState.Running) { } else { thread_delete = new Thread(() => { try { int result_order = 0; int result_orderdetail = 0; for (int i = 0; i < StaticClass.GeneralClass.list_ec_tb_order_general.Count; i++) { EC_tb_Order ec_tb_order = new EC_tb_Order(); ec_tb_order.OrderID = StaticClass.GeneralClass.list_ec_tb_order_general[i].OrderID; if (bus_tb_order.DeleteOrder(ec_tb_order) == 1) { result_order++; if (bus_tb_orderdetail.DeleteAllOrderDetail("WHERE [OrderID]=" + StaticClass.GeneralClass.list_ec_tb_order_general[i].OrderID) > 0) { result_orderdetail++; } } } if (result_order == result_orderdetail) { StaticClass.GeneralClass.flag_check_delete_order_orderdetail = true; StaticClass.GeneralClass.list_ec_tb_order_general.Clear(); if (btndelete_delegate != null) { btndelete_delegate(true); this.Dispatcher.Invoke((Action)(() => { this.Close(); })); } } else { this.tblNotification.Dispatcher.Invoke((Action)(() => { this.tblNotification.Text = FindResource("error_delete").ToString(); })); } } catch (Exception ex) { this.tblNotification.Dispatcher.Invoke((Action)(() => { this.tblNotification.Text = ex.Message; })); } }); thread_delete.Start(); } } }
//PayOrder private bool PayOrder() { int quantity = StaticClass.GeneralClass.list_ec_tb_orderdetail_general.Count; bool result = false; if (quantity > 0) { //create Order EC_tb_Order ec_tb_order = new EC_tb_Order(); ec_tb_order.CustomerID = StaticClass.GeneralClass.customerid_general; ec_tb_order.CustomerName = StaticClass.GeneralClass.customername_general; ec_tb_order.Quatity = quantity; ec_tb_order.OrderDate = System.DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); ec_tb_order.SalesPersonID = StaticClass.GeneralClass.salespersonid_login_general; ec_tb_order.SalesPersonName = StaticClass.GeneralClass.salespersonname_login_general; this.Dispatcher.Invoke((Action)(() => { ec_tb_order.PaymentID = list_ec_payment.Find(x => x.RdoCard.IsChecked.Value == true).PaymentID; ec_tb_order.PaymentName = list_ec_payment.Find(x => x.RdoCard.IsChecked.Value == true).Card; })); ec_tb_order.DiscountType = StaticClass.GeneralClass.discounttype_general; ec_tb_order.Discount = StaticClass.GeneralClass.discount_general; ec_tb_order.TotalDiscount = StaticClass.GeneralClass.totaldiscount_general; ec_tb_order.TotalTax = StaticClass.GeneralClass.totaltaxrate_general; ec_tb_order.TotalAmount = total; if (bus_tb_order.InsertOrder(ec_tb_order, StaticClass.GeneralClass.flag_database_type_general) == 1) { int num_orderdetail_inserted = 0; foreach (EC_tb_OrderDetail ec_tb_orderdetail in StaticClass.GeneralClass.list_ec_tb_orderdetail_general) { ec_tb_order.OrderID = bus_tb_order.GetMaxOrderID(""); ec_tb_orderdetail.OrderID = ec_tb_order.OrderID; if (bus_tb_orderdetail.InsertOrderDetail(ec_tb_orderdetail, StaticClass.GeneralClass.flag_database_type_general) == 1) { num_orderdetail_inserted++; //update InventoryCount for Product EC_tb_Product ec_tb_product = new EC_tb_Product(); ec_tb_product.ProductID = ec_tb_orderdetail.ProductID; ec_tb_product.InventoryCount = ec_tb_orderdetail.Qty; bus_tb_product.UpdateInventoryCount(ec_tb_product); } } //if insert orderdetai success if (num_orderdetail_inserted > 0) { result = true; } //if insert orderdetail failed else { if (bus_tb_order.DeleteOrder(ec_tb_order) == 1) { result = false; } } } } return(result); }
//muiBtnOK_Click private void muiBtnOK_Click(object sender, RoutedEventArgs e) { if (StaticClass.GeneralClass.list_ec_tb_orderdetail_general.Count == 0) { tblNotification.Text = FindResource("select_least_order_detail").ToString(); return; } else { try { int orderdetail_qty_root = bus_tb_orderdetail.GetOrderDetail("WHERE [OrderID] = " + StaticClass.GeneralClass.orderdetailid_general).Rows.Count; int result = 0; for (int i = 0; i < StaticClass.GeneralClass.list_ec_tb_orderdetail_general.Count; i++) { EC_tb_OrderDetail ec_tb_orderdetail = new EC_tb_OrderDetail(); ec_tb_orderdetail.OrderID = StaticClass.GeneralClass.list_ec_tb_orderdetail_general[i].OrderID; ec_tb_orderdetail.ProductID = StaticClass.GeneralClass.list_ec_tb_orderdetail_general[i].ProductID; //ec_tb_orderdetail.InputID = StaticClass.GeneralClass.list_ec_tb_orderdetail_general[i].InputID; if (bus_tb_orderdetail.DeleteOrderDetail(ec_tb_orderdetail) == 1) { result++; } } if (result == orderdetail_qty_root) { EC_tb_Order ec_tb_order = new EC_tb_Order(); ec_tb_order.OrderID = StaticClass.GeneralClass.orderdetailid_general; if (bus_tb_order.DeleteOrder(ec_tb_order) == 1) { } else { tblNotification.Text = FindResource("cannot_delete_order").ToString(); return; } } //update table order if ((result > 0) && (result < orderdetail_qty_root)) { DataTable dt_tb_order = bus_tb_order.GetOrder("WHERE [OrderID] = " + StaticClass.GeneralClass.orderdetailid_general); DataTable dt_tb_orderdetail = bus_tb_orderdetail.GetOrderDetail("WHERE [OrderID] = " + StaticClass.GeneralClass.orderdetailid_general); int quantity = 0; decimal total_tax = 0; decimal total = 0; decimal total_discount = 0; decimal total_amount = 0; foreach (DataRow datarow in dt_tb_orderdetail.Rows) { quantity += Convert.ToInt32(datarow["Qty"].ToString()); total_tax += Convert.ToDecimal(datarow["Tax"].ToString()); total += Convert.ToDecimal(datarow["Total"].ToString()); } if (Convert.ToInt32(dt_tb_order.Rows[0]["DiscountType"].ToString()) == 1) { total_discount = Convert.ToDecimal(dt_tb_order.Rows[0]["Discount"].ToString()) * total / 100; } else { total_discount = Convert.ToDecimal(dt_tb_order.Rows[0]["Discount"].ToString()); } total_amount = total - total_discount + total_tax; EC_tb_Order ec_tb_order = new EC_tb_Order(); ec_tb_order.OrderID = Convert.ToInt32(dt_tb_order.Rows[0]["OrderID"].ToString()); ec_tb_order.CustomerID = Convert.ToInt32(dt_tb_order.Rows[0]["CustomerID"].ToString()); ec_tb_order.CustomerName = dt_tb_order.Rows[0]["CustomerName"].ToString(); ec_tb_order.Quatity = quantity; ec_tb_order.OrderDate = dt_tb_order.Rows[0]["OrderDate"].ToString(); ec_tb_order.SalesPersonID = Convert.ToInt32(dt_tb_order.Rows[0]["SalespersonID"].ToString()); ec_tb_order.SalesPersonName = dt_tb_order.Rows[0]["SalespersonName"].ToString(); ec_tb_order.PaymentID = Convert.ToInt32(dt_tb_order.Rows[0]["PaymentID"].ToString()); ec_tb_order.PaymentName = dt_tb_order.Rows[0]["PaymentName"].ToString(); ec_tb_order.DiscountType = Convert.ToInt32(dt_tb_order.Rows[0]["DiscountType"].ToString()); ec_tb_order.Discount = Convert.ToDecimal(dt_tb_order.Rows[0]["Discount"].ToString()); ec_tb_order.TotalDiscount = total_discount; ec_tb_order.TotalTax = total_tax; ec_tb_order.TotalAmount = total_amount; bus_tb_order.UpdateOrder(ec_tb_order, StaticClass.GeneralClass.flag_database_type_general); } if (btndelete_delegate != null) { StaticClass.GeneralClass.flag_check_delete_order_orderdetail = true; StaticClass.GeneralClass.list_ec_tb_orderdetail_general.Clear(); btndelete_delegate(true); this.Close(); } } catch (Exception ex) { tblNotification.Text = ex.Message; } } }
private bool PayOrder() { int quantity = StaticClass.GeneralClass.list_ec_tb_orderdetail_general.Count; bool result = false; if (quantity > 0) { //create Order EC_tb_Order ec_tb_order = new EC_tb_Order(); ec_tb_order.CustomerID = StaticClass.GeneralClass.customerid_general; ec_tb_order.CustomerName = StaticClass.GeneralClass.customername_general; ec_tb_order.Quatity = quantity; ec_tb_order.OrderDate = System.DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt"); ec_tb_order.SalesPersonID = StaticClass.GeneralClass.salespersonid_login_general; ec_tb_order.SalesPersonName = StaticClass.GeneralClass.salespersonname_login_general; this.Dispatcher.Invoke((Action)(() => { ShellOutModel shellPayMent = (ShellOutModel)lstShellOut.Items[0]; ec_tb_order.PaymentID = Convert.ToInt16(shellPayMent.PaymentId); //paymentid; ec_tb_order.PaymentName = shellPayMent.PaymentName; //paymentname; })); ec_tb_order.DiscountType = StaticClass.GeneralClass.discounttype_general; ec_tb_order.Discount = StaticClass.GeneralClass.discount_general; ec_tb_order.TotalDiscount = StaticClass.GeneralClass.totaldiscount_general; ec_tb_order.TotalTax = StaticClass.GeneralClass.totaltaxrate_general; ec_tb_order.TotalAmount = total; if (bus_tb_order.InsertOrder(ec_tb_order, StaticClass.GeneralClass.flag_database_type_general) == 1) { int num_orderdetail_inserted = 0; foreach (EC_tb_OrderDetail ec_tb_orderdetail in StaticClass.GeneralClass.list_ec_tb_orderdetail_general) { //ec_tb_orderdetail.ID = bus_tb_orderdetail.GetMaxID("") + 1; ec_tb_order.OrderID = bus_tb_order.GetMaxOrderID(""); ec_tb_orderdetail.OrderID = ec_tb_order.OrderID; if (bus_tb_orderdetail.InsertOrderDetail(ec_tb_orderdetail, StaticClass.GeneralClass.flag_database_type_general) == 1) { num_orderdetail_inserted++; //update InventoryCount for Product EC_tb_Product ec_tb_product = new EC_tb_Product(); ec_tb_product.ProductID = ec_tb_orderdetail.ProductID; ec_tb_product.InventoryCount = ec_tb_orderdetail.Qty; bus_tb_product.UpdateInventoryCount(ec_tb_product); ShellOutViewModel.eventSavePaymentOther(ec_tb_order.OrderID, null); } } //if insert orderdetai success if (num_orderdetail_inserted > 0) { result = true; } //if insert orderdetail failed else { if (bus_tb_order.DeleteOrder(ec_tb_order) == 1) { result = false; } } } } return(result); }