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 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 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 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); }
protected void Page_Load(object sender, EventArgs e) { BusinessLogic.Customer CurrentCustomer = BusinessLogic.Customer.GetCurrentCustomer(); if (CurrentCustomer != null && CurrentCustomer.CurrentType.Id == 1) { if (!IsPostBack) { DropDownListType.DataSource = BusinessLogic.CustomerType.GetList(); DropDownListType.DataBind(); DropDownListType.Items.Insert(0, new ListItem("", "0")); if (Request.QueryString["id"] != null) { int IdResult; bool IdToIntResult = int.TryParse(Request.QueryString["id"], out IdResult); if (IdToIntResult) { BusinessLogic.Customer EditedCustomer = BusinessLogic.Customer.GetByID(IdResult); TextBoxLogin.Text = EditedCustomer.Login; TextBoxPassword.Text = EditedCustomer.Password; DropDownListType.SelectedValue = EditedCustomer.CurrentType.Id.ToString(); } } } } else { Server.Transfer("Default.aspx"); } }
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 CustomerSourceOfIncome Create(SourceOfIncome sourceOfIncome, Customer customer, DateTime today) { CustomerSourceOfIncome customerSourceOfIncome = new CustomerSourceOfIncome(); customerSourceOfIncome.Customer = customer; customerSourceOfIncome.EffectiveDate = today; customerSourceOfIncome.SourceOfIncome = sourceOfIncome; Context.CustomerSourceOfIncomes.AddObject(customerSourceOfIncome); return customerSourceOfIncome; }
protected void Page_Load(object sender, EventArgs e) { BusinessLogic.Customer CurrentCustomer = BusinessLogic.Customer.GetCurrentCustomer(); if (CurrentCustomer != null && CurrentCustomer.CurrentType.Name == "Administrator") { LiteralMessage.Text = "Hello, " + CurrentCustomer.Login + "(" + CurrentCustomer.CurrentType.ToString() + ")"; } else { Server.Transfer("Default.aspx"); } }
public static CustomerSourceOfIncome CreateOrUpdate(SourceOfIncome sourceOfIncome, Customer customer, DateTime today) { CustomerSourceOfIncome current = GetActive(customer, sourceOfIncome); if (current != null) current.EndDate = today; CustomerSourceOfIncome customerSourceOfIncome = new CustomerSourceOfIncome(); customerSourceOfIncome.Customer = customer; customerSourceOfIncome.EffectiveDate = today; customerSourceOfIncome.SourceOfIncome = sourceOfIncome; Context.CustomerSourceOfIncomes.AddObject(customerSourceOfIncome); return customerSourceOfIncome; }
protected void ButtonSave_Click(object sender, EventArgs e) { LiteralMessage.Text = string.Empty; if ( !string.IsNullOrEmpty(TextBoxLogin.Text.Trim()) && !string.IsNullOrEmpty(TextBoxPassword.Text.Trim()) && DropDownListType.SelectedItem != null && DropDownListType.SelectedValue != "0") { BusinessLogic.Customer NewCustomer = new BusinessLogic.Customer(); NewCustomer.Id = null; NewCustomer.Login = TextBoxLogin.Text.Trim(); NewCustomer.Password = TextBoxPassword.Text.Trim(); NewCustomer.CurrentType = BusinessLogic.CustomerType.GetList().Find(temp => temp.Id == Convert.ToInt32(DropDownListType.SelectedValue)); string ErrorMessage; bool Result = false; if (Request.QueryString["id"] == null) { Result = NewCustomer.Add(out ErrorMessage); } else { int IdResult; bool IdToIntResult = int.TryParse(Request.QueryString["id"], out IdResult); if (IdToIntResult) { NewCustomer.Id = IdResult; Result = NewCustomer.Update(out ErrorMessage); } else { ErrorMessage = "Id not found"; } } if (Result) { LiteralMessage.Text = "Data was saved"; } else { LiteralMessage.Text = ErrorMessage; } } }
public static List<CustomerSourceOfIncome> GetAllActive(Customer customer) { return customer.CustomerSourceOfIncomes.Where(entity => entity.EndDate == null && entity.PartyRoleId == customer.PartyRoleId).ToList(); }
public static CustomerSourceOfIncome GetActive(Customer customer, SourceOfIncome sourceOfIncome) { return customer.CustomerSourceOfIncomes.FirstOrDefault(entity => entity.EndDate == null && entity.SourceOfIncomeId == sourceOfIncome.Id); }