protected void btnRegister_Click(object sender, EventArgs e) { if (Page.IsValid) { MembershipUser user = Membership.CreateUser(txtUserName.Text.Trim(), txtPassword.Text); CustomersEntity customer = new CustomersEntity(); customer.Id = new Guid(user.ProviderUserKey.ToString()); customer.UserName = user.UserName; customer.FullName = Filter.GetStringNoHtml(txtFullname.Text.Trim(), CustomersFields.FullName.MaxLength); customer.Email = Filter.GetMaxString(txtEmail.Text.Trim(), CustomersFields.Email.MaxLength); customer.Address = Filter.GetStringNoHtml(txtAddress.Text.Trim(), CustomersFields.Address.MaxLength); customer.IsAccount = true; CustomersManager.CreateInstant().Insert(customer); user.Email = txtEmail.Text.Trim(); Membership.UpdateUser(user); Roles.AddUserToRole(user.UserName, Modules.Role.EnumsRoles.UserMember); FormsAuthentication.SetAuthCookie(user.UserName, true); Response.Redirect("/", true); } }
public bool Delete(Guid Id) { bool toReturn = false; using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter()) { CustomersEntity _CustomersEntity = new CustomersEntity(Id); if (adapter.FetchEntity(_CustomersEntity)) { adapter.DeleteEntity(_CustomersEntity); toReturn = true; } } return toReturn; }
protected void Page_Load(object sender, EventArgs e) { if (Request["status"] == "1") { MarkTransferEntity od = MarkTransferManager.CreateInstant().GetByCode(Request["ordercode"]); if (od != null) { Session["PAY"] = true; // chi tiet nop tien MarkAddHistoryEntity hisobj = new MarkAddHistoryEntity(); // kt user da ton tai trong bang customer chua CustomersEntity CusObj = new CustomersEntity(); CustomersEntity CusTemp = CustomersManager.CreateInstant().GetByName(Util.CurrentUserName); if (CusTemp != null) //kt user da ton tai trong bang customer chua { hisobj.MarkBeforeAdd = CusTemp.Mark; CusObj = CusTemp; CusObj.Mark = CusObj.Mark + od.Mark; CustomersManager.CreateInstant().Update(CusObj); } else { hisobj.MarkBeforeAdd = 0; CusObj.Id = Guid.NewGuid(); CusObj.UserName = Util.CurrentUserName; CusObj.FullName = Profile.FullName; CusObj.Mark = od.Mark; CustomersManager.CreateInstant().Insert(CusObj); } hisobj.Id = Guid.NewGuid(); hisobj.CustomerId = CusObj.Id; hisobj.CodeMarkId = Guid.Empty; hisobj.Date = DateTime.Now; hisobj.MarkAfterAdd = CusObj.Mark; hisobj.CreatedBy = Util.CurrentUserName; hisobj.CreatedDate = DateTime.Now; hisobj.IsDeleted = false; MarkAddHistoryManager.CreateInstant().Insert(hisobj); Response.Redirect("/Payment/Thankyou.aspx?t=" + NganLuong.PayDoc + "&id=" + od.Id.ToString()); } } Response.Redirect("/"); }
/// <summary> /// Gets the customer with the most orders and also the customers' number of orders. /// </summary> /// <param name="numberOfOrders">The number of orders.</param> /// <returns>the CustomerEntity with the most orders and also the number of orders of this customer</returns> /// <remarks>No error checking is applied to this routine, it's for illustrating the framework functionality.</remarks> public IEntity2 GetCustomerWithMostOrdersAndNumberOfOrders(out int numberOfOrders) { CustomersEntity toReturn = null; using (DataAccessAdapter adapter = new DataAccessAdapter()) { // create a list to obtain the customerid + # of orders. We'll just fetch the 1st row, ordering on the # of orders. ResultsetFields orderCustomerFields = new ResultsetFields(2); orderCustomerFields.DefineField(OrdersFields.CustomerId, 0, "CustomerId"); orderCustomerFields.DefineField(OrdersFields.OrderId, 1, "NumberOfOrders", "", AggregateFunction.Count); GroupByCollection groupBy = new GroupByCollection(); groupBy.Add(orderCustomerFields[0]); SortExpression sorter = new SortExpression(); sorter.Add(new SortClause(orderCustomerFields[1], null, SortOperator.Descending)); // now fetch the list, specify to fetch just 1 row, ordered descending on amount DataTable orderCustomer = new DataTable(); adapter.FetchTypedList(orderCustomerFields, orderCustomer, null, 1, sorter, true, groupBy); numberOfOrders = (int)orderCustomer.Rows[0]["NumberOfOrders"]; // we'll assume the data was there, so there is a row. toReturn = new CustomersEntity(orderCustomer.Rows[0]["CustomerId"].ToString()); adapter.FetchEntity(toReturn); } return(toReturn); }
/// <summary> /// Calculates the statistics for the Northwind database and shows them in the form, utilizing the remote service for the actual work. /// </summary> /// <remarks>No error checking is applied to this routine, it's for illustrating the framework functionality.</remarks> private void CalculateStatistics() { // use the service to obtain the information needed. // get the # of customers in the database. _amountCustomersTextBox.Text = MainForm.DalService.GetNumberOfCustomers().ToString(); // get highest order price, order id of order with highest price, average price. decimal averageOrderPrice = 0.0M; decimal highestOrderPrice = 0.0M; int orderIdWithHighestPrice = 0; int numberOfOrders = 0; MainForm.DalService.GetOrderStatistics(out averageOrderPrice, out highestOrderPrice, out numberOfOrders, out orderIdWithHighestPrice); _highestOrderPriceTextBox.Text = highestOrderPrice.ToString("C"); _averageOrderPriceTextBox.Text = averageOrderPrice.ToString("C"); // get order with highest price. Pull customer also in 1 go OrdersEntity highestOrder = (OrdersEntity)MainForm.DalService.GetOrderAndCustomerWithHighestPrice(orderIdWithHighestPrice); _customerWithHighestOrder = highestOrder.Customers; // already loaded through prefetch path. _highestOrderCustomerTextBox.Text = _customerWithHighestOrder.CompanyName; // get customer with most orders. int numberOfOrdersForTopCustomer = 0; _customerWithMostOrders = (CustomersEntity)MainForm.DalService.GetCustomerWithMostOrdersAndNumberOfOrders(out numberOfOrdersForTopCustomer); _mostOrdersPerCustomerTextBox.Text = numberOfOrdersForTopCustomer.ToString(); _mostOrdersCustomerTextBox.Text = _customerWithMostOrders.CompanyName; }
/// <summary> /// Gets the customer entity with the id specified /// </summary> /// <param name="customerId">The customer id.</param> /// <returns>customer entity with the id specified.</returns> public IEntity2 GetCustomer(string customerId) { CustomersEntity toReturn = new CustomersEntity(customerId); using (DataAccessAdapter adapter = new DataAccessAdapter()) { adapter.FetchEntity(toReturn); } return(toReturn); }
/// <summary> /// CTor /// </summary> public CustomerManager() { InitializeComponent(); _currentCustomer = null; _customerObjectIsBinded = false; // block resizing beyond a minimum; this.MinimumSize = this.Size; _ordersCManager = null; _visitedOrderDetails = new List <EntityCollection <OrderDetailsEntity> >(); }
/// <summary> /// CTor /// </summary> public MainForm() { InitializeComponent(); this.MinimumSize = this.Size; _customerWithMostOrders = null; _customerWithHighestOrder = null; // calculate statistics for northwind and show these in the form. CalculateStatistics(); }
/// <summary> /// Gets the customer entity + orders + order details for the customer of the customer id passed in. /// </summary> /// <param name="customerId">The customer id.</param> /// <returns>Customer entity with its order entities + order details entities per order for the customer passed in.</returns> public IEntity2 GetCustomerWithFullOrders(string customerId) { // fetch customer, orders and order details in one go with a prefetch path. CustomersEntity toReturn = new CustomersEntity(customerId); PrefetchPath2 path = new PrefetchPath2((int)EntityType.CustomersEntity); // add orders to the path, specify to sort the orders on order id ascending. path.Add(CustomersEntity.PrefetchPathOrders, 0, null, null, new SortExpression(OrdersFields.OrderId | SortOperator.Ascending)) .SubPath.Add(OrdersEntity.PrefetchPathOrderDetails); using (DataAccessAdapter adapter = new DataAccessAdapter()) { adapter.FetchEntity(toReturn, path); } return(toReturn); }
private void saveCustomerButton_Click(object sender, System.EventArgs e) { // save the customer, not recursively, as we just want to save the customer. bool succeeded = MainForm.DalService.SaveCustomer(_currentCustomer, false); if (succeeded) { MessageBox.Show("Save was succesful!", "Save result", MessageBoxButtons.OK, MessageBoxIcon.Information); saveCustomerButton.Enabled = false; } else { MessageBox.Show(this, "Save was NOT succesful!", "Save result", MessageBoxButtons.OK, MessageBoxIcon.Information); } CustomersEntity newData = (CustomersEntity)MainForm.DalService.GetCustomer(_currentCustomer.CustomerId); // as remoting copies objects, we want to keep the old customer object but with the data refetched from the service _currentCustomer.Fields = newData.Fields; }
public async Task <IActionResult> AddCustomer([FromBody] CustomerModel customerModel) { var userId = HttpContext.GetCurrentUserId(); if (userId is null) { return(Unauthorized()); } var customersEntity = _customerEntity.Queryable.FirstOrDefault(t => t.Name == customerModel.Name); if (customersEntity != null) { return(BadRequest("A customer with the same name exists")); } var customerEntity = new CustomersEntity(customerModel.Name, customerModel.Rebate, customerModel.SellRate, Guid.NewGuid().ToString(), false); await _customerEntity.AddAsync(customerEntity); return(Ok()); }
/// <summary> /// Fetches the customer + orders + order details from the service for the customer passed in, /// adding values of the customer to the controls on the form and setting /// up eventhandlers so the gui is aware of changes of the customer or its contents. /// </summary> /// <param name="customer"></param> private void SetCustomerAsCurrent(string customerId) { if (_currentCustomer != null) { // first remove the eventhandlers from the current object _currentCustomer.PropertyChanged -= new PropertyChangedEventHandler(_currentCustomer_PropertyChanged); _currentCustomer.Orders.ListChanged -= new ListChangedEventHandler(Orders_ListChanged); } if (_ordersCManager != null) { // remove the currency manager. _ordersCManager.PositionChanged -= new EventHandler(_ordersCManager_PositionChanged); _ordersCManager = null; } // get new graph from server _currentCustomer = (CustomersEntity)MainForm.DalService.GetCustomerWithFullOrders(customerId); // bind the customer to the gui elements. BindCustomerToGui(); }
public bool Update(CustomersEntity _CustomersEntity) { bool toReturn = false; using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter()) { RelationPredicateBucket filter = new RelationPredicateBucket(); IPredicateExpression _PredicateExpression = new PredicateExpression(); _PredicateExpression.Add(CustomersFields.Id == _CustomersEntity.Id); filter.PredicateExpression.Add(_PredicateExpression); adapter.UpdateEntitiesDirectly(_CustomersEntity, filter); toReturn = true; } return toReturn; }
public CustomersEntity SelectOne(Guid Id) { CustomersEntity toReturn = null; using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter()) { CustomersEntity _CustomersEntity = new CustomersEntity(Id); if (adapter.FetchEntity(_CustomersEntity)) { toReturn = _CustomersEntity; } } return toReturn; }
OrdersEntity getOrder(CustomersEntity customer) { OrdersEntity order = new OrdersEntity(); order.Id = Guid.NewGuid(); order.OrderCode = OrderCode.CreateInstant().GetNumber(); order.CustomerId = customer.Id; order.CustomerName = customer.FullName; order.CustomerEmail = customer.Email; order.CustomerPhone = customer.Mobi; order.CustomerAddress = customer.Address; order.TotalAmountBeforeTax = TotalAmountBeforeTax; order.TotalAmountAfterTax = TotalAmountAfterTax; order.TotalDiscount = 0; order.TotalOther = 0; order.TotalPaid = order.TotalAmountAfterTax + order.TotalOther - order.TotalDiscount; order.TotalCommission = 0; order.TotalAllSupplier = 0; order.PaymentMethod = ucPayment.PaymentMethod; return order; }
protected void btSubmit_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(Util.CurrentUserName)) { CodeMarkEntity obj = CodeMarkManager.CreateInstant().GetByCode(txtCode.Text.Trim()); if (obj != null) { // chi tiet nop tien MarkAddHistoryEntity hisobj = new MarkAddHistoryEntity(); // kt user da ton tai trong bang customer chua CustomersEntity CusObj=new CustomersEntity(); CustomersEntity CusTemp = CustomersManager.CreateInstant().GetByName(Util.CurrentUserName); if (CusTemp != null) //kt user da ton tai trong bang customer chua { if (CusTemp.Mark < Modules.Document.DocumentConfig.MaxMark) { hisobj.MarkBeforeAdd = CusTemp.Mark; CusObj = CusTemp; CusObj.Mark = CusObj.Mark + obj.Mark; CustomersManager.CreateInstant().Update(CusObj); } else { CustomValidator1.ErrorMessage = "Số điểm hiện tại của bạn đã đạt giới hạn (giới hạn: "+ Modules.Document.DocumentConfig.MaxMark+" điểm), vui lòng giữ lại mã số và nạp điểm vào lần sau"; CustomValidator1.IsValid = false; return; } } else { hisobj.MarkBeforeAdd = 0; CusObj.Id = Guid.NewGuid(); CusObj.UserName = Util.CurrentUserName; CusObj.FullName = Profile.FullName; CusObj.Mark = obj.Mark; CustomersManager.CreateInstant().Insert(CusObj); } hisobj.Id = Guid.NewGuid(); hisobj.CustomerId = CusObj.Id; hisobj.CodeMarkId = obj.Id; hisobj.Date = DateTime.Now; hisobj.MarkAfterAdd = CusObj.Mark; hisobj.CreatedBy = Util.CurrentUserName; hisobj.CreatedDate = DateTime.Now; hisobj.IsDeleted = false; MarkAddHistoryManager.CreateInstant().Insert(hisobj); obj.IsDeleted = true; CodeMarkManager.CreateInstant().Update(obj); CustomValidator1.ErrorMessage = "Nạp điểm thành công"; CustomValidator1.IsValid = false; } else { CustomValidator1.ErrorMessage = "Mã số không tồn tại"; CustomValidator1.IsValid = false; return; } } else Response.Redirect(CheckRoles.CreateInstant().GetUrlDirect(Request.RawUrl)); }
public CustomersEntity Insert(CustomersEntity _CustomersEntity) { using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter()) { adapter.SaveEntity(_CustomersEntity, true); } return _CustomersEntity; }
public bool Update(CustomersEntity _CustomersEntity, RelationPredicateBucket filter) { bool toReturn = false; using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter()) { adapter.UpdateEntitiesDirectly(_CustomersEntity, filter); toReturn = true; } return toReturn; }
public bool Update(Guid Id, string UserName, string FullName, string Telphone, string Mobi, string Email, long Mark, string CountryCode, string CityCode, string DistrictCode, string Address) { bool toReturn = false; using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter()) { CustomersEntity _CustomersEntity = new CustomersEntity(Id); if (adapter.FetchEntity(_CustomersEntity)) { _CustomersEntity.UserName = UserName; _CustomersEntity.FullName = FullName; _CustomersEntity.Telphone = Telphone; _CustomersEntity.Mobi = Mobi; _CustomersEntity.Email = Email; _CustomersEntity.Mark = Mark; _CustomersEntity.CountryCode = CountryCode; _CustomersEntity.CityCode = CityCode; _CustomersEntity.DistrictCode = DistrictCode; _CustomersEntity.Address = Address; adapter.SaveEntity(_CustomersEntity, true); toReturn = true; } } return toReturn; }
private void selectButton_Click(object sender, System.EventArgs e) { _cancelClicked = false; _selectedCustomer = (CustomersEntity)_allCustomers[customersDataGrid.CurrentRowIndex]; this.Close(); }
public CustomersEntity Insert(string UserName, string FullName, string Telphone, string Mobi, string Email, long Mark, string CountryCode, string CityCode, string DistrictCode, string Address) { CustomersEntity _CustomersEntity = new CustomersEntity(); using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter()) { _CustomersEntity.UserName = UserName; _CustomersEntity.FullName = FullName; _CustomersEntity.Telphone = Telphone; _CustomersEntity.Mobi = Mobi; _CustomersEntity.Email = Email; _CustomersEntity.Mark = Mark; _CustomersEntity.CountryCode = CountryCode; _CustomersEntity.CityCode = CityCode; _CustomersEntity.DistrictCode = DistrictCode; _CustomersEntity.Address = Address; adapter.SaveEntity(_CustomersEntity, true); } return _CustomersEntity; }
CustomersEntity getCustomer() { CustomersEntity customer = new CustomersEntity(); customer.Id = Guid.NewGuid(); customer.UserName = Util.CurrentUserName; customer.FullName = Filter.GetStringNoHtml(txtCustomerName.Text.Trim(), CustomersFields.FullName.MaxLength); customer.Email = Filter.GetMaxString(txtCustomerEmail.Text.Trim(), CustomersFields.Email.MaxLength); customer.Address = Filter.GetStringNoHtml(txtCustomerAddress.Text.Trim(), CustomersFields.Address.MaxLength); customer.Mobi = Filter.GetStringNoHtml(txtCustomerPhone.Text.Trim(), CustomersFields.Mobi.MaxLength); return customer; }
/// <summary> /// CTor /// </summary> /// <param name="customer">the customer to manage</param> public CustomerManager(CustomersEntity customer) : this() { // load customer and set as active. SetCustomerAsCurrent(customer.CustomerId); }
protected void lnkDown_Click(object sender, EventArgs e) { DocumentEntity doc = DocumentManager.CreateInstant().GetByIntId(IntId); if (doc != null) { // kiem tra dang nhap // kiem tra diem if (!string.IsNullOrEmpty(Util.CurrentUserName)) // kt dang nhap { CustomersEntity CusObj = CustomersManager.CreateInstant().GetByName(Util.CurrentUserName); if (CusObj != null) //kt user da ton tai trong bang customer chua { if (CusObj.Mark >= doc.Mark) // kt customer co du diem down tai lieu nay khong { //Response.Redirect("/Modules/Document/Download.aspx?id=" + IntId, false); // Tru diem va luu lai history download string temp = "0"; temp = (string)Session["flagdown"]; if (temp == "0" || string.IsNullOrEmpty(temp)) { DownLoadHistoryEntity downObj = new DownLoadHistoryEntity(); downObj.CustomerId = CusObj.Id; downObj.DocumentId = doc.Id; downObj.Date = DateTime.Now; downObj.MarkBeforeDown = CusObj.Mark; downObj.MarkAfterDown = CusObj.Mark - doc.Mark; downObj.CreatedBy = Util.CurrentUserName; downObj.CreatedDate = DateTime.Now; downObj.IsDeleted = false; DownLoadHistoryManager.CreateInstant().Insert(downObj); // tru diem CusObj.Mark = CusObj.Mark - doc.Mark; CustomersManager.CreateInstant().Update(CusObj); Session["flagdown"] = "1"; } string ext = doc.PathName.Substring(doc.PathName.LastIndexOf(".") + 1); WebUtility.DownLoadFile(Page, doc.TextId + "." + ext, Server.MapPath(doc.PathName)); Response.Redirect(Request.RawUrl); } else { // Xu ly cho truong hop khong du diem down tai lieu Response.Redirect(Modules.Document.UrlBuilder.DownLoadGuide1(0)); } } else { CustomersEntity obj = new CustomersEntity(); obj.UserName = Util.CurrentUserName; obj.FullName = Profile.FullName; CustomersManager.CreateInstant().Insert(obj); // sau khi insert vo bang customer bao cho kh bit la ho chua du diem download Response.Redirect(Modules.Document.UrlBuilder.DownLoadGuide1(0)); } } } }