public void AddnewCompany(CompanyWPF companynew) { Company company = new Company(); company.Name = companynew.Name; company.Password = companynew.Password; company.Phone = companynew.Phone; company.Type = companynew.Type; client.AddnewCompany(company); }
public CompanyWPF FindCompanybyName(String Name) { CompanyWPF company = new CompanyWPF(); Company datafromdb = client.FindCompanybyName(Name); if (datafromdb == null) { return(null); } company.Name = datafromdb.Name; company.Password = datafromdb.Password; company.Phone = datafromdb.Phone; company.Type = datafromdb.Type; return(company); }
private void Registration(object obj) { RegistrationName = UsernameInReg; bool CheckCompany = IsCheckedCompany; bool CheckUser = IsCheckedUser; String nameofUserCompany = UsernameInReg; String password = PasswordInReg; String phone = TelephoneInReg; if (CheckCompany == false && CheckUser == false) { MessageBox.Show("Choose a type of account"); return; } int size; while (String.IsNullOrEmpty(nameofUserCompany) || String.IsNullOrEmpty(password) || String.IsNullOrEmpty(phone) || (!Int32.TryParse(phone, out size)) || (nameofUserCompany.Length <= 0 || nameofUserCompany.Length > 30) || (password.Length <= 0 || password.Length > 30) || (phone.Length <= 0 || phone.Length > 30)) { MessageBox.Show("INCORRECT PARAMETERS"); return; } CompanyWPF company = methods.FindCompanybyName(nameofUserCompany); CompanyWPF newcompany = new CompanyWPF(); if (company == null) { newcompany.Name = nameofUserCompany; newcompany.Password = password; newcompany.Phone = phone; if (CheckCompany == true) { newcompany.Type = 1; } else { newcompany.Type = 2; } methods.AddnewCompany(newcompany); MessageBox.Show("Registration is Successful"); } else { MessageBox.Show("There is such user"); } }
private void CreateANewRoute(object obj) { if (LoginName != null) { String start = StartDestinationInCreate; String finish = FinalDestinationInCreate; String freespaces = FreeSpacesInCreate; String price = PriceInCreate; string day = Day.Content.ToString(); string month = Month.Content.ToString(); string year = Year.Content.ToString(); string hour = Hour.Content.ToString(); string minute = Minute.Content.ToString(); string second = Second.Content.ToString(); int dayint, monthint, yearint, hourint, minuteint, secondint, spaces; decimal prices; Int32.TryParse(day, out dayint); Int32.TryParse(month, out monthint); Int32.TryParse(year, out yearint); Int32.TryParse(hour, out hourint); Int32.TryParse(minute, out minuteint); Int32.TryParse(second, out secondint); if (!Int32.TryParse(freespaces, out spaces)) { MessageBox.Show("Include a valid number of spaces"); return; } else { if (spaces > 50) { MessageBox.Show("Include a valid number of spaces"); return; } } if (!decimal.TryParse(price, out prices)) { MessageBox.Show("Include a valid value for price"); return; } else { if (prices > 50) { MessageBox.Show("Include a valid number of price"); return; } } bool city1 = false, city2 = false; List <String> allcities = methods.GetAllCities(); foreach (String city in allcities) { if (string.Equals(city, start, StringComparison.OrdinalIgnoreCase)) { city1 = true; } if (string.Equals(city, finish, StringComparison.OrdinalIgnoreCase)) { city2 = true; } } if ((city1 == true) && (city2 == true)) { CompanyWPF idcompany = methods.FindCompanybyName(LoginName); Route newroute = new Route(); newroute.ID_Company = idcompany.ID; newroute.Price = prices; int idcity1 = methods.CitybyName(start); int idcity2 = methods.CitybyName(finish); DateTime dt; try { dt = new DateTime(yearint, monthint, dayint, hourint, minuteint, secondint); newroute.Timeof = dt; newroute.StartPoint = idcity1; newroute.EndPoint = idcity2; List <Route> allroutes = methods.GetAllLines(); foreach (Route route in allroutes) { if (route.Timeof.Equals(dt) && route.StartPoint.Equals(idcity1) && route.EndPoint.Equals(idcity2) && route.ID_Company.Equals(idcompany.ID)) { MessageBox.Show("There is such route on this time"); return; } } methods.AddnewLine(newroute); } catch (Exception e) { MessageBox.Show("INVALID DATE"); } } else { MessageBox.Show("There is a incorrect location"); } } else if (RegistrationName != null) { String start = StartDestinationInCreate; String finish = FinalDestinationInCreate; String freespaces = FreeSpacesInCreate; String price = PriceInCreate; string day = Day.Content.ToString(); string month = Month.Content.ToString(); string year = Year.Content.ToString(); string hour = Hour.Content.ToString(); string minute = Minute.Content.ToString(); string second = Second.Content.ToString(); int dayint, monthint, yearint, hourint, minuteint, secondint, spaces; decimal prices; Int32.TryParse(day, out dayint); Int32.TryParse(month, out monthint); Int32.TryParse(year, out yearint); Int32.TryParse(hour, out hourint); Int32.TryParse(minute, out minuteint); Int32.TryParse(second, out secondint); if (!Int32.TryParse(freespaces, out spaces)) { MessageBox.Show("Include a valid number of spaces"); return; } else { if (spaces > 50) { MessageBox.Show("Include a valid number of spaces"); return; } } if (!decimal.TryParse(price, out prices)) { MessageBox.Show("Include a valid value for price.INSERT WITH A DOT NOT A COMMA"); return; } else { if (prices > 50) { MessageBox.Show("Include a valid number of price"); return; } } bool city1 = false, city2 = false; List <String> allcities = methods.GetAllCities(); foreach (String city in allcities) { if (string.Equals(city, start, StringComparison.OrdinalIgnoreCase)) { city1 = true; } if (string.Equals(city, finish, StringComparison.OrdinalIgnoreCase)) { city2 = true; } } if ((city1 == true) && (city2 == true)) { CompanyWPF idcompany = methods.FindCompanybyName(LoginName); Route newroute = new Route(); newroute.ID_Company = idcompany.ID; newroute.Price = prices; int idcity1 = methods.CitybyName(start); int idcity2 = methods.CitybyName(finish); DateTime dt; try { dt = new DateTime(yearint, monthint, dayint, hourint, minuteint, secondint); newroute.Timeof = dt; newroute.StartPoint = idcity1; newroute.EndPoint = idcity2; List <Route> allroutes = methods.GetAllLines(); foreach (Route route in allroutes) { if (route.Timeof.Equals(dt) && route.StartPoint.Equals(idcity1) && route.EndPoint.Equals(idcity2) && route.ID_Company.Equals(idcompany.ID)) { MessageBox.Show("There is such route on this time"); return; } } methods.AddnewLine(newroute); } catch (Exception e) { MessageBox.Show("INVALID DATE"); } } else { MessageBox.Show("There is a incorrect location"); } } else { MessageBox.Show("Your have to login or register user to create new route"); } }