//btnTbOrder_Click private void btnTbOrder_Click(object sender, RoutedEventArgs e) { try { DataTable tb_order = new DataTable(); tb_order = GetTableImport("tb_Order"); if (tb_order.Rows.Count > 0) { if (bus_tb_order.GetOrder("").Rows.Count > 0) { bus_tb_order.DeleteAllOrder(); } } if (InSertAllOrder(tb_order) > 0) { Pages.Notification page = new Pages.Notification(); page.tblNotification.Text = "Import success!"; page.ShowDialog(); } } catch (Exception ex) { Pages.Notification page = new Pages.Notification(); page.tblNotification.Text = ex.Message; page.ShowDialog(); } }
//muiBtnOK_Click private void muiBtnOK_Click(object sender, RoutedEventArgs e) { if (StaticClass.GeneralClass.list_ec_tb_customer_general.Count == 0) { tblNotification.Text = FindResource("select_least_customer").ToString(); } else { try { int result = 0; for (int i = 0; i < StaticClass.GeneralClass.list_ec_tb_customer_general.Count; i++) { if (bus_tb_order.GetOrder("WHERE [CustomerID]=" + StaticClass.GeneralClass.list_ec_tb_customer_general[i].CustomerID.ToString()).Rows.Count > 0) { tblNotification.Text = FindResource("customer_id").ToString() + ": " + StaticClass.GeneralClass.list_ec_tb_customer_general[i].CustomerID.ToString() + " " + FindResource("already_uses").ToString(); } else { EC_tb_Customer ec_tb_customer = new EC_tb_Customer(); ec_tb_customer.CustomerID = StaticClass.GeneralClass.list_ec_tb_customer_general[i].CustomerID; if (bus_tb_customer.DeleteCustomer(ec_tb_customer) == 1) { result++; } } } if (result > 0) { if (muibtndelete_delegate != null) { StaticClass.GeneralClass.flag_add_edit_delete_customer_general = true; StaticClass.GeneralClass.list_ec_tb_salesperson_general.Clear(); muibtndelete_delegate(true); this.Close(); } } } catch (Exception ex) { tblNotification.Text = ex.Message; } } }
private void Button_Click(object sender, RoutedEventArgs e) { System.IO.StreamWriter stream_writer = new System.IO.StreamWriter(@"G:\CheckOut.sql"); //export table user stream_writer.WriteLine("-- table dbo.tb_User"); //delete data from table user stream_writer.WriteLine("delete * from [tb_User]"); stream_writer.WriteLine(""); DataTable tb_user = new DataTable(); tb_user = bus_tb_user.GetUser(""); foreach (DataRow dr in tb_user.Rows) { stream_writer.WriteLine("INSERT INTO [tb_User] ([ID],[Name],[Email],[Address],[Password],[Question],[Answer]) VALUES (" + dr["ID"].ToString() + ",'" + dr["Name"].ToString() + "','" + dr["Email"].ToString() + "','" + dr["Address"].ToString() + "','" + dr["Password"].ToString() + "','" + dr["Question"].ToString() + "','" + dr["Answer"].ToString() + "');"); } //export table setting stream_writer.WriteLine(""); stream_writer.WriteLine(""); stream_writer.WriteLine("-- table dbo.tb_Setting"); //delete data from table Setting stream_writer.WriteLine("delete * from [tb_Setting]"); stream_writer.WriteLine(""); DataTable tb_setting = new DataTable(); tb_setting = bus_tb_setting.GetSetting(""); foreach (DataRow dr in tb_setting.Rows) { stream_writer.WriteLine("INSERT INTO [tb_Setting] ([SettingID],[Currency],[TaxRate],[Active],[Version]) VALUES (" + dr["SettingID"].ToString() + ",'" + dr["Currency"].ToString() + "'," + dr["TaxRate"].ToString() + "," + dr["Active"].ToString() + "," + dr["Version"].ToString() + ");"); } //export table category stream_writer.WriteLine(""); stream_writer.WriteLine(""); stream_writer.WriteLine("-- table dbo.tb_Category"); //delete data from table category stream_writer.WriteLine("delete * from [tb_Category]"); stream_writer.WriteLine(""); DataTable tb_category = new DataTable(); tb_category = bus_tb_category.GetCatagorySetting(""); foreach (DataRow dr in tb_category.Rows) { stream_writer.WriteLine("INSERT INTO [tb_Category] ([CategoryID],[CategoryName]) VALUES (" + dr["CategoryID"].ToString() + ",'" + dr["CategoryName"].ToString() + "');"); } //export table customer stream_writer.WriteLine(""); stream_writer.WriteLine(""); stream_writer.WriteLine("-- table dbo.tb_Customer"); //delete data from table customer stream_writer.WriteLine("delete * from [tb_Customer]"); stream_writer.WriteLine(""); DataTable tb_customer = new DataTable(); tb_customer = bus_tb_customer.GetCustomer(""); foreach (DataRow dr in tb_customer.Rows) { stream_writer.WriteLine("INSERT INTO [tb_Customer] ([CustomerID],[FirstName],[LastName],[Address1],[Address2],[City],[State],[Zipcode],[Phone],[Email]) VALUES (" + dr["CustomerID"].ToString() + ",'" + dr["FirstName"].ToString() + "','" + dr["LastName"].ToString() + "','" + dr["Address1"].ToString() + "','" + dr["Address2"].ToString() + "','" + dr["City"].ToString() + "','" + dr["State"].ToString() + "','" + dr["Zipcode"].ToString() + "','" + dr["Phone"].ToString() + "','" + dr["Email"].ToString() + "');"); } //export table inputhistory stream_writer.WriteLine(""); stream_writer.WriteLine(""); stream_writer.WriteLine("-- table dbo.tb_InputHistory"); //delete data from table inputhistory stream_writer.WriteLine("delete * from [tb_InputHistory]"); stream_writer.WriteLine(""); DataTable tb_inputhistory = new DataTable(); tb_inputhistory = bus_tb_inputdistory.GetAllInputHistory(""); foreach (DataRow dr in tb_inputhistory.Rows) { stream_writer.WriteLine("INSERT INTO [tb_InputHistory] ([InputID],[ProductID],[ProductName],[InputDate],[UserID],[UserName],[Cost],[Price],[InventoryCount],[CategoryID],[CategoryName],[Tax],[Active],[Country],[Size_Weight]) VALUES (" + dr["InputID"].ToString() + "," + dr["ProductID"].ToString() + ",'" + dr["ProductName"].ToString() + "','" + dr["InputDate"].ToString() + "'," + dr["UserID"].ToString() + ",'" + dr["UserName"].ToString() + "'," + dr["Cost"].ToString() + "," + dr["Price"].ToString() + "," + dr["InventoryCount"].ToString() + "," + dr["CategoryID"].ToString() + ",'" + dr["CategoryName"].ToString() + "'," + dr["Tax"].ToString() + "," + dr["Active"].ToString() + ",'" + dr["Country"].ToString() + "','" + dr["Size_Weight"].ToString() + "');"); } //export table order stream_writer.WriteLine(""); stream_writer.WriteLine(""); stream_writer.WriteLine("-- table dbo.tb_Order"); //delete data from table order stream_writer.WriteLine("delete * from [tb_Order]"); stream_writer.WriteLine(""); DataTable tb_order = new DataTable(); tb_order = bus_tb_order.GetOrder(""); foreach (DataRow dr in tb_order.Rows) { stream_writer.WriteLine("INSERT INTO [tb_Order] ([OrderID],[CustomerID],[CustomerName],[Quantity],[OrderDate],[SalespersonID],[SalespersonName],[PaymentID],[PaymentName],[DiscountType],[Discount],[TotalDiscount],[TotalTax],[TotalAmount]) VALUES (" + dr["OrderID"].ToString() + "," + dr["CustomerID"].ToString() + ",'" + dr["CustomerName"].ToString() + "', " + dr["Quantity"].ToString() + ",'" + dr["OrderDate"].ToString() + "', " + dr["SalespersonID"].ToString() + ", '" + dr["SalespersonName"].ToString() + "', " + dr["PaymentID"].ToString() + ",'" + dr["PaymentName"].ToString() + ", " + dr["DiscountType"].ToString() + "," + dr["Discount"].ToString() + "," + dr["TotalDiscount"].ToString() + "," + dr["TotalTax"].ToString() + "," + dr["TotalAmount"].ToString() + ");"); } //export table orderdetail stream_writer.WriteLine(""); stream_writer.WriteLine(""); stream_writer.WriteLine("-- table dbo.tb_OrderDetail"); //delete data from table orderdetail stream_writer.WriteLine("delete * from [tb_OrderDetail]"); stream_writer.WriteLine(""); DataTable tb_orderdetail = new DataTable(); tb_orderdetail = bus_tb_orderdetail.GetOrderDetail(""); foreach (DataRow dr in tb_orderdetail.Rows) { stream_writer.WriteLine("INSERT INTO [tb_OrderDetail] ([ID],[CategoryID],[CategoryName],[ProductID],[ProductName],[Cost],[Price],[Qty],[Tax],[DiscountType],[Discount],[TotalDiscount],[Total],[OrderID]) VALUES (" + dr["ID"].ToString() + "," + dr["CategoryID"].ToString() + ",'" + dr["CategoryName"].ToString() + "'," + dr["ProductID"].ToString() + ", '" + dr["ProductName"].ToString() + "'," + dr["Cost"].ToString() + "," + dr["Price"].ToString() + "," + dr["Qty"].ToString() + "," + dr["Tax"].ToString() + "," + dr["DiscountType"].ToString() + "," + dr["Discount"].ToString() + "," + dr["TotalDiscount"].ToString() + "," + dr["Total"].ToString() + "," + dr["OrderID"].ToString() + ");"); } //export table payment stream_writer.WriteLine(""); stream_writer.WriteLine(""); stream_writer.WriteLine("-- table dbo.tb_Payment"); //delete data from table payment stream_writer.WriteLine("delete * from [tb_Payment]"); stream_writer.WriteLine(""); DataTable tb_payment = new DataTable(); tb_payment = bus_tb_payment.GetPayment(""); foreach (DataRow dr in tb_payment.Rows) { stream_writer.WriteLine("INSERT INTO [tb_Payment] ([PaymentID],[Card]) VALUES (" + dr["PaymentID"].ToString() + ",'" + dr["Card"].ToString() + "');"); } //export table product str stream_writer.WriteLine(""); stream_writer.WriteLine(""); stream_writer.WriteLine("-- table dbo.tb_Product"); //delete data from table product stream_writer.WriteLine("delete * from [tb_Product]"); stream_writer.WriteLine(""); DataTable tb_product = new DataTable(); tb_product = bus_tb_product.GetProduct(""); foreach (DataRow dr in tb_product.Rows) { stream_writer.WriteLine("INSERT INTO [tb_Product] ([ProductID],[BarcodeID],[ShortName],[LongName],[Cost],[Price],[InventoryCount],[CategoryID],[Tax],[PathImage],[Capture],[Active],[Country],[Size_Weight]) VALUES (" + dr["ProductID"].ToString() + ", '" + dr["BarcodeID"].ToString() + "','" + dr["ShortName"].ToString() + "','" + dr["LongName"].ToString() + "'," + dr["Cost"].ToString() + "," + dr["Price"].ToString() + "," + dr["InventoryCount"].ToString() + "," + dr["CategoryID"].ToString() + "," + dr["Tax"].ToString() + ",'" + dr["PathImage"].ToString() + "'," + dr["Capture"].ToString() + "," + dr["Active"].ToString() + ",'" + dr["Country"].ToString() + "','" + dr["Size_Weight"].ToString() + "');"); } //export table salesperson stream_writer.WriteLine(""); stream_writer.WriteLine(""); stream_writer.WriteLine("-- table dbo.tb_Salesperson"); //delete data from table salesperson stream_writer.WriteLine("delete * from [tb_Salesperson]"); stream_writer.WriteLine(""); DataTable tb_salesperson = new DataTable(); tb_salesperson = bus_tb_salesperson.GetSalesPerson(""); foreach (DataRow dr in tb_salesperson.Rows) { stream_writer.WriteLine("INSERT INTO [tb_Salesperson] ([SalespersonID],[Name],[Birthday],[Address],[Email],[Password],[Active],[Default]) VALUES (" + dr["SalespersonID"].ToString() + ", '" + dr["Name"].ToString() + "', '" + dr["Birthday"].ToString() + "', '" + dr["Address"].ToString() + "', '" + dr["Email"].ToString() + "', '" + dr["Password"].ToString() + "', " + dr["Active"].ToString() + "," + dr["Default"].ToString() + ");"); } stream_writer.Close(); }
//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; } } }
//ExportSQL func public static bool ExportSQL(string backup_position) { bool flag = false; try { //using for table user BUS_tb_User bus_tb_user = new BUS_tb_User(); //using for table setting BUS_tb_Setting bus_tb_setting = new BUS_tb_Setting(); //using for table category BUS_tb_Category bus_tb_category = new BUS_tb_Category(); //using for table customer BUS_tb_Customer bus_tb_customer = new BUS_tb_Customer(); //using for table inputhistory BUS_tb_InputHistory bus_tb_inputdistory = new BUS_tb_InputHistory(); //using for table order BUS_tb_Order bus_tb_order = new BUS_tb_Order(); //using for table orderdetail BUS_tb_OrderDetail bus_tb_orderdetail = new BUS_tb_OrderDetail(); //using for table payment BUS_tb_Payment bus_tb_payment = new BUS_tb_Payment(); //using for table product BUS_tb_Product bus_tb_product = new BUS_tb_Product(); //using for table salesperson BUS_tb_SalesPerson bus_tb_salesperson = new BUS_tb_SalesPerson(); using (System.IO.StreamWriter stream_writer = new System.IO.StreamWriter(backup_position)) { stream_writer.WriteLine("use CheckOut;"); stream_writer.WriteLine(""); stream_writer.WriteLine(""); //export table user stream_writer.WriteLine("-- table dbo.tb_User"); //reset auto increment //stream_writer.WriteLine("DBCC CHECKIDENT(tb_User, RESEED, 0);"); //delete data from table user stream_writer.WriteLine("delete from [tb_User];"); stream_writer.WriteLine(""); DataTable tb_user = new DataTable(); tb_user = bus_tb_user.GetUser(""); foreach (DataRow dr in tb_user.Rows) { stream_writer.WriteLine("INSERT INTO [tb_User] ([ID],[Name],[Email],[Address],[Password],[Question],[Answer]) VALUES (" + dr["ID"].ToString() + ",'" + dr["Name"].ToString() + "','" + dr["Email"].ToString() + "','" + dr["Address"].ToString() + "','" + dr["Password"].ToString() + "','" + dr["Question"].ToString() + "','" + dr["Answer"].ToString() + "');"); } //export table setting stream_writer.WriteLine(""); stream_writer.WriteLine(""); stream_writer.WriteLine("-- table dbo.tb_Setting"); //delete data from table Setting stream_writer.WriteLine("delete from [tb_Setting];"); stream_writer.WriteLine(""); DataTable tb_setting = new DataTable(); tb_setting = bus_tb_setting.GetSetting(""); foreach (DataRow dr in tb_setting.Rows) { stream_writer.WriteLine("INSERT INTO [tb_Setting] ([SettingID],[Currency],[TaxRate],[Active],[Version]) VALUES (" + dr["SettingID"].ToString() + ",'" + dr["Currency"].ToString() + "'," + dr["TaxRate"].ToString() + "," + dr["Active"].ToString() + "," + dr["Version"].ToString() + ");"); } //export table category stream_writer.WriteLine(""); stream_writer.WriteLine(""); stream_writer.WriteLine("-- table dbo.tb_Category"); //delete data from table category stream_writer.WriteLine("delete from [tb_Category];"); stream_writer.WriteLine(""); DataTable tb_category = new DataTable(); tb_category = bus_tb_category.GetCatagorySetting(""); foreach (DataRow dr in tb_category.Rows) { stream_writer.WriteLine("INSERT INTO [tb_Category] ([CategoryID],[CategoryName]) VALUES (" + dr["CategoryID"].ToString() + ",'" + dr["CategoryName"].ToString() + "');"); } //export table customer stream_writer.WriteLine(""); stream_writer.WriteLine(""); stream_writer.WriteLine("-- table dbo.tb_Customer"); //delete data from table customer stream_writer.WriteLine("delete from [tb_Customer];"); stream_writer.WriteLine(""); DataTable tb_customer = new DataTable(); tb_customer = bus_tb_customer.GetCustomer(""); foreach (DataRow dr in tb_customer.Rows) { stream_writer.WriteLine("INSERT INTO [tb_Customer] ([CustomerID],[FirstName],[LastName],[Address1],[Address2],[City],[State],[Zipcode],[Phone],[Email]) VALUES (" + dr["CustomerID"].ToString() + ",'" + dr["FirstName"].ToString() + "','" + dr["LastName"].ToString() + "','" + dr["Address1"].ToString() + "','" + dr["Address2"].ToString() + "','" + dr["City"].ToString() + "','" + dr["State"].ToString() + "','" + dr["Zipcode"].ToString() + "','" + dr["Phone"].ToString() + "','" + dr["Email"].ToString() + "');"); } //export table inputhistory stream_writer.WriteLine(""); stream_writer.WriteLine(""); stream_writer.WriteLine("-- table dbo.tb_InputHistory"); //delete data from table inputhistory stream_writer.WriteLine("delete from [tb_InputHistory];"); stream_writer.WriteLine(""); DataTable tb_inputhistory = new DataTable(); tb_inputhistory = bus_tb_inputdistory.GetAllInputHistory(""); foreach (DataRow dr in tb_inputhistory.Rows) { stream_writer.WriteLine("INSERT INTO [tb_InputHistory] ([InputID],[ProductID],[ProductName],[InputDate],[UserID],[UserName],[Cost],[Price],[InventoryCount],[CategoryID],[CategoryName],[Tax],[Active],[Country],[Size_Weight]) VALUES (" + dr["InputID"].ToString() + "," + dr["ProductID"].ToString() + ",'" + dr["ProductName"].ToString() + "','" + dr["InputDate"].ToString() + "'," + dr["UserID"].ToString() + ",'" + dr["UserName"].ToString() + "'," + dr["Cost"].ToString() + "," + dr["Price"].ToString() + "," + dr["InventoryCount"].ToString() + "," + dr["CategoryID"].ToString() + ",'" + dr["CategoryName"].ToString() + "'," + dr["Tax"].ToString() + "," + dr["Active"].ToString() + ",'" + dr["Country"].ToString() + "','" + dr["Size_Weight"].ToString() + "');"); } //export table order stream_writer.WriteLine(""); stream_writer.WriteLine(""); stream_writer.WriteLine("-- table dbo.tb_Order"); //delete data from table order stream_writer.WriteLine("delete from [tb_Order];"); stream_writer.WriteLine(""); DataTable tb_order = new DataTable(); tb_order = bus_tb_order.GetOrder(""); foreach (DataRow dr in tb_order.Rows) { stream_writer.WriteLine("INSERT INTO [tb_Order] ([OrderID],[CustomerID],[CustomerName],[Quantity],[OrderDate],[SalespersonID],[SalespersonName],[PaymentID],[PaymentName],[DiscountType],[Discount],[TotalDiscount],[TotalTax],[TotalAmount]) VALUES (" + dr["OrderID"].ToString() + "," + dr["CustomerID"].ToString() + ",'" + dr["CustomerName"].ToString() + "', " + dr["Quantity"].ToString() + ",'" + dr["OrderDate"].ToString() + "', " + dr["SalespersonID"].ToString() + ", '" + dr["SalespersonName"].ToString() + "', " + dr["PaymentID"].ToString() + ",'" + dr["PaymentName"].ToString() + "', " + dr["DiscountType"].ToString() + "," + dr["Discount"].ToString() + "," + dr["TotalDiscount"].ToString() + "," + dr["TotalTax"].ToString() + "," + dr["TotalAmount"].ToString() + ");"); } //export table orderdetail stream_writer.WriteLine(""); stream_writer.WriteLine(""); stream_writer.WriteLine("-- table dbo.tb_OrderDetail"); //delete data from table orderdetail stream_writer.WriteLine("delete from [tb_OrderDetail];"); stream_writer.WriteLine(""); DataTable tb_orderdetail = new DataTable(); tb_orderdetail = bus_tb_orderdetail.GetOrderDetail(""); foreach (DataRow dr in tb_orderdetail.Rows) { stream_writer.WriteLine("INSERT INTO [tb_OrderDetail] ([ID],[CategoryID],[CategoryName],[ProductID],[ProductName],[Cost],[Price],[Qty],[Tax],[DiscountType],[Discount],[TotalDiscount],[Total],[OrderID]) VALUES (" + dr["ID"].ToString() + "," + dr["CategoryID"].ToString() + ",'" + dr["CategoryName"].ToString() + "'," + dr["ProductID"].ToString() + ", '" + dr["ProductName"].ToString() + "'," + dr["Cost"].ToString() + "," + dr["Price"].ToString() + "," + dr["Qty"].ToString() + "," + dr["Tax"].ToString() + "," + dr["DiscountType"].ToString() + "," + dr["Discount"].ToString() + "," + dr["TotalDiscount"].ToString() + "," + dr["Total"].ToString() + "," + dr["OrderID"].ToString() + ");"); } //export table payment stream_writer.WriteLine(""); stream_writer.WriteLine(""); stream_writer.WriteLine("-- table dbo.tb_Payment"); //delete data from table payment stream_writer.WriteLine("delete from [tb_Payment];"); stream_writer.WriteLine(""); DataTable tb_payment = new DataTable(); tb_payment = bus_tb_payment.GetPayment(""); foreach (DataRow dr in tb_payment.Rows) { stream_writer.WriteLine("INSERT INTO [tb_Payment] ([PaymentID],[Card]) VALUES (" + dr["PaymentID"].ToString() + ",'" + dr["Card"].ToString() + "');"); } //export table product str stream_writer.WriteLine(""); stream_writer.WriteLine(""); stream_writer.WriteLine("-- table dbo.tb_Product"); //delete data from table product stream_writer.WriteLine("delete from [tb_Product];"); stream_writer.WriteLine(""); DataTable tb_product = new DataTable(); tb_product = bus_tb_product.GetProduct(""); foreach (DataRow dr in tb_product.Rows) { stream_writer.WriteLine("INSERT INTO [tb_Product] ([ProductID],[BarcodeID],[ShortName],[LongName],[Cost],[Price],[InventoryCount],[CategoryID],[Tax],[PathImage],[Capture],[Active],[Country],[Size_Weight]) VALUES (" + dr["ProductID"].ToString() + ",'" + dr["BarcodeID"].ToString() + "','" + HandlingSpecialCharacter(dr["ShortName"].ToString()) + "','" + HandlingSpecialCharacter(dr["LongName"].ToString()) + "'," + dr["Cost"].ToString() + "," + dr["Price"].ToString() + "," + dr["InventoryCount"].ToString() + "," + dr["CategoryID"].ToString() + "," + dr["Tax"].ToString() + ",'" + dr["PathImage"].ToString() + "'," + dr["Capture"].ToString() + "," + dr["Active"].ToString() + ",'" + dr["Country"].ToString() + "','" + dr["Size_Weight"].ToString() + "');"); } //export table salesperson stream_writer.WriteLine(""); stream_writer.WriteLine(""); stream_writer.WriteLine("-- table dbo.tb_Salesperson"); //delete data from table salesperson stream_writer.WriteLine("delete from [tb_Salesperson];"); stream_writer.WriteLine(""); DataTable tb_salesperson = new DataTable(); tb_salesperson = bus_tb_salesperson.GetSalesPerson(""); foreach (DataRow dr in tb_salesperson.Rows) { stream_writer.WriteLine("INSERT INTO [tb_Salesperson] ([SalespersonID],[Name],[Birthday],[Address],[Email],[Password],[Active],[Default]) VALUES (" + dr["SalespersonID"].ToString() + ",'" + dr["Name"].ToString() + "', '" + dr["Birthday"].ToString() + "', '" + dr["Address"].ToString() + "', '" + dr["Email"].ToString() + "', '" + dr["Password"].ToString() + "', " + dr["Active"].ToString() + "," + dr["Default"].ToString() + ");"); } stream_writer.Close(); flag = true; } } catch (Exception) { flag = false; } return(flag); }
private void muiBtnExport_Click(object sender, RoutedEventArgs e) { try { if (thread_export != null && thread_export.ThreadState == ThreadState.Running) { } else { thread_export = new Thread(() => { int num_export = 0; bool flag = false; string path = ""; this.Dispatcher.Invoke((Action)(() => { System.Windows.Forms.FolderBrowserDialog folder_browser_dialog = new System.Windows.Forms.FolderBrowserDialog(); if (folder_browser_dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { flag = true; num_export = 0; path = folder_browser_dialog.SelectedPath.ToString(); } })); if (flag == true) { this.muiBtnExport.Dispatcher.Invoke((Action)(() => { this.muiBtnExport.Visibility = System.Windows.Visibility.Hidden; })); this.mprExport.Dispatcher.Invoke((Action)(() => { this.mprExport.Visibility = System.Windows.Visibility.Visible; })); this.mprExport.Dispatcher.Invoke((Action)(() => { this.mprExport.IsActive = true; })); //tb_Category if (flag_category == true) { datatable_export = new DataTable(); datatable_export = bus_tb_category.GetCatagorySetting(""); if (excel_utility.WriteDataTableToExcel(datatable_export, "tb_Category", path + @"\tb_Category.csv", "Details") == true) { num_export++; } } //tb_Customer if (flag_customer == true) { datatable_export = new DataTable(); datatable_export = bus_tb_customer.GetCustomer(""); if (excel_utility.WriteDataTableToExcel(datatable_export, "tb_Customer", path + @"\tb_Customer.csv", "Details") == true) { num_export++; } } //tb_InputHistory if (flag_inputhistory == true) { datatable_export = new DataTable(); datatable_export = bus_tb_inputhistory.GetInputHistory(""); if (excel_utility.WriteDataTableToExcel(datatable_export, "tb_InputHistory", path + @"\tb_InputHistory.csv", "Details") == true) { num_export++; } } //tb_Order if (flag_order == true) { datatable_export = new DataTable(); datatable_export = bus_tb_order.GetOrder(""); if (excel_utility.WriteDataTableToExcel(datatable_export, "tb_Order", path + @"\tb_Order.csv", "Details") == true) { num_export++; } } //tb_OrderDetail if (flag_orderdetail == true) { datatable_export = new DataTable(); datatable_export = bus_tb_orderdetail.GetOrderDetail(""); if (excel_utility.WriteDataTableToExcel(datatable_export, "tb_OrderDetail", path + @"\tb_OrderDetail.csv", "Details") == true) { num_export++; } } //tb_Payment if (flag_payment == true) { datatable_export = new DataTable(); datatable_export = bus_tb_payment.GetPayment(""); if (excel_utility.WriteDataTableToExcel(datatable_export, "tb_Payment", path + @"\tb_Payment.csv", "Details") == true) { num_export++; } } //tb_Product if (flag_product == true) { datatable_export = new DataTable(); datatable_export = bus_tb_product.GetProduct(""); if (excel_utility.WriteDataTableToExcel(datatable_export, "tb_Product", path + @"\tb_Product.csv", "Details") == true) { num_export++; } } //tb_Salesperson if (flag_salesperson == true) { datatable_export = new DataTable(); datatable_export = bus_tb_salesperson.GetSalesPerson(""); if (excel_utility.WriteDataTableToExcel(datatable_export, "tb_Salesperson", path + @"\tb_Salesperson.csv", "Details") == true) { num_export++; } } //tb_Setting if (flag_setting == true) { datatable_export = new DataTable(); datatable_export = bus_tb_setting.GetSetting(""); if (excel_utility.WriteDataTableToExcel(datatable_export, "tb_Setting", path + @"\tb_Setting.csv", "Details") == true) { num_export++; } } //tb_User if (flag_user == true) { datatable_export = new DataTable(); datatable_export = bus_tb_user.GetUser(""); if (excel_utility.WriteDataTableToExcel(datatable_export, "tb_User", path + @"\tb_User.csv", "Details") == true) { num_export++; } } } Thread.Sleep(500); this.mprExport.Dispatcher.Invoke((Action)(() => { this.mprExport.IsActive = false; })); this.mprExport.Dispatcher.Invoke((Action)(() => { this.mprExport.Visibility = System.Windows.Visibility.Hidden; })); this.muiBtnExport.Dispatcher.Invoke((Action)(() => { this.muiBtnExport.Visibility = System.Windows.Visibility.Visible; })); //export success if (num_export == num_export_selected) { this.Dispatcher.Invoke((Action)(() => { ModernDialog md = new ModernDialog(); md.Title = FindResource("notification").ToString(); md.Content = FindResource("export_success").ToString(); md.ShowDialog(); })); } }); thread_export.SetApartmentState(ApartmentState.STA); thread_export.Start(); } } catch (Exception ex) { ModernDialog mderr = new ModernDialog(); mderr.Title = FindResource("notification").ToString(); mderr.Content = ex.Message; mderr.ShowDialog(); } }