protected void Page_Load(object sender, EventArgs e) { EditOrderActions curAction = EditOrderActions.ViewOnly; LoadBonus(ddltoAddress.SelectedValue); OrderBonus.CleanBonusData(OrderId); //btnPrint.OnClientClick = @"window.open('../report/printorder.aspx?oid=" + OrderId + "','printOrder_at_" + DateTime.Now.ToString("dd_MM_yyyy_hh_mm_ss") + "',''); return false;"; phInventoryLock.Visible = false; phOldItemNotOnSale.Visible = false; if (!Page.IsPostBack) { //EnablePrint(false); PageMode = PageModes.Input; txtOrderDate.Text = GetFullDateString(DateTime.Now.ToShortDateString(), "/"); //txtOrderDate.Text = DateTime.Now.ToShortDateString(); if (OrderId != 0) { LoadOrderPayments(OrderId); //LoadOrderBonus(OrderId); IDao<Orderheader, long> dao = DaoFactory.GetDao<Orderheader, long>(); Value = dao.GetById(OrderId, false); if (Value != null) { // load order detail LoadOrderItems(); ReCheckItems(_items); if ( (!IsDealer || (Value.Status == (int)OrderStatus.Draft) || (Value.Status == (int)OrderStatus.Sent)) && OrderDAO.CanWriteToInterface(Value.Id) ) { curAction = EditOrderActions.EditOldOrder; } else { curAction = EditOrderActions.ViewOnly; } } } else { //if (InventoryHelper.IsInventoryLock(DateTime.Now, UserHelper.DealerCode)) GoHome(); curAction = EditOrderActions.EditNewOrder; } if (!IsDealer) { mvComment.ActiveViewIndex = 1; //ddltoAddress.Enabled = false; } // check for inventory lock Validator.SetDateRange(rvOrderDate, InventoryHelper.GetLockedDate(ddltoAddress.SelectedValue, ddlSecondaryAddress.SelectedValue).AddMonths(1), DateTime.MaxValue, true); if (InventoryHelper.IsInventoryLock(DateTime.Now, ddltoAddress.SelectedValue, ddlSecondaryAddress.SelectedValue)) { curAction = EditOrderActions.ViewOnly; phInventoryLock.Visible = true; } else { phInventoryLock.Visible = false; } SetAction(curAction); // page mode here BindData(); } }
private void SetAction(EditOrderActions action) { CurAction = action; // default bool showPrintBtn = (Value != null) && (Value.Id > 0); cmdDelete.Enabled = cmdSave.Enabled = cmdSend.Enabled = false; cmdFinish.Visible = cmdEdit.Visible = false; gvMain.Visible = gvPreview.Visible = false; cmdComputePrice.Enabled = false; EnablePaymentEdit(false); switch (action) { case EditOrderActions.FinishEdit: cmdEdit.Visible = true; cmdSave.Enabled = true; cmdSend.Enabled = (Value == null) || (Value.Status == (int)OrderStatus.Draft); gvPreview.Visible = true; break; case EditOrderActions.ViewWithCommands: cmdEdit.Visible = true; cmdSend.Enabled = (Value == null) || (Value.Status == (int)OrderStatus.Draft); cmdDelete.Enabled = (Value != null) && (Value.Status != (int)OrderStatus.Confirmed); gvPreview.Visible = true; break; case EditOrderActions.ViewOnly: gvPreview.Visible = true; PageMode = PageModes.PreCalcul; break; case EditOrderActions.EditOldOrder: cmdDelete.Enabled = (Value != null) && (Value.Status != (int)OrderStatus.Confirmed); cmdFinish.Visible = true; cmdEdit.Visible = false; gvMain.Visible = true; cmdComputePrice.Enabled = true; EnablePaymentEdit(true); break; case EditOrderActions.EditNewOrder: Value = null; // force bind dealer info showPrintBtn = false; cmdFinish.Visible = true; gvMain.Visible = true; cmdComputePrice.Enabled = true; EnablePaymentEdit(true); break; } EnablePrint(showPrintBtn); gvPayment.DataBind(); gvBonus.DataBind(); }
public bool SaveOrder(int OrderStatus) { bool res = true; long oldId = OrderId; // for save payment var dto = UserHelper.ParseDate(txtOrderDate.Text, true); var daooh = DaoFactory.GetDao<Orderheader, long>(); var daood = DaoFactory.GetDao<Orderdetail, long>(); Orderheader oh; //dto = Order.FixOrderDate(dto); if (Value != null) { oh = daooh.GetById(Value.Id, false); if (oh.Status == (int)VDMS.I.Vehicle.OrderStatus.Confirmed) return false; if (oh.Status == (int)VDMS.I.Vehicle.OrderStatus.Approved && UserHelper.IsDealer) return false; } else oh = Order.CreateNewOrderHeaderDefault(dto); // Update OrderHeader oh.Shippingto = ddltoAddress.SelectedValue; //if (ddlSecondaryAddress.SelectedIndex != 0) { oh.Secondaryshippingcode = ddlSecondaryAddress.SelectedValue; oh.Secondaryshippingto = ddlSecondaryAddress.SelectedItem.Text; } if (IsDealer) oh.Dealercomment = txtDealerComment.Text; else oh.Vmepcomment = txtVmepComment.Text; if (OrderStatus != -1) oh.Status = OrderStatus; // To Database using (TransactionBlock tran = new TransactionBlock()) { try { oh = daooh.SaveOrUpdate(oh); // delete all old items if (Value != null) { Order.DeleteOrderItems(Value.Id, ref daood); } // add edited items foreach (ItemOrder item in _items) { item.Orderheader = oh; daood.SaveOrUpdate(item.Base); } oh.Subtotal = _items.Sum(d => d.Unitprice * d.Orderqty); tran.IsValid = true; OrderId = oh.Id; } catch { tran.IsValid = false; res = false; } } this.Value = oh; // payment if (res) res = SavePayment(oldId, oh.Id); VDMS.II.Linq.DCFactory.RemoveDataContext<VDMS.I.Linq.VehicleDataContext>(); VDMS.II.Linq.DCFactory.RemoveDataContext<VDMS.Bonus.Linq.BonusDataContext>(); LoadOrderPayments(OrderId); return res; }
protected override void LoadControlState(object savedState) { object[] ctlState = (object[])savedState; base.LoadControlState(ctlState[0]); this._value = (Orderheader)ctlState[1]; this._items = (List<ItemOrder>)ctlState[2]; this.PageMode = (PageModes)ctlState[3]; this._totalItemsCount = (int)ctlState[4]; }
/// <summary> /// Create new order header /// </summary> /// <returns></returns> public static Orderheader CreateNewOrderHeaderDefault(DateTime orderDate) { Orderheader res = new Orderheader(); DateTime dtNow = DateTime.Now; res.Createddate = dtNow; res.Createdby = UserHelper.Username; res.Lastediteddate = dtNow; res.Lasteditedby = UserHelper.Username; res.Orderdate = orderDate; res.Ordertimes = Order.GetOrderNumberByDate(orderDate, UserHelper.DealerCode); res.Shippingdate = dtNow; res.Status = (int)OrderStatus.Draft; res.Dealercode = UserHelper.DealerCode; res.Areacode = UserHelper.AreaCode; res.Databasecode = UserHelper.DatabaseCode; res.Deliveredstatus = (int)DeliveredOrderStatus.NotDeliveredAll; return res; }
public static Orderheader SendOrderHearder(Orderheader oh) { IDao<Orderheader, long> dao = DaoFactory.GetDao<Orderheader, long>(); oh.Status = (int)OrderStatus.Sent; return dao.SaveOrUpdate(oh); }
bool SynchronizeOrderDetail(string OrderNumber, IDao<Orderheader, long> ohDao, IDao<Orderdetail, long> odDao, Orderheader oh) { DataSet ds = VDMS.Data.TipTop.Order.GetOrderDetail(OrderNumber); long total = 0; foreach (DataRow row in ds.Tables[0].Rows) { if (!ItemDataSource.IsExistItem((string)row["ItemCode"], NEED_ITEM_AVAILABLE_ON_CONFIRM)) return false; Orderdetail od = new Orderdetail() { Createddate = DateTime.Now, Createdby = UserHelper.Username, Lastediteddate = DateTime.Now, Lasteditedby = UserHelper.Username, Unitprice = long.Parse(row["Price"].ToString()), Unitpricediscount = 0, Orderpriority = int.Parse((string)row["Priority"]), Orderqty = (int)((decimal)row["Quantity"]) }; total += (od.Unitprice * od.Orderqty); Item item = new Item() { Id = (string)row["ItemCode"] }; od.Item = item; od.Orderheader = oh; odDao.SaveOrUpdate(od); } oh.Subtotal = total; ohDao.SaveOrUpdate(oh); return true; }
private void BindData() { IDao<Orderheader, long> ohDao = DaoFactory.GetDao<Orderheader, long>(); _currentOrderHeader = ohDao.GetById(OrderId, false); //true -> false DataSet ds = OrderDao.GetOrderDetail(OrderId); gvMain.DataSource = ds; gvMain.DataBind(); gvSplit.DataSource = ds; gvSplit.DataBind(); int status = int.Parse(ds.Tables[0].Rows[0]["Status"].ToString()); if (status == (int)OrderStatus.Deleted) Response.Redirect("~/default.aspx"); if (status != (int)OrderStatus.Confirmed) { this.cmdEdit.OnClientClick = string.Format("javascript:location.href='EditOrder.aspx?OrderId={0}&Dealer=0'; return false;", OrderId); this.cmdSplit.CommandName = "SplitBefore"; } else { //this.cmdEdit.OnClientClick = string.Format("javascript:alert('{0}'); return false;", Message.OrderForm_DeleteConfirmedOrderError); //this.cmdApprove.OnClientClick = string.Format("javascript:alert('{0}'); return false;", Message.OrderForm_ApprovedConfirmedOrderError); this.cmdEdit.Enabled = this.cmdApprove.Enabled = false; this.cmdSplit.CommandName = "SplitAfter"; } if (!string.IsNullOrEmpty(_currentOrderHeader.Ordernumber) && !IsTipTopOrderValid(_currentOrderHeader.Ordernumber, _currentOrderHeader.Shippingto, false) ) this.cmdSplit.Enabled = false; if (status != (int)OrderStatus.Sent) cmdApprove.Enabled = false; lblStatus.Text = VDMS.I.Vehicle.Order.GetOrderStatusString(status); lblOrderDate.Text = ((DateTime)ds.Tables[0].Rows[0]["ORDERDATE"]).ToShortDateString(); lblOrderTimes.Text = ds.Tables[0].Rows[0]["ORDERTIMES"].ToString(); //lblShipingTo.Text = ds.Tables[0].Rows[0]["SHIPPINGTO"].ToString() + " - " + Dealer.GetAddressByBranchCode(ds.Tables[0].Rows[0]["SHIPPINGTO"].ToString()); lblDealerComment.Text = ds.Tables[0].Rows[0]["DEALERCOMMENT"].ToString(); lblSecondaryAddress.Text = ds.Tables[0].Rows[0]["SECONDARYSHIPPINGCODE"].ToString() + " - " + ds.Tables[0].Rows[0]["SECONDARYSHIPPINGTO"].ToString(); txtComment.Text = ds.Tables[0].Rows[0]["VMEPCOMMENT"] as string; txtOrder1Date.Text = ((DateTime)ds.Tables[0].Rows[0]["ORDERDATE"]).ToShortDateString(); txtOrder2Date.Text = DateTime.Now.ToShortDateString(); txtTipTopOrderNumber.Text = ds.Tables[0].Rows[0]["ORDERNUMBER"] as string; if (!string.IsNullOrEmpty(txtTipTopOrderNumber.Text)) txtTipTopOrderNumber.ReadOnly = true; }
protected override void LoadControlState(object savedState) { object[] ctlState = (object[])savedState; base.LoadControlState(ctlState[0]); this._currentOrderHeader = (Orderheader)ctlState[1]; this._OrderQueryInfo = (OrderQueryInformation)ctlState[2]; }
// tach truoc khi confirmed protected void cmdDoSplit_Click(object sender, EventArgs e) { int count1 = 0, count2 = 0; foreach (GridViewRow row in gvSplit.Rows) { count1 += int.Parse((row.Cells[2].Controls[1] as TextBox).Text); count2 += int.Parse((row.Cells[3].Controls[1] as TextBox).Text); } if (count1 == count2 || count2 == 0) { lblResult.Text = (string)GetLocalResourceObject("_EmptyOrderError"); return; } IDao<Orderheader, long> ohDao = DaoFactory.GetDao<Orderheader, long>(); IDao<Orderdetail, long> odDao = DaoFactory.GetDao<Orderdetail, long>(); using (TransactionBlock tran = new TransactionBlock()) { //get current order Orderheader oh = CurrentOrderHeader; // and mark current order to deleted oh.Status = (int)VDMS.I.Vehicle.OrderStatus.Deleted; oh.Lasteditedby = UserHelper.Username; oh.Lastediteddate = DateTime.Now; ohDao.SaveOrUpdate(oh); // get detail of this order odDao.SetCriteria(new ICriterion[] { Expression.Eq("Orderheader", oh) }); List<Orderdetail> listOd = odDao.GetAll(); // create two new orders Orderheader oh1 = new Orderheader(), oh2 = new Orderheader(); oh1.Createddate = oh2.Createddate = DateTime.Now; oh1.Createdby = oh2.Createdby = UserHelper.Username; oh1.Lastediteddate = oh2.Lastediteddate = DateTime.Now; oh1.Lasteditedby = oh2.Lasteditedby = UserHelper.Username; oh1.Ordernumber = oh2.Ordernumber = oh.Ordernumber; // set order date of two orders header DateTime oh1Date, oh2Date; DateTime.TryParse(txtOrder1Date.Text, new CultureInfo(UserHelper.Language), DateTimeStyles.AllowWhiteSpaces, out oh1Date); DateTime.TryParse(txtOrder2Date.Text, new CultureInfo(UserHelper.Language), DateTimeStyles.AllowWhiteSpaces, out oh2Date); oh1.Orderdate = oh1Date; oh2.Orderdate = oh2Date; oh1.Ordertimes = oh2.Ordertimes = 1; // TODO oh1.Shippingdate = oh2.Shippingdate = oh.Shippingdate; oh1.Shippingto = oh2.Shippingto = oh.Shippingto; oh1.Status = oh2.Status = (int)VDMS.I.Vehicle.OrderStatus.Sent; oh1.Dealercode = oh2.Dealercode = oh.Dealercode; oh1.Subtotal = oh2.Subtotal = 0; // TODO oh1.Taxamt = oh2.Taxamt = oh.Taxamt; oh1.Freight = oh2.Freight = oh.Freight; oh1.Dealercomment = oh2.Dealercomment = oh.Dealercomment; oh1.Vmepcomment = oh2.Vmepcomment = oh.Vmepcomment; oh1.Referenceorderid = oh2.Referenceorderid = (int)oh.Id; oh1.Databasecode = oh2.Databasecode = oh.Databasecode; oh1.Areacode = oh2.Areacode = oh.Areacode; // new on substore mgr oh1.Secondaryshippingcode = oh2.Secondaryshippingcode = oh.Secondaryshippingcode; oh1.Secondaryshippingto = oh2.Secondaryshippingto = oh.Secondaryshippingto; // save three orders ohDao.SaveOrUpdate(oh1); ohDao.SaveOrUpdate(oh2); int index = 0; foreach (GridViewRow row in gvSplit.Rows) { int total = int.Parse((row.Cells[2].Controls[1] as TextBox).Text); int q2 = int.Parse((row.Cells[3].Controls[1] as TextBox).Text); int q1 = total - q2; Orderdetail od1 = new Orderdetail(), od2 = new Orderdetail(); od1.Createddate = od2.Createddate = DateTime.Now; od1.Createdby = od2.Createdby = UserHelper.Username; od1.Lastediteddate = od2.Lastediteddate = DateTime.Now; od1.Lasteditedby = od2.Lasteditedby = UserHelper.Username; //od1.Unitprice = od2.Unitprice = listOd[index].Unitprice; //od1.Unitpricediscount = od2.Unitpricediscount = listOd[index].Unitpricediscount; //od1.Orderpriority = od2.Orderpriority = listOd[index].Orderpriority; //Orderdetail od = listOd.Find(delegate(Orderdetail d) { return d.Item.Id == row.Cells[0].Text; }); Orderdetail od = listOd.Find(d => d.Item.Id == row.Cells[0].Text); od1.Unitprice = od2.Unitprice = od.Unitprice; od1.Unitpricediscount = od2.Unitpricediscount = od.Unitpricediscount; od1.Orderpriority = od2.Orderpriority = od.Orderpriority; od1.Item = od2.Item = od.Item; od1.Orderheader = oh1; od2.Orderheader = oh2; if (q1 > 0) { od1.Orderqty = q1; odDao.SaveOrUpdate(od1); } if (q2 > 0) { od2.Orderqty = q2; odDao.SaveOrUpdate(od2); } index++; } tran.IsValid = true; } lblResult.Text = (string)GetLocalResourceObject("_ProcessComplete"); phGoback.Visible = true; DisableButton(); }
// tach sau khi confirmed protected void cmdDoConfirmSplit_Click(object sender, EventArgs e) { if (!Page.IsValid) return; string oldOder = txtOldOrderNumber.Text; string[] newOrders = txtNewOrderNumber.Text.Split(';'); IDao<Orderheader, long> ohDao = DaoFactory.GetDao<Orderheader, long>(); IDao<Orderdetail, long> odDao = DaoFactory.GetDao<Orderdetail, long>(); using (TransactionBlock tran = new TransactionBlock()) { //get current order Orderheader oh = CurrentOrderHeader; if (chkDeleted.Checked) oh.Status = (int)VDMS.I.Vehicle.OrderStatus.Deleted; oh.Lasteditedby = UserHelper.Username; oh.Lastediteddate = DateTime.Now; ohDao.SaveOrUpdate(oh); if (!chkDeleted.Checked) // mean sale modify old order { // first delete the order detail odDao.SetCriteria(new ICriterion[] { Expression.Eq("Orderheader", oh) }); foreach (Orderdetail obj in odDao.GetAll()) odDao.Delete(obj); // second, add new contain, do in later step } // create a new list order header List<Orderheader> newOh = new List<Orderheader>(); foreach (var newOrder in newOrders) { Orderheader noh = new Orderheader() { Createddate = DateTime.Now, Createdby = UserHelper.Username, Lastediteddate = DateTime.Now, Lasteditedby = UserHelper.Username, Ordernumber = newOrder, Orderdate = oh.Orderdate, Ordertimes = 1, Shippingdate = oh.Shippingdate, Shippingto = oh.Shippingto, Status = (int)OrderStatus.Confirmed, Dealercode = oh.Dealercode, Subtotal = 0, // TODO Taxamt = oh.Taxamt, Freight = oh.Freight, Dealercomment = oh.Dealercomment, Vmepcomment = oh.Vmepcomment, Referenceorderid = (int)oh.Id, Databasecode = oh.Databasecode, Areacode = oh.Areacode, // new on substore mgr Secondaryshippingcode = oh.Secondaryshippingcode, Secondaryshippingto = oh.Secondaryshippingto, }; newOh.Add(noh); ohDao.SaveOrUpdate(noh); } // create order detail, include old order if necessary int index = 0; bool b = true; foreach (var newOrder in newOrders) { if (!SynchronizeOrderDetail(newOrder, ohDao, odDao, newOh[index])) { tran.IsValid = false; b = false; lblError.Text = (string)GetLocalResourceObject("_ItemDefferent"); } index++; } if (!chkDeleted.Checked && b) { // ======> no need SynchronizeOrderDetail, order on interface auto sync //if (!SynchronizeOrderDetail(oh.Ordernumber, odDao, oh)) //{ // tran.IsValid = false; // lblError.Text = (string)GetLocalResourceObject("_ItemDefferent"); //} } if (b) tran.IsValid = true; } // if bonus hasnt confirmed yet, do it now - CR 21/7/2010 if (!chBConfirmed.Checked) OrderDAO.ChangeBonus(CurrentOrderHeader.Id, long.Parse(txtBonusAmount.Text), true, string.Empty); phGoback.Visible = true; DisableButton(); }