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 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 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 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.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); }
static DataManager() { AppDataSet AppData = new AppDataSet(); if (!File.Exists(DataPath)) { DataRow NewRow = AppData.Table_CustomerType.NewRow(); NewRow["CustomerTypeName"] = "Administrator"; AppData.Table_CustomerType.Rows.Add(NewRow); NewRow = AppData.Table_CustomerType.NewRow(); NewRow["CustomerTypeName"] = "User"; AppData.Table_CustomerType.Rows.Add(NewRow); NewRow = AppData.Table_Customers.NewRow(); NewRow["CustomerTypeId"] = 1; NewRow["CustomerLogin"] = "******"; NewRow["CustomerPassword"] = "******"; AppData.Table_Customers.Rows.Add(NewRow); AppData.WriteXml(DataPath); AppData.Dispose(); } }