public static bool AddNewCustomer(BusinessLogic.Customer NewCustomer, out string ErrorMessage) { bool Result = true; ErrorMessage = string.Empty; AppDataSet AppData = new AppDataSet(); AppData.ReadXml(DataPath); DataRow NewRow = AppData.Table_Customers.NewRow(); NewRow["CustomerLogin"] = NewCustomer.Login; NewRow["CustomerPassword"] = NewCustomer.Password; NewRow["CustomerTypeId"] = NewCustomer.CurrentType.Id; try { AppData.Table_Customers.Rows.Add(NewRow); AppData.WriteXml(DataPath); } catch (System.Exception CurrentException) { ErrorMessage = CurrentException.Message; Result = false; } AppData.Dispose(); return(Result); }
public static BusinessLogic.Customer GetCustomerByLoginAndPassword(string Login, string Password) { AppDataSet AppData = new AppDataSet(); AppData.ReadXml(DataPath); List <BusinessLogic.CustomerType> Types = new List <BusinessLogic.CustomerType>(); for (int i = 0; i < AppData.Table_CustomerType.Rows.Count; ++i) { BusinessLogic.CustomerType CurrentType = new BusinessLogic.CustomerType(); CurrentType.Id = Convert.ToInt32(AppData.Table_CustomerType.Rows[i]["CustomerTypeId"]); CurrentType.Name = AppData.Table_CustomerType.Rows[i]["CustomerTypeName"].ToString(); Types.Add(CurrentType); } DataRow[] ResultRows = AppData.Table_Customers.Select("CustomerLogin='******' AND CustomerPassword='******'"); if (ResultRows.Length == 0) { AppData.Dispose(); return(null); } BusinessLogic.Customer Result = new BusinessLogic.Customer(); Result.Id = Convert.ToInt32(ResultRows[0]["CustomerId"]); Result.Login = Login; Result.Password = Password; Result.CurrentType = Types.Find(temp => temp.Id == Convert.ToInt32(ResultRows[0]["CustomerTypeId"])); AppData.Dispose(); return(Result); }
public static BusinessLogic.Customer GetCustomerById(int Id) { BusinessLogic.Customer Result = null; AppDataSet AppData = new AppDataSet(); AppData.ReadXml(DataPath); DataRow[] ResultCustomersRows = AppData.Table_Customers.Select("CustomerId=" + Id.ToString()); if (ResultCustomersRows.Length > 0) { Result = new BusinessLogic.Customer(); Result.Id = Id; Result.Login = ResultCustomersRows[0]["CustomerLogin"].ToString(); Result.Password = ResultCustomersRows[0]["CustomerPassword"].ToString(); string CustomerTypeId = ResultCustomersRows[0]["CustomerTypeId"].ToString(); DataRow[] ResultCustomerTypeRows = AppData.Table_Customers.Select("CustomerTypeId=" + CustomerTypeId); if (ResultCustomerTypeRows.Length == 0) { AppData.Dispose(); return(null); } Result.CurrentType = new BusinessLogic.CustomerType(); Result.CurrentType.Id = Convert.ToInt32(ResultCustomerTypeRows[0]["CustomerTypeId"]); //Result.CurrentType.Name = ResultCustomerTypeRows[0]["CustomerTypeName"].ToString(); } return(Result); }
public static List <BusinessLogic.Customer> GetCustomersList() { List <BusinessLogic.Customer> Result = new List <BusinessLogic.Customer>(); AppDataSet AppData = new AppDataSet(); AppData.ReadXml(DataPath); List <BusinessLogic.CustomerType> Types = new List <BusinessLogic.CustomerType>(); for (int i = 0; i < AppData.Table_CustomerType.Rows.Count; ++i) { BusinessLogic.CustomerType CurrentType = new BusinessLogic.CustomerType(); CurrentType.Id = Convert.ToInt32(AppData.Table_CustomerType.Rows[i]["CustomerTypeId"]); CurrentType.Name = AppData.Table_CustomerType.Rows[i]["CustomerTypeName"].ToString(); Types.Add(CurrentType); } for (int i = 0; i < AppData.Table_Customers.Rows.Count; ++i) { BusinessLogic.Customer NewCustomer = new BusinessLogic.Customer(); NewCustomer.Id = Convert.ToInt32(AppData.Table_Customers.Rows[i]["CustomerId"]); NewCustomer.Login = AppData.Table_Customers.Rows[i]["CustomerLogin"].ToString(); NewCustomer.Password = AppData.Table_Customers.Rows[i]["CustomerPassword"].ToString(); NewCustomer.CurrentType = Types.Find(temp => temp.Id == Convert.ToInt32(AppData.Table_Customers.Rows[i]["CustomerTypeId"])); Result.Add(NewCustomer); } return(Result); }
public static bool UpdateCustomer(BusinessLogic.Customer EditedCustomer, out string ErrorMessage) { ErrorMessage = string.Empty; bool Result = true; AppDataSet AppData = new AppDataSet(); AppData.ReadXml(DataPath); DataRow[] ResultCustomerRows = AppData.Table_Customers.Select("CustomerId = " + EditedCustomer.Id.ToString()); if (ResultCustomerRows.Length > 0) { try { ResultCustomerRows[0]["CustomerLogin"] = EditedCustomer.Login; ResultCustomerRows[0]["CustomerPassword"] = EditedCustomer.Password; ResultCustomerRows[0]["CustomerTypeId"] = EditedCustomer.CurrentType.Id; AppData.WriteXml(DataPath); } catch (System.Exception ex) { Result = false; ErrorMessage = ex.Message; AppData.Dispose(); } } AppData.Dispose(); return(Result); }
public static List <BusinessLogic.CustomerType> GetCustomerTypeList() { AppDataSet AppData = new AppDataSet(); AppData.ReadXml(DataPath); List <BusinessLogic.CustomerType> Result = new List <BusinessLogic.CustomerType>(); for (int i = 0; i < AppData.Table_CustomerType.Rows.Count; ++i) { BusinessLogic.CustomerType CurrentType = new BusinessLogic.CustomerType(); CurrentType.Id = Convert.ToInt32(AppData.Table_CustomerType.Rows[i]["CustomerTypeId"]); CurrentType.Name = AppData.Table_CustomerType.Rows[i]["CustomerTypeName"].ToString(); Result.Add(CurrentType); } AppData.Dispose(); return(Result); }