public static ObservableCollection <Bill> Load() { using (SqlConnection connection = new SqlConnection(ApplicationA.CONNECTION_STRING)) { ObservableCollection <Bill> bills = new ObservableCollection <Bill>(); connection.Open(); DataSet dataSet = new DataSet(); SqlCommand command = connection.CreateCommand(); command.CommandText = @"Select * From bill;"; SqlDataAdapter dataAdapter = new SqlDataAdapter(command); try { dataAdapter.Fill(dataSet, "bill"); foreach (DataRow row in dataSet.Tables["bill"].Rows) { int id = (int)row["id"]; String dispatcher = (String)row["dispatcher"]; String trafficMonth = (String)row["traffic_month"]; int trafficYear = (int)row["traffic_year"]; int billNumForYear = (int)row["bill_num_for_year"]; DateTime billDate = (DateTime)row["bill_date"]; int companyId = (int)row["company_id"]; double amount = (double)row["bill_sum"]; bills.Add(new Bill(id, dispatcher, companyId, billNumForYear, trafficMonth, trafficYear, billDate, amount)); } } catch (SqlException e) { MessageBox.Show(ApplicationA.DATABASE_ERROR_MESSAGE); ApplicationA.WriteToLog(e.StackTrace); } catch (InvalidOperationException a) { MessageBox.Show(ApplicationA.DATABASE_ERROR_MESSAGE); ApplicationA.WriteToLog(a.StackTrace); } catch (ArgumentException g) { MessageBox.Show(ApplicationA.DATABASE_ERROR_MESSAGE); ApplicationA.WriteToLog(g.StackTrace); } catch (NullReferenceException n) { MessageBox.Show(ApplicationA.DATABASE_ERROR_MESSAGE); ApplicationA.WriteToLog(n.StackTrace); } return(bills); } }
public static ObservableCollection <Billitem> LoadForBill(int billId) { using (SqlConnection connection = new SqlConnection(ApplicationA.CONNECTION_STRING)) { ObservableCollection <Billitem> items = new ObservableCollection <Billitem>(); connection.Open(); DataSet dataSet = new DataSet(); SqlCommand command = connection.CreateCommand(); command.CommandText = @"Select * From bill_item Where bill_id = @Bill_Id;"; SqlDataAdapter dataAdapter = new SqlDataAdapter(command); try { command.Parameters.Add(new SqlParameter("@Bill_Id", billId)); dataAdapter.Fill(dataSet, "bill_item"); foreach (DataRow row in dataSet.Tables["bill_item"].Rows) { int id = (int)row["id"]; int carpetId = (int)row["carpet_id"]; int quantity = (int)row["quantity"]; double price = (double)row["price"]; Billitem item = new Billitem(id, carpetId, price, quantity); items.Add(item); } } catch (SqlException e) { MessageBox.Show("SQL Exception"); ApplicationA.WriteToLog(e.StackTrace); } catch (InvalidOperationException a) { MessageBox.Show("InvalidOperationException"); ApplicationA.WriteToLog(a.StackTrace); } catch (ArgumentException g) { MessageBox.Show("ArgumentException"); ApplicationA.WriteToLog(g.StackTrace); } catch (NullReferenceException n) { MessageBox.Show("NullReferenceException"); ApplicationA.WriteToLog(n.StackTrace); } return(items); } }
public static ObservableCollection <Carpet> Load() { using (SqlConnection connection = new SqlConnection(ApplicationA.CONNECTION_STRING)) { ObservableCollection <Carpet> carpets = new ObservableCollection <Carpet>(); connection.Open(); DataSet dataSet = new DataSet(); SqlCommand command = connection.CreateCommand(); command.CommandText = @"Select * From carpet;"; SqlDataAdapter dataAdapter = new SqlDataAdapter(command); try { dataAdapter.Fill(dataSet, "carpet"); foreach (DataRow row in dataSet.Tables["carpet"].Rows) { int id = (int)row["id"]; double length = (double)row["c_length"]; double width = (double)row["c_width"]; Carpet carpet = new Carpet(id, length, width); carpets.Add(carpet); } } catch (SqlException e) { MessageBox.Show(ApplicationA.DATABASE_ERROR_MESSAGE); ApplicationA.WriteToLog(e.StackTrace); } catch (InvalidOperationException a) { MessageBox.Show(ApplicationA.DATABASE_ERROR_MESSAGE); ApplicationA.WriteToLog(a.StackTrace); } catch (ArgumentException g) { MessageBox.Show(ApplicationA.DATABASE_ERROR_MESSAGE); ApplicationA.WriteToLog(g.StackTrace); } catch (NullReferenceException n) { MessageBox.Show(ApplicationA.DATABASE_ERROR_MESSAGE); MessageBox.Show(n.StackTrace); ApplicationA.WriteToLog(n.StackTrace); } return(carpets); } }
public static bool Add(Bill bill) { using (SqlConnection connection = new SqlConnection(ApplicationA.CONNECTION_STRING)) { bool valid = false; connection.Open(); SqlCommand command = connection.CreateCommand(); command.CommandText = @"Insert Into bill Values(@Dispathcer,@Carpet,@BillNumNext,@TrafficMonth,@TrafficYear,@BillDate,@BillAmount);"; try { command.Parameters.Add(new SqlParameter("@Dispathcer", bill.Dispatcher)); command.Parameters.Add(new SqlParameter("@Carpet", bill.Company.Id)); command.Parameters.Add(new SqlParameter("@BillNumNext", bill.BillNumForYear)); command.Parameters.Add(new SqlParameter("@TrafficMonth", bill.TrafficMonth)); command.Parameters.Add(new SqlParameter("@TrafficYear", bill.TrafficYear)); command.Parameters.Add(new SqlParameter("@BillDate", bill.BillDate)); command.Parameters.Add(new SqlParameter("@BillAmount", bill.Amount)); command.ExecuteNonQuery(); valid = true; } catch (SqlException e) { MessageBox.Show(ApplicationA.DATABASE_ERROR_MESSAGE); ApplicationA.WriteToLog(e.StackTrace); } catch (InvalidOperationException a) { MessageBox.Show(ApplicationA.DATABASE_ERROR_MESSAGE); ApplicationA.WriteToLog(a.StackTrace); } catch (ArgumentException g) { MessageBox.Show(ApplicationA.DATABASE_ERROR_MESSAGE); ApplicationA.WriteToLog(g.StackTrace); } catch (NullReferenceException n) { MessageBox.Show(ApplicationA.DATABASE_ERROR_MESSAGE); ApplicationA.WriteToLog(n.StackTrace); } return(valid); } }
public static bool Add(Billitem item, Bill bill) { using (SqlConnection connection = new SqlConnection(ApplicationA.CONNECTION_STRING)) { bool valid = false; connection.Open(); SqlCommand command = connection.CreateCommand(); command.CommandText = @"Insert Into bill_item Values(@Carpet,@Price,@Bill);"; try { command.Parameters.Add(new SqlParameter("@Carpet", item.Carpet.Id)); command.Parameters.Add(new SqlParameter("@Price", item.Price)); command.Parameters.Add(new SqlParameter("@Bill", bill.Id)); command.ExecuteNonQuery(); valid = true; } catch (SqlException e) { MessageBox.Show(ApplicationA.DATABASE_ERROR_MESSAGE); ApplicationA.WriteToLog(e.StackTrace); } catch (InvalidOperationException a) { MessageBox.Show(ApplicationA.DATABASE_ERROR_MESSAGE); ApplicationA.WriteToLog(a.StackTrace); } catch (ArgumentException g) { MessageBox.Show(ApplicationA.DATABASE_ERROR_MESSAGE); ApplicationA.WriteToLog(g.StackTrace); } catch (NullReferenceException n) { MessageBox.Show(ApplicationA.DATABASE_ERROR_MESSAGE); ApplicationA.WriteToLog(n.StackTrace); } return(valid); } }
static void Main(string[] args) { Console.WriteLine("Hello World!"); var med = new ConcreteMediator(); var a = new ApplicationA("Alice", med); var b = new ApplicationA("Bob", med); var c = new ApplicationA("Charlie", med); a.Send("Request to everyone, I need help"); b.Send("I am here, my coord is 12AF41."); c.Send("I am listening, but not able to help."); a.Send("Hey b, my coord is 12AG78, I am sinking, help!"); b.Send("Okay, find your position, rushing to help you"); }
public bool createBills(DataGrid dg, DateTime bill_date, DateTime traffic_month_and_year, bool print) { bool valid = false; foreach (Company c in dg.SelectedItems) { Bill newBill = (Bill)c.Bill.Clone(); newBill.BillDate = bill_date; newBill.BillNumForYear = BillMaxHelper.findMaxBillNumForYear(traffic_month_and_year.Year) + 1; newBill.TrafficMonth = MonthHelper.getMonthFromInt(traffic_month_and_year.Month); newBill.TrafficYear = traffic_month_and_year.Year; newBill.Id = ApplicationA.Instance.Bills[ApplicationA.Instance.Bills.Count - 1].Id + 1; valid = BillDao.Add(newBill); if (valid) { ApplicationA.Instance.Bills.Add(newBill); c.Bill = newBill; ApplicationA.WriteToLogActions(newBill.Id, "racun"); } MessageBox.Show(newBill.Items.Count.ToString()); foreach (Billitem item in newBill.Items) { valid = BillitemDao.Add(item, newBill); if (valid) { item.Id = BillMaxHelper.findMaxBillItemId(newBill); ApplicationA.WriteToLogActions(item.Id, "stavka racuna"); } } if (print) { ExcelFileEditHelper.editExcelFile(c, print); } } return(valid); }
public static ObservableCollection <Company> Load() { using (SqlConnection connection = new SqlConnection(ApplicationA.CONNECTION_STRING)) { ObservableCollection <Company> companies = new ObservableCollection <Company>(); connection.Open(); DataSet dataSet = new DataSet(); SqlCommand command = connection.CreateCommand(); command.CommandText = @"Select * From company;"; SqlDataAdapter dataAdapter = new SqlDataAdapter(command); try { dataAdapter.Fill(dataSet, "company"); foreach (DataRow row in dataSet.Tables["company"].Rows) { int id = (int)row["id"]; String name = (String)row["name"]; String pib = (String)row["pib"]; String address = (String)row["adress"]; String city = (String)row["city"]; String zone = (String)row["zone"]; String contactPerson = (String)row["contact_person"]; String phoneNumber = (String)row["phone_number"]; DateTime signingDate = (DateTime)row["signing_date"]; bool insecure = (bool)row["insecure"]; double compensation = (double)row["compensation"]; int numReplacements = (int)row["num_replacements"]; int numLocations = (int)row["num_locations"]; int numCarpets = (int)row["num_carpets"]; Company company = new Company(id, name, pib, address, city, zone, contactPerson, phoneNumber, signingDate, insecure, compensation, numReplacements, numLocations, numCarpets); companies.Add(company); } } catch (SqlException e) { MessageBox.Show(ApplicationA.DATABASE_ERROR_MESSAGE); ApplicationA.WriteToLog(e.StackTrace); } catch (InvalidOperationException a) { MessageBox.Show(ApplicationA.DATABASE_ERROR_MESSAGE); ApplicationA.WriteToLog(a.StackTrace); } catch (ArgumentException g) { MessageBox.Show(ApplicationA.DATABASE_ERROR_MESSAGE); ApplicationA.WriteToLog(g.StackTrace); } catch (NullReferenceException n) { MessageBox.Show(ApplicationA.DATABASE_ERROR_MESSAGE); ApplicationA.WriteToLog(n.StackTrace); } return(companies); } }