//btnTbSetting_Click private void btnTbSetting_Click(object sender, RoutedEventArgs e) { try { DataTable tb_setting = new DataTable(); tb_setting = GetTableImport("tb_Currency"); if (tb_setting.Rows.Count > 0) { if (bus_tb_setting.GetSetting("").Rows.Count > 0) { bus_tb_setting.DeleteAllSetting(); } } if (InSertAllSetting(tb_setting) > 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(); } }
//DataInitialize private void DataInitialize() { try { //initialize for setting BUS_tb_Setting bus_tb_setting = new BUS_tb_Setting(); using (DataTable dt_setting = bus_tb_setting.GetSetting("WHERE Active = 1")) { StaticClass.GeneralClass.settingid_setting_general = Convert.ToInt32(dt_setting.Rows[0]["SettingID"].ToString()); StaticClass.GeneralClass.currency_setting_general = dt_setting.Rows[0]["Currency"].ToString() + " "; StaticClass.GeneralClass.taxrate_setting_general = Convert.ToDecimal(dt_setting.Rows[0]["TaxRate"].ToString()); StaticClass.GeneralClass.active_setting_general = Convert.ToInt32(dt_setting.Rows[0]["Active"].ToString()); StaticClass.GeneralClass.version_setting_general = Convert.ToInt32(dt_setting.Rows[0]["Version"].ToString()); } } catch (Exception ex) { Pages.Notification page = new Pages.Notification(); page.tblNotification.Text = ex.Message; page.ShowDialog(); } }
//btnAdd_Click private void btnAdd_Click(object sender, RoutedEventArgs e) { try { if (txbCurrency.Text.Trim() == "") { tblNotification.Text = FindResource("currency_null").ToString(); return; } if (txbTaxRate.Text.Trim() == "") { tblNotification.Text = FindResource("tax_rate_null").ToString(); return; } decimal taxrate = 0; if (!decimal.TryParse(txbTaxRate.Text.Trim(), NumberStyles.AllowDecimalPoint, StaticClass.GeneralClass.app_settings["decimalSeparator"].ToString() == "0" ? new CultureInfo("en-US") : new CultureInfo("fr-FR"), out taxrate)) { tblNotification.Text = FindResource("tax_rate_invalid").ToString(); return; } if (taxrate >= 100 || taxrate < 0) { tblNotification.Text = FindResource("tax_rate_value_invalid").ToString(); return; } int version = 1; if (int.TryParse(txbVersion.Text.Trim().ToString(), out version) == false) { tblNotification.Text = FindResource("version_invalid").ToString(); return; } else { EC_tb_Setting setting = new EC_tb_Setting(); setting.Currency = StaticClass.GeneralClass.HandlingSpecialCharacter(txbCurrency.Text.Trim().ToString()); setting.TaxRate = taxrate; setting.Version = version; if (chkActive.IsChecked == true) { setting.Active = 1; bus_tb_setting.UpdateSettingActive(); } else { setting.Active = 0; } if (bus_tb_setting.InsertSetting(setting, StaticClass.GeneralClass.flag_database_type_general) == 1) { if (setting.Active == 1) { DataTable tb_setting = bus_tb_setting.GetSetting("WHERE [SettingID] = (SELECT MAX([SettingID]) FROM [tb_Currency])"); if (tb_setting.Rows.Count == 1) { StaticClass.GeneralClass.flag_add_edit_setting_general = true; StaticClass.GeneralClass.settingid_setting_general = Convert.ToInt32(tb_setting.Rows[0]["SettingID"].ToString()); StaticClass.GeneralClass.currency_setting_general = tb_setting.Rows[0]["Currency"].ToString() + " "; StaticClass.GeneralClass.taxrate_setting_general = Convert.ToDecimal(tb_setting.Rows[0]["TaxRate"].ToString()); StaticClass.GeneralClass.active_setting_general = Convert.ToInt32(tb_setting.Rows[0]["Active"].ToString()); StaticClass.GeneralClass.version_setting_general = Convert.ToInt32(tb_setting.Rows[0]["Version"].ToString()); } } if (add_delegate != null) { add_delegate(); 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(); }
//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 GetListSetting() { if (thread_set != null && thread_set.ThreadState == ThreadState.Running) { } else { thread_set = new Thread(() => { try { dt_setting.Clear(); list_ec_tb_setting.Clear(); this.Dispatcher.Invoke((Action)(() => { this.chkAll.IsChecked = false; this.dtgCurrency.Items.Refresh(); this.dtgCurrency.Visibility = System.Windows.Visibility.Hidden; this.mpr.Visibility = System.Windows.Visibility.Visible; this.mpr.IsActive = true; })); dt_setting = bus_tb_setting.GetSetting(""); int no = 0; foreach (DataRow datarow in dt_setting.Rows) { no++; EC_tb_Setting ec_tb_setting = new EC_tb_Setting(); ec_tb_setting.No = no; ec_tb_setting.SettingID = Convert.ToInt32(datarow["SettingID"].ToString()); ec_tb_setting.Currency = datarow["Currency"].ToString(); ec_tb_setting.TaxRate = Convert.ToDecimal(datarow["TaxRate"].ToString()); ec_tb_setting.StrTaxRate = GeneralClass.GetNumFormatDisplay(ec_tb_setting.TaxRate); ec_tb_setting.Active = Convert.ToInt32(datarow["Active"].ToString()); ec_tb_setting.Version = Convert.ToInt32(datarow["Version"].ToString()); ec_tb_setting.ImageUrl = @"pack://application:,,,/Resources/edit.png"; list_ec_tb_setting.Add(ec_tb_setting); } this.Dispatcher.Invoke((Action)(() => { this.dtgCurrency.Items.Refresh(); this.tblTotal.Text = FindResource("total").ToString() + "(" + list_ec_tb_setting.Count.ToString() + ")"; })); Thread.Sleep(500); this.mpr.Dispatcher.Invoke((Action)(() => { this.mpr.Visibility = System.Windows.Visibility.Hidden; this.mpr.IsActive = false; })); this.dtgCurrency.Dispatcher.Invoke((Action)(() => { this.dtgCurrency.Visibility = System.Windows.Visibility.Visible; })); } catch (Exception ex) { this.Dispatcher.Invoke((Action)(() => { ModernDialog md = new ModernDialog(); md.CloseButton.Content = FindResource("close").ToString(); md.Title = FindResource("notification").ToString(); md.Content = ex.Message; md.ShowDialog(); })); } }); thread_set.Start(); } }
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(); } }