//UserControl_Loaded private void UserControl_Loaded(object sender, RoutedEventArgs e) { flag_zero_load = false; //handle control HandleControl(); try { dttb_user = bus_tb_user.GetUser("WHERE [ID]=" + StaticClass.GeneralClass.id_user_general); if (dttb_user.Rows.Count > 0) { tblID.Text = dttb_user.Rows[0]["ID"].ToString(); tblUserName.Text = dttb_user.Rows[0]["Name"].ToString(); txbEmail.Text = dttb_user.Rows[0]["Email"].ToString(); txbAddress.Text = dttb_user.Rows[0]["Address"].ToString(); txbQuestion.Text = dttb_user.Rows[0]["Question"].ToString(); txbAnswer.Text = dttb_user.Rows[0]["Answer"].ToString(); flag_zero_load = true; } } catch (Exception ex) { Pages.Notification page = new Pages.Notification(); page.tblNotification.Text = ex.Message; page.ShowDialog(); } }
//btnTbUser_Click private void btnTbUser_Click(object sender, RoutedEventArgs e) { try { DataTable tb_user = new DataTable(); tb_user = GetTableImport("tb_User"); if (tb_user.Rows.Count > 0) { if (bus_tb_user.GetUser("").Rows.Count > 0) { bus_tb_user.DeleteAllUser(); } } if (InSertAllUser(tb_user) > 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(); } }
//btnOK_Click private void btnOK_Click(object sender, RoutedEventArgs e) { if (txbQuestion.Text.Trim().ToString() == "") { tblNotification.Text = FindResource("question_null").ToString();; txbQuestion.Focus(); return; } if (txbAnswer.Text.Trim().ToString() == "") { tblNotification.Text = FindResource("answer_null").ToString();; txbAnswer.Focus(); return; } if (CheckResetPassword(txbQuestion.Text.Trim(), txbAnswer.Text.Trim())) { BBCodeBlock bbcodeblock = new BBCodeBlock(); bbcodeblock.LinkNavigator.Navigate(new Uri(@"/Pages/Setting/CreateNewPassword.xaml", UriKind.Relative), this); } else { System.Data.DataTable tb_user = bus_tb_user.GetUser("WHERE [Name] = 'Admin' AND [Question] = '" + txbQuestion.Text.Trim().ToLower() + "' AND [Answer] = '" + txbAnswer.Text.Trim().ToLower() + "'"); if (tb_user.Rows.Count == 1) { StaticClass.GeneralClass.id_user_general = Convert.ToInt32(tb_user.Rows[0]["ID"].ToString()); BBCodeBlock bbcodeblock = new BBCodeBlock(); bbcodeblock.LinkNavigator.Navigate(new Uri(@"/Pages/Setting/CreateNewPassword.xaml", UriKind.Relative), this); } else { tblNotification.Text = FindResource("user_info_incorrect").ToString(); txbQuestion.Focus(); } } }
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(); }
private void GetUser() { if (thread_content != null && thread_content.ThreadState == ThreadState.Running) { } else { thread_content = new Thread(() => { try { this.grContent.Dispatcher.Invoke((Action)(() => { dtgUser.ItemsSource = null; this.dtgUser.Visibility = System.Windows.Visibility.Hidden; })); this.mpr.Dispatcher.Invoke((Action)(() => { this.mpr.Visibility = System.Windows.Visibility.Visible; this.mpr.IsActive = true; })); tb_user.Clear(); list_ec_tb_user.Clear(); tb_user = bus_tb_user.GetUser(""); foreach (DataRow datarow in tb_user.Rows) { EC_tb_User ec_tb_user = new EC_tb_User(); ec_tb_user.ID = Convert.ToInt32(datarow["ID"].ToString()); ec_tb_user.Name = datarow["Name"].ToString(); ec_tb_user.Email = datarow["Email"].ToString(); ec_tb_user.Address = datarow["Address"].ToString(); ec_tb_user.Password = datarow["Password"].ToString(); ec_tb_user.Question = datarow["Question"].ToString(); ec_tb_user.Answer = datarow["Answer"].ToString(); ec_tb_user.EditImage = @"pack://application:,,,/Resources/edit.png"; list_ec_tb_user.Add(ec_tb_user); } this.tblTotal.Dispatcher.Invoke((Action)(() => { tblTotal.Text = FindResource("total").ToString() + "(" + list_ec_tb_user.Count.ToString() + ")"; })); this.dtgUser.Dispatcher.Invoke((Action)(() => { dtgUser.ItemsSource = list_ec_tb_user; })); Thread.Sleep(500); this.mpr.Dispatcher.Invoke((Action)(() => { this.mpr.Visibility = System.Windows.Visibility.Hidden; this.mpr.IsActive = false; })); this.grContent.Dispatcher.Invoke((Action)(() => { this.dtgUser.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_content.Start(); } }
//btnLogin_Click private void btnLogin_Click(object sender, RoutedEventArgs e) { try { tblNotification.Text = ""; if (txbUsername.Text.Trim().ToString() == "") { tblNotification.Text = FindResource("username_null").ToString(); txbUsername.Focus(); return; } /*if (pwbPassword.Password.Trim() == "") * { * tblNotification.Text = FindResource("password_null").ToString(); * pwbPassword.Focus(); * return; * }*/ else { string _user_name = txbUsername.Text.Trim().ToString(); string user_name = _user_name.Substring(0, 1).ToUpper() + _user_name.Substring(1).ToLower(); string password = GeneralClass.MD5Hash(pwbPassword.Password.Trim().ToString()); bool _isLogin = false; thread_login = new Thread(() => { this.Dispatcher.Invoke((Action)(() => { mpr.IsActive = true; btnLogin.IsEnabled = false; })); DataTable dt_user = new DataTable(); dt_user = bus_tb_user.GetUser("WHERE [Name] = '" + user_name + "'"); if (dt_user.Rows.Count == 1) { if (string.IsNullOrEmpty(pwbPassword.Password.Trim().ToString()) && string.IsNullOrEmpty(dt_user.Rows[0]["Password"].ToString())) { _isLogin = true; } else if (dt_user.Rows[0]["Password"].ToString() == password || pwbPassword.Password.Trim().ToString() == dt_user.Rows[0]["Password"].ToString()) { _isLogin = true; } } if (_isLogin) { GeneralClass.user_permission = Convert.ToInt32(dt_user.Rows[0]["ID"].ToString()); GeneralClass.id_user_general = Convert.ToInt32(dt_user.Rows[0]["ID"].ToString()); GeneralClass.name_user_general = user_name; GeneralClass.password_user_general = dt_user.Rows[0]["Password"].ToString(); this.Dispatcher.Invoke((Action)(() => { app.mainWindow.TitleLinks.Remove(app.linkLogin); app.mainWindow.TitleLinks.Add(app.linkAccount); app.linkAccount.DisplayName = Application.Current.FindResource("hi").ToString() + " " + GeneralClass.name_user_general; app.mainWindow.TitleLinks.Add(app.linkLogout); app.mainWindow.MenuLinkGroups.Remove(app.linkGroupLogInOut); app.mainWindow.MenuLinkGroups.Remove(app.linkGroupOption); })); switch (GeneralClass.user_permission) { case (int)GeneralClass.UserPermission.admin: //admin permission this.Dispatcher.Invoke((Action)(() => { app.mainWindow.MenuLinkGroups.Add(app.linkGroupReport); app.mainWindow.MenuLinkGroups.Add(app.linkGroupSetting); app.mainWindow.MenuLinkGroups.Add(app.linkGroupChart); app.mainWindow.MenuLinkGroups.Add(app.linkGroupStatistic); })); break; case (int)GeneralClass.UserPermission.inventory: //inventory permission this.Dispatcher.Invoke((Action)(() => { app.mainWindow.MenuLinkGroups.Add(app.linkGroupSetting); })); break; case (int)GeneralClass.UserPermission.report: //report permission this.Dispatcher.Invoke((Action)(() => { app.mainWindow.MenuLinkGroups.Add(app.linkGroupReport); })); break; default: break; } this.Dispatcher.Invoke((Action)(() => { app.mainWindow.MenuLinkGroups.Add(app.linkGroupOption); app.mainWindow.MenuLinkGroups.Add(app.linkGroupLogInOut); })); //save logs if (StaticClass.GeneralClass.app_settings["isSaveLogs"].ToString() == "True") { new System.Threading.Thread(() => { GeneralClass.SaveLogs(user_name, "Logged in", DateTime.Now); }).Start(); } this.Dispatcher.Invoke((Action)(() => { app.mainWindow.ContentSource = new Uri(@"/Pages/Home/Home.xaml", UriKind.Relative); })); _isLogin = false; } else { this.Dispatcher.Invoke((Action)(() => { mpr.IsActive = false; tblNotification.Text = FindResource("username_password_incorrect").ToString(); btnLogin.IsEnabled = true; txbUsername.Focus(); })); } }); thread_login.Start(); } } catch (Exception ex) { Pages.Notification page = new Pages.Notification(); page.tblNotification.Text = ex.Message; page.ShowDialog(); } }
//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(); } }