private void muibtnSearch_Click(object sender, RoutedEventArgs e) { if (thread_search != null && thread_search.ThreadState == ThreadState.Running) { } else { thread_search = new Thread(() => { try { this.tblNotification.Dispatcher.Invoke((Action)(() => { this.tblNotification.Text = ""; })); string str_barcode = ""; this.txbBarcode.Dispatcher.Invoke((Action)(() => { str_barcode = txbBarcode.Text.Trim().ToString(); })); if (str_barcode == "") { this.tblNotification.Dispatcher.Invoke((Action)(() => { this.tblNotification.Text = FindResource("barcode_null").ToString(); })); return; } else { this.muibtnSearch.Dispatcher.Invoke((Action)(() => { this.muibtnSearch.Visibility = System.Windows.Visibility.Collapsed; })); this.mprSearch.Dispatcher.Invoke((Action)(() => { this.mprSearch.IsActive = true; })); this.tblCancel.Dispatcher.Invoke((Action)(() => { this.tblCancel.Visibility = System.Windows.Visibility.Visible; })); if (bus_tb_product.GetProduct("WHERE [BarcodeID] = " + str_barcode).Rows.Count > 0) { this.tblNotification.Dispatcher.Invoke((Action)(() => { this.tblNotification.Text = FindResource("barcode_uses_existing").ToString(); })); } else { if (!GetProductInfo(url + str_barcode)) { this.tblNotification.Dispatcher.Invoke((Action)(() => { this.tblNotification.Text = FindResource("information_not_found").ToString(); })); this.tblNotification.Dispatcher.Invoke((Action)(() => { this.txbLongName.Text = ""; })); this.tblNotification.Dispatcher.Invoke((Action)(() => { this.txbSize_Weight.Text = ""; })); this.tblNotification.Dispatcher.Invoke((Action)(() => { this.txbCountry.Text = ""; })); } } } this.mprSearch.Dispatcher.Invoke((Action)(() => { this.mprSearch.IsActive = false; })); this.tblCancel.Dispatcher.Invoke((Action)(() => { this.tblCancel.Visibility = System.Windows.Visibility.Collapsed; })); this.muibtnSearch.Dispatcher.Invoke((Action)(() => { this.muibtnSearch.Visibility = System.Windows.Visibility.Visible; })); } catch (Exception ex) { this.tblNotification.Dispatcher.Invoke((Action)(() => { this.tblNotification.Text = ex.Message; })); } }); thread_search.Start(); } }
//btnTbProduct_Click private void btnTbProduct_Click(object sender, RoutedEventArgs e) { try { DataTable tb_product = new DataTable(); tb_product = GetTableImport("tb_Product"); if (tb_product.Rows.Count > 0) { if (bus_tb_product.GetProduct("").Rows.Count > 0) { bus_tb_product.DeleteAllProduct(); } } if (InSertAllProduct(tb_product) > 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(); } }
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(); }
//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(); } }