public async Task <string> InsertBills(BillPostModel model) { try { DateTime date = DateTime.ParseExact(model.Date.ToString(), "MM/dd/yyyy", CultureInfo.InvariantCulture); BillsTable bills = new BillsTable() { BillId = model.BillId, Number = model.Number, LanguangeId = model.LanguangeId, CurrencyId = model.CurrencyId, From = model.From, DestinationId = model.DestinationId, Date = date, InvoiceDue = model.InvoiceDue, PurchaseOrderId = model.PurchaseOrderId, MeasurementId = model.MeasurementId, SubTotal = decimal.Parse(model.SubTotal.Replace(".", ",")), Discount = decimal.Parse(model.Discount.Replace(".", ",")), Total = decimal.Parse(model.Total.Replace(".", ",")), DiscountName = model.DiscountName, Status = model.Status, }; await db.Bills.AddAsync(bills); await db.SaveChangesAsync(); return(bills.Number + " successfully added"); } catch (Exception x) { return(x.Message.ToString()); } }
private void SellB_Click(object sender, EventArgs e) { BillsTable.Client = Client.Text; BillsTable.MName = PName.Text; BillsTable.MCost = Convert.ToDecimal(PCost.Text); if (PName.Text != "" && Client.Text != "" && NewBill.Checked) { SellMedic(); BillsTable.newbill(); BillNO.Text = BillsTable.BillNO.ToString(); } else if (PName.Text != "" && Client.Text != "" && !NewBill.Checked) { SellMedic(); BillsTable.updatebill(); } else if (Client.Text == "") { MessageBox.Show("ادخل اسم المشترى"); } else { MessageBox.Show("الدواء غير متوفر"); } }
private void SellB_Click(object sender, EventArgs e) { BillsTable.Client = Client.Text; BillsTable.MName = PName.Text; BillsTable.MCost = Convert.ToDecimal(PCost.Text); if (PName.Text != "" && Client.Text != "" && NewBill.Checked) { SellMedic(); if (SellCom != true) { return; } BillsTable.newbill(); try { MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("bills").Order("ID"); MySqlReader r = new MySqlReader(cmd); if (r.Read()) { BillNO.Text = r.ReadString("ID"); } r.Close(); SellCom = false; } catch (Exception el) { Program.SaveException(el); } } else if (PName.Text != "" && Client.Text != "" && !NewBill.Checked) { SellMedic(); if (SellCom == false) { return; } BillsTable.updatebill(); SellCom = false; } else if (PName.Text == "" || PCost.Text == "") { MessageBox.Show("لا يوجد دواء"); } else if (Client.Text == "") { MessageBox.Show("ادخل اسم المشترى"); } else { MessageBox.Show("الدواء غير متوفر"); } }
private void Install_Click(object sender, EventArgs e) { try { IniFile file = new IniFile(Constants.SetupConfigPath); if (this.Text == "تنصيب البرنامج") { if (!File.Exists(Constants.SetupConfigPath)) { file.Write("MySql", "Host", DBHost.Text); file.Write("MySql", "Username", DBUser.Text); file.Write("MySql", "Password", DBPass.Text); file.Write("MySql", "Database", DBName.Text); file.Write("Upgrade", "Version", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString().Replace(".", "")); if (!Directory.Exists(Application.StartupPath + @"BackUp\")) { Directory.CreateDirectory(Application.StartupPath + @"\BackUp\"); } DataHolder.CreateConnection(Program.INIDecrypt(file.ReadString("MySql", "Username")), Program.INIDecrypt(file.ReadString("MySql", "Password")), Program.INIDecrypt(file.ReadString("MySql", "Host"))); CreateDB.Createdb(DBName.Text); DataHolder.CreateConnection(Program.INIDecrypt(file.ReadString("MySql", "Username")), Program.INIDecrypt(file.ReadString("MySql", "Password")), Program.INIDecrypt(file.ReadString("MySql", "Database")), Program.INIDecrypt(file.ReadString("MySql", "Host"))); CreateDB.CreateTables(); MessageBox.Show("تم تنصيب الاعدادات\nمن فضلك انشاء حساب جديد لتتمكن من الدخول"); Register reg = new Register(); reg.ShowDialog(); this.Close(); } } else if (this.Text == "اعدادات البرنامج") { if (File.Exists(Constants.SetupConfigPath)) { BackUp.NewDbBackup(); DataHolder.CreateConnection(Program.INIDecrypt(file.ReadString("MySql", "Username")), Program.INIDecrypt(file.ReadString("MySql", "Password")), Program.INIDecrypt(file.ReadString("MySql", "Host"))); CreateDB.Createdb(file.ReadString("MySql", "Database"), DBName.Text); file.Write("MySql", "Host", DBHost.Text); file.Write("MySql", "Username", DBUser.Text); file.Write("MySql", "Password", DBPass.Text); file.Write("MySql", "Database", DBName.Text); DataHolder.CreateConnection(Program.INIDecrypt(file.ReadString("MySql", "Username")), Program.INIDecrypt(file.ReadString("MySql", "Password")), Program.INIDecrypt(file.ReadString("MySql", "Database")), Program.INIDecrypt(file.ReadString("MySql", "Host"))); BackUp.NewDbRestore(); BillsTable.LBN(); MessageBox.Show("تم تغيير الاعدادات"); } } } catch (Exception ee) { Program.SaveException(ee); } }
private static void EngineThread_Execute() { try { IniFile file = new IniFile(Constants.SetupConfigPath); if (!File.Exists(Constants.SetupConfigPath)) { Setup set = new Setup { Text = "تنصيب البرنامج" }; set.ShowDialog(); } DataHolder.CreateConnection(INIDecrypt(file.ReadString("MySql", "Username")), INIDecrypt(file.ReadString("MySql", "Password")), INIDecrypt(file.ReadString("MySql", "Database")), INIDecrypt(file.ReadString("MySql", "Host"))); GC.Collect(); BillsTable.LBN(); } catch (Exception exception) { MessageBox.Show(exception.ToString()); File.Delete(Constants.SetupConfigPath); } }
/// <summary> /// The first thing that program is going to do after showing up /// like checking for database connection etc /// </summary> public static void StartUp_Engine() { if (!EngineOn) { try { IniFile file2 = new IniFile(Paths.BackupConfigPath); if (!File.Exists(Paths.SetupConfigPath)) { IsSetup = true; Set set = new Set { Title = "تنصيب البرنامج" }; set.ShowDialog(); } Config co = new Config(); co.Read(true); DataHolder.CreateConnection(co.DbUserName, co.DbUserPassword, co.DbName, co.Hostname); string ver = co.Version; if (Convert.ToInt16(ver) < Convert.ToInt16(Assembly.GetExecutingAssembly().GetName().Version.ToString().Replace(".", ""))) { IsSetup = true; //IsUpgrading = true; Set set = new Set { Title = "ترقية البرنامج" }; set.ShowDialog(); } if (!IsSetup) { co.Read(true, true); if (AccountsTable.CountUsers() == 0) { IsSetup = true; NoAccount = true; Set set = new Set { Title = "تنصيب البرنامج" }; View.Pages.Setup.IsInstallCompleted = true; set.ShowDialog(); } BillsTable.LBN(); MySqlCommand cmd = new MySqlCommand(MySqlCommandType.UPDATE); cmd.Update("logs").Set("Online", 0).Where("Online", 1).Execute(); sb = INIDecrypt(file2.ReadString("Settings", "Backup")); tb = INIDecrypt(file2.ReadString("Settings", "TakeBackup")); st = INIDecrypt(file2.ReadString("Settings", "Type")); stt = INIDecrypt(file2.ReadString("Settings", "Time")); std = INIDecrypt(file2.ReadString("Settings", "Date")); #region database logs if (co.AccountsLog == "0") { View.Pages.Settings.IsRecAcc = false; } else if (co.AccountsLog == "1") { View.Pages.Settings.IsRecAcc = true; } if (co.DrugsLog == "0") { View.Pages.Settings.IsRecMed = false; } else if (co.DrugsLog == "1") { View.Pages.Settings.IsRecMed = true; } #endregion #region automatic backup system if (File.Exists(Paths.BackupConfigPath)) { try { if (Convert.ToByte(sb) == 1) { if (Convert.ToByte(st) == 1) { string[] time = stt.Split(':'); if (Convert.ToByte(tb) == 0) { if (DateTime.Now.Date == Convert.ToDateTime(std)) { if (DateTime.Now.Hour - Convert.ToByte(time[0]) == 0 && DateTime.Now.Minute - Convert.ToByte(time[1]) >= 0) { BackUp.Backup("PROPHMW"); file2.Write("Settings", "TakeBackup", "1"); tb = "1"; Console.WriteLine("Daily backup has been taken"); } if (DateTime.Now.Hour - Convert.ToByte(time[0]) >= 1) { BackUp.Backup("PROPHMW"); file2.Write("Settings", "TakeBackup", "1"); tb = "1"; Console.WriteLine("Daily backup has been taken"); } } } else { if (DateTime.Now.Date > Convert.ToDateTime(std)) { file2.Write("Settings", "TakeBackup", "0"); tb = "0"; Console.WriteLine("Daily backup has been reset"); } } } else if (Convert.ToByte(st) == 2) { if (Convert.ToByte(tb) == 0) { if (Convert.ToByte(stt) <= Convert.ToByte(DateTime.Now.DayOfWeek)) { BackUp.Backup("PROPHMW"); file2.Write("Settings", "TakeBackup", "1"); tb = "1"; Console.WriteLine("Weekly backup has been taken"); } } else { if (Convert.ToByte(stt) > Convert.ToByte(DateTime.Now.DayOfWeek)) { file2.Write("Settings", "TakeBackup", "0"); tb = "0"; Console.WriteLine("Weekly backup has been reset"); } } } else if (Convert.ToByte(st) == 3) { if (Convert.ToByte(tb) == 0) { if (Convert.ToByte(stt) <= Convert.ToByte(DateTime.Now.Day)) { BackUp.Backup("PROPHMW"); file2.Write("Settings", "TakeBackup", "1"); tb = "1"; Console.WriteLine("Monthly backup has been taken"); } } else { if (Convert.ToByte(stt) > Convert.ToByte(DateTime.Now.Day)) { file2.Write("Settings", "TakeBackup", "0"); tb = "0"; Console.WriteLine("Monthly backup has been reset"); } } } } } catch (Exception e) { Console.WriteLine("Check the automatic backup system in the core"); SaveException(e); File.Delete(Paths.BackupConfigPath); } } #endregion EngineOn = true; } } catch (Exception ex) { SaveException(ex); if (File.Exists(Paths.SetupConfigPath)) { File.Delete(Paths.SetupConfigPath); } if (File.Exists(Paths.BackupConfigPath)) { File.Delete(Paths.BackupConfigPath); } Console.WriteLine("Program configuration files has been deleted \r\n now we are goning to shutdown your PC"); } } }
private void SellM_Click(object sender, RoutedEventArgs e) { if (MName.Text == "" || MPrice.Text == "" || MExist.Text == "" || MWSell.Text == "") { MessageBox.Show("لا يمكن اتمام عمليه البيع بسبب وجود حقل مهم فارغ"); return; } if (EnBills.IsChecked == true) { BillsTable.bClient = Client.Text; BillsTable.bMName = MName.Text; BillsTable.bMCost = Convert.ToDecimal(MPrice.Text) * Convert.ToDecimal(MWSell.Text); if (MName.Text != "" && Client.Text != "" && NewBill.IsChecked == true) { SellMedic(); if (CompleteSelling != true) { return; } BillsTable.newbill(); try { MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("bills").Order("ID"); MySqlReader r = new MySqlReader(cmd); if (r.Read()) { BillNo.Text = r.ReadString("ID"); } r.Close(); CompleteSelling = false; } catch (Exception ex) { Core.SaveException(ex); } } else if (MName.Text != "" && Client.Text != "" && NewBill.IsChecked == false) { SellMedic(); if (CompleteSelling == false) { return; } BillsTable.updatebill(); CompleteSelling = false; } else if (Client.Text == "") { MessageBox.Show("ادخل اسم المشترى/العميل"); } else { MessageBox.Show("الدواء غير متوفر"); } } else { SellMedic(); CompleteSelling = false; } }