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 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); }
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(); } }