public void Delete(Int64 Id)
        {
            using (TransactionBlock tran = new TransactionBlock())
            {
                Shippingdetail item = new Shippingdetail();
                item.Id = Id;

                dao.Delete(item);
                tran.IsValid = true;
            }
        }
 public static bool Delete(string brokenCode)
 {
     IDao<Broken, long> bDao = DaoFactory.GetDao<Broken, long>();
     bDao.SetCriteria(new ICriterion[] { Expression.Eq("Brokencode", brokenCode.Trim()) });
     List<Broken> list = bDao.GetAll();
     if (list.Count != 1) return false;
     try
     {
         using (TransactionBlock trans = new TransactionBlock())
         {
             Broken item = (Broken)list[0];
             bDao.Delete(item);
             trans.IsValid = true;
         }
     }
     catch { return false; }
     return true;
 }
    protected void cmdSynchronize_Click(object sender, EventArgs e)
    {
        DataSet ds = Motorbike.GetAllAvailable();

        IDao<Item, string> dao = DaoFactory.GetDao<Item, string>();
        using (TransactionBlock tran = new TransactionBlock())
        {
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                Item item1 = dao.GetById((string)row["ItemCode"], false); //true -> false
                if (item1 != default(Item))
                {
                    if (item1.DatabaseCode != null && item1.DatabaseCode.IndexOf(UserHelper.DatabaseCode) > -1)
                        continue;
                    item1.DatabaseCode += UserHelper.DatabaseCode;
                    dao.SaveOrUpdate(item1);
                    continue;
                }

                Item item = new Item();
                item.Id = (string)row["ItemCode"];
                if (!row.IsNull("ItemName")) item.Itemname = (string)row["ItemName"];
                else item.Itemname = " ";
                item.Itemtype = ((string)row["ItemCode"]).Split('-')[0];
                item.Price = (long)(decimal)row["Price"];
                item.Colorcode = ((string)row["ColorCode"]).Trim();
                if (!row.IsNull("ColorName")) item.Colorname = ((string)row["ColorName"]).Trim();
                else item.Colorname = " ";
                item.DatabaseCode = UserHelper.DatabaseCode;
                //item.Available = false;

                dao.Save(item);
            }
            tran.IsValid = true;
        }
        ReLoad();
    }
 // overWrite == false : donot over Write status if it verified
 private void BatchVerify(bool overWrite, ExchangeVoucherStatus status)
 {
     bool hasErr = false;
     using (var tran = new VDMS.Data.DAL.NHibernateDAL.TransactionBlock())
     {
         for (int i = 0; i < lvEv.Items.Count; i++)
         {
             var res = ExchangeVoucherBO.ChangeExchangeStatus((long)lvEv.DataKeys[i].Value, status, overWrite);
             if (res != VerifyExchangeErrorCode.OK) { AddError(res); hasErr = true; break; }
         }
         // need rollback ????
         if (!hasErr) ExchangeVoucherBO.DC.SubmitChanges();
         //if (!hasErr) Response.Redirect(Request.Url.ToString(), true);
     }
 }
    private bool SaveSheet(ServiceStatus status)
    {
        // check service type
        //if (chblSerList.SelectedIndex < 0) { AddError(WarrantyContentErrorCode.InvalidServiceType); return false; }

        ////////////////////////////////////////
        int serviceType = 0;
        long km, fee, total;
        DateTime serDate, buyDate;
        DateTimeFormatInfo dti = Thread.CurrentThread.CurrentCulture.DateTimeFormat;
        WarrantyContentErrorCode error = WarrantyContentErrorCode.OK;
        string model, plateNumber, frameNumber, errStatus, solution, color;

        // colect header infos
        model = txtModel.Text;
        plateNumber = txtNumberPlate.Text;
        frameNumber = txtFrameNumber.Text;
        errStatus = txtErrorStatus.Text;
        solution = txtRepair.Text;
        total = CalculateTotalAmount();
        color = ddlColour.SelectedValue;

        DateTime.TryParse(txtRepairDate.Text, dti, DateTimeStyles.AllowWhiteSpaces, out serDate);
        DateTime.TryParse(txtBuyDate.Text, dti, DateTimeStyles.AllowWhiteSpaces, out buyDate);

        long.TryParse(txtKm.Text, out km);
        long.TryParse(_feeAmount, out fee);
        serviceType = GetSelectedServices();

        using (TransactionBlock trans = new TransactionBlock())
        {
            // check last km count before save
            WarrantyInfo warrInfo = ServiceTools.GetWarrantyInfo(hdEngineNumber.Value);
            long.TryParse(txtLastKm.Text, out changedLastKm);
            if ((warrInfo != null) && (changedLastKm != warrInfo.KmCount))
            {
                AddError(WarrantyContentErrorCode.LastKmChanged);
                _finish = false;
                CheckFinish();
                txtLastKm.Text = warrInfo.KmCount.ToString();
                return false;
            }

            // save service header                                                  // ddlBranchCode.SelectedValue
            Serviceheader serH = WarrantyContent.SaveSerHeader(_editSheetId, status, CurrentDealer, CurrentBranch, hdEngineNumber.Value, plateNumber, frameNumber, model, color, errStatus, solution, _exchangeNumber, serviceType, _custInfo, km, fee, total, serDate, buyDate, out error);
            if ((serH == null) || (error != WarrantyContentErrorCode.OK)) { AddError(error); trans.IsValid = false; return false; }

            // save service details
            error = WarrantyContent.SaveSerDetails(gvSpareList.DataSourceTable, serH);
            if (error != WarrantyContentErrorCode.OK) { AddError(error); trans.IsValid = false; return false; }
            _editSheetId = serH.Id;

            // save exchange spares (also addErr)
            trans.IsValid = SaveExchangeSpares(status, _exchangeHeader, serH, AddExchange1.SpareList, AddExchange1.TotalFee);

            // save warranty info
            if ((_itemExist) && (status != ServiceStatus.Temp))
            {
                // cho nay ko update customer
                if (!ServiceTools.SaveWarrantyInfo(hdEngineNumber.Value, Convert.ToInt32(km), buyDate, _sVehicleDB, model, color, _sVehicleDealer, 0))
                {
                    AddError(WarrantyContentErrorCode.UpdateDataFailed);
                    trans.IsValid = false; return false;
                }
            }

            // show real sheet no
            txtSheetNo.Text = serH.Servicesheetnumber;
            // refresh exchange items with saved VoucherNumber
            if ((_exchangeHeader != null) && (AddExchange1.SpareList != null) && (AddExchange1.SpareList.Rows.Count > 0)) CopyExchangeList();
        }

        return true;
    }
    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;
    }
        public static void DeleteSRS(long sheetId)
        {
            if (CanDeleteSRS(sheetId))
            {
                using (TransactionBlock tran = new TransactionBlock())
                {
                    try
                    {
                        IDao<Serviceheader, long> daos = DaoFactory.GetDao<Serviceheader, long>();
                        Serviceheader sh = daos.GetById(sheetId, true);

                        if ((sh != null)
                            //&& (sh.Status >= 0)
                           )
                        {
                            IDao<Servicedetail, long> daosd = DaoFactory.GetDao<Servicedetail, long>();
                            IDao<Exchangepartheader, long> daox = DaoFactory.GetDao<Exchangepartheader, long>();
                            IDao<Exchangepartdetail, long> daoxd = DaoFactory.GetDao<Exchangepartdetail, long>();

                            // delete exchange part
                            daox.SetCriteria(new ICriterion[] { //Expression.Ge("Status", 0),
                                                Expression.Eq("Serviceheader.Id", sheetId) });
                            foreach (Exchangepartheader item in daox.GetAll())
                            {
                                daoxd.SetCriteria(new ICriterion[] { Expression.Eq("Exchangepartheader.Id", item.Id) });
                                foreach (Exchangepartdetail xDetail in daoxd.GetAll())
                                {
                                    daoxd.Delete(xDetail);
                                }
                                daox.Delete(item);
                            }

                            // delete service sheet
                            daosd.SetCriteria(new ICriterion[] { Expression.Eq("Serviceheader.Id", sheetId) });
                            foreach (Servicedetail item in daosd.GetAll())
                            {
                                daosd.Delete(item);
                            }
                            daos.Delete(sh);
                        }
                        tran.IsValid = true;
                    }
                    catch
                    {
                        tran.IsValid = false;
                    }
                }
            }
        }
Example #8
0
    private bool SaveShippingDetail2()
    {
        string exception, shipNumber, itemCode, engineNumber, itemType, color, orderNumber, shipTo, branchCode;
        Int32 status;
        bool hasVoucher;
        ImportItemStatus IisStatus;
        Iteminstance IInst = null;
        ItemStatus hisItemStatus;
        DateTime madeDate, impDate, itemImpDate;
        Shippingdetail SD;
        long Price;

        VDMS.Core.Domain.Item item = null;
        long shipID;
        ISession sess = NHibernateSessionManager.Instance.GetSession();

        using (TransactionBlock trans = new TransactionBlock())
        {
            try
            {
                if ((!DateTime.TryParse(txtImportDate.Text, new CultureInfo(UserHelper.Language), DateTimeStyles.AllowWhiteSpaces, out impDate)) || (impDate > DateTime.Now))
                {
                    //impDate = DateTime.Now;
                    AddError(ImportErrorCode.InvalidImportDate);
                    return false;
                }

                DateTime baseImportDate = (DateTime)ViewState[VS_BaseShipDate];
                if (impDate < baseImportDate)
                {
                    AddError(ImportErrorCode.ImportDateLessThanBaseDate);
                    return false;
                }

                shipNumber = ViewState[VS_ShippingNumber].ToString();
                branchCode = ViewState[VS_BranchCode].ToString();
                shipTo = hdAddress.Value;

                // save Shipping header
                ShippingHeader SH = CommonDAO.SaveOrUpdateShippingHeader(logedAreaCode, shipNumber, shipTo, impDate, UserHelper.DealerCode, (GridView1.Rows.Count + GridView3.Rows.Count), UserHelper.Username);
                if (SH == null) { trans.IsValid = false; return false; }
                else shipID = SH.Id;

                #region save shipping
                foreach (GridViewRow row in GridView3.Rows)
                {
                    if (row.Enabled) // skip error vehicle
                    {
                        exception = ((TextBox)row.FindControl("txtException")).Text.Trim();
                        Int32.TryParse(((RadioButtonList)row.FindControl("rblStatus")).SelectedValue, out status);
                        hasVoucher = ((CheckBox)row.FindControl("chbVoucherStatus")).Checked;
                        itemCode = ((Label)row.FindControl("lblItemCode")).Text.Trim();
                        engineNumber = ((Label)row.FindControl("lblEngineNumber")).Text;
                        itemType = ((Label)row.FindControl("lblItemType")).Text;
                        color = ((Label)row.FindControl("lblColor")).Text + " (" + ((Label)row.FindControl("lblColorName")).Text + ")";
                        orderNumber = ((Label)row.FindControl("lblOrderNumber")).Text;
                        DateTime.TryParse(((Label)row.FindControl("lblMadeDate")).Text, Thread.CurrentThread.CurrentCulture, DateTimeStyles.AllowWhiteSpaces, out madeDate);
                        long.TryParse(((Label)row.FindControl("lblPrice")).Text, out Price);

                        // custom imported date for item
                        string impDateString = ((TextBox)row.FindControl("txtItemImportDate")).Text.Trim();
                        if (string.IsNullOrEmpty(impDateString)) impDateString = txtImportDate.Text;

                        if (!DateTime.TryParse(impDateString, Thread.CurrentThread.CurrentCulture, DateTimeStyles.AllowWhiteSpaces, out itemImpDate))
                        {
                            AddError(ImportErrorCode.InvalidImportDate);
                        }

                        if (itemImpDate < baseImportDate) AddError(ImportErrorCode.ImportDateLessThanBaseDate);
                        if (itemImpDate > DateTime.Now) AddError(ImportErrorCode.ImportDateTooLate);
                        if (InventoryHelper.IsInventoryLock(itemImpDate, UserHelper.DealerCode, UserHelper.BranchCode)) AddError(ImportErrorCode.ImportDateLocked);
                        if (errorCode.Count > 0)
                        {
                            trans.IsValid = false; return false;
                        }

                        //branchCode = ((Label)row.FindControl("lblBranchCode")).Text;

                        // day du cac thu roi thi khong chap nhan exception
                        if ((hasVoucher) && (status == 1)) exception = string.Empty;

                        IInst = null;
                        // get n' check item in table DATA_ITEM
                        item = CommonDAO.GetItemByCode(itemCode);
                        if (item == null) { AddError(ImportErrorCode.ItemNotExist); return false; }

                        if (status > 0) // nhap xe hoac tam nhap => save iteminstance n' transHistory
                        {
                            // clear instance for old shipping info
                            foreach (var sd in CommonDAO.GetShippingDetails(engineNumber))
                            {
                                sd.PRODUCTINSTANCE = null;
                            }
                            // save ItemInstance of shipping
                            switch (status)
                            {
                                case 0: IisStatus = ImportItemStatus.NotArrived; break;
                                case 1: IisStatus = ImportItemStatus.Imported; break;
                                case 2: IisStatus = ImportItemStatus.AdmitTemporarily; break;
                                default: IisStatus = ImportItemStatus.NotArrived; break;
                            }
                            IInst = CommonDAO.SaveOrUpdateItemInstance(UserHelper.DealerCode, branchCode, engineNumber, shipNumber, orderNumber, itemType, item, itemImpDate, color, (int)IisStatus, madeDate, UserHelper.DatabaseCode);
                            if (IInst == null) { trans.IsValid = false; return false; }

                            // save transaction history. <actualCost> is temporary equal to "zero"
                            switch (status)
                            {
                                case 0: hisItemStatus = ItemStatus.Lacked; break;
                                case 1: hisItemStatus = ItemStatus.Imported; break;
                                case 2: hisItemStatus = ItemStatus.AdmitTemporarily; break;
                                default: hisItemStatus = ItemStatus.AdmitTemporarily; break;
                            }
                            if (CommonDAO.SaveTransHist(IInst, itemImpDate, hisItemStatus, Price, UserHelper.DealerCode, UserHelper.BranchCode) == null) { trans.IsValid = false; return false; };

                            // save to Inventory of Day
                            if (InventoryHelper.SaveInventoryDay(itemCode, itemImpDate, 1, (int)IisStatus, UserHelper.DealerCode, branchCode) == null) { trans.IsValid = false; return false; };
                        }

                        // save shipping detail info
                        SD = CommonDAO.SaveOrUpdateShippingDetail(shipID, item, engineNumber, status, hasVoucher, exception, IInst, itemType, color, UserHelper.DealerCode, orderNumber);
                        if (SD == null) { trans.IsValid = false; return false; }
                    }
                }
                #endregion

                #region Update order delivered status

                foreach (GridViewRow row in GridView3.Rows)
                {
                    orderNumber = ((Label)row.FindControl("lblOrderNumber")).Text;
                    /* tntung
                     * 14/01/2008
                     * Update order delivered status
                     */
                    IDao<Orderheader, long> oDao = DaoFactory.GetDao<Orderheader, long>();
                    oDao.SetCriteria(new ICriterion[] { Expression.Eq("Ordernumber", orderNumber) });
                    IList list = oDao.GetAll();
                    if (list.Count > 0)
                    {
                        Orderheader OrderHeaderUpdated = (Orderheader)list[0];
                        DataSet ds = InventoryDao.CheckOrderDetail(OrderHeaderUpdated.Id);
                        int Orderstatus = (int)DeliveredOrderStatus.DeliveredAll;
                        int Orderqty, OrderShipped;
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            item = CommonDAO.GetItemByCode(dr["itemcode"].ToString());
                            Orderqty = int.Parse(dr["orderqty"].ToString());
                            IDao<Shippingdetail, long> sDao = DaoFactory.GetDao<Shippingdetail, long>();
                            sDao.SetCriteria(new ICriterion[] {
                                Expression.Eq("Ordernumber", orderNumber),
                                Expression.Eq("Item", item),
                                Expression.Not(Expression.Eq("Status", (int)ItemStatus.NotArrived))
                            });
                            OrderShipped = sDao.GetAll().Count;
                            if ((Orderqty - OrderShipped) != 0)
                            {
                                Orderstatus = (int)DeliveredOrderStatus.NotDeliveredAll;
                            }
                        }
                        OrderHeaderUpdated.Deliveredstatus = Orderstatus;   //  (Orderstatus.Equals((int)DeliveredOrderStatus.NotDeliveredAll)) ? (int)DeliveredOrderStatus.NotDeliveredAll : (int)DeliveredOrderStatus.DeliveredAll;
                        oDao.SaveOrUpdate(OrderHeaderUpdated);
                    }
                }
                #endregion
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                trans.IsValid = false;
                return false;
            }
            trans.IsValid = true;

        }  // transaction
        return true;
    }
    protected void cmdConfirm_Click(object sender, EventArgs e)
    {
        if ((!Page.IsValid)
            && !OnDevTesting
            ) return;
        IDao<Orderheader, long> ohDao = DaoFactory.GetDao<Orderheader, long>();
        IDao<Orderdetail, long> odDao = DaoFactory.GetDao<Orderdetail, long>();

        using (TransactionBlock tran = new TransactionBlock())
        {
            Orderheader oh = CurrentOrderHeader;
            oh.Status = (int)OrderStatus.Confirmed;
            oh.Ordernumber = txtTipTopOrderNumber.Text;
            ////oh.Createddate =
            //    oh.Orderdate = VDMS.Data.TipTop.Order.GetOrderDate(oh.Ordernumber);
            ohDao.SaveOrUpdate(oh);

            //if (!OnDevTesting)
            {
                // ======> need SynchronizeOrderDetail (du lieu Interface chi co y nghia sau lan confirm dau tien)
                int index = 0;

                // first, delete all in VDMS
                foreach (DataKey key in gvMain.DataKeys)
                {
                    long OrderDetailId = long.Parse(key.Value.ToString());
                    odDao.Delete(OrderDetailId);
                    index++;
                }

                // second, copy from Tip-Top to VDSM
                if (!SynchronizeOrderDetail(txtTipTopOrderNumber.Text, ohDao, odDao, oh))
                {
                    tran.IsValid = false;
                    lblError.Text = (string)GetLocalResourceObject("_ItemDefferent");
                }
                else tran.IsValid = true;

                // update header
                oh.Orderdate = VDMS.Data.TipTop.Order.GetOrderDate(oh.Ordernumber);
            }
            //else
            tran.IsValid = true;
        }

        IFShipping.RefreshShipping(txtTipTopOrderNumber.Text.ToUpper(), CurrentOrderHeader.Id);
        //RefreshShipping("DOA-550075", CurrentOrderHeader.Id);
        cmdRefreshShipping.Enabled = (CurrentOrderHeader != null) && (!string.IsNullOrEmpty(CurrentOrderHeader.Ordernumber));

        phGoback.Visible = true;
        DisableButton();
    }
    // 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();
    }
Example #12
0
    private bool SaveReturnFinish(string engineNumber, string branchCode)
    {
        using (TransactionBlock trans = new TransactionBlock())
        {
            IDao<Iteminstance, long> iisDao = DaoFactory.GetDao<Iteminstance, long>();
            IDao<Returnitem, long> riDao = DaoFactory.GetDao<Returnitem, long>();
            IDao<TransHis, long> trhDao = DaoFactory.GetDao<TransHis, long>();
            IList lst;
            try
            {
                // iteminstance record
                iisDao.SetCriteria(new ICriterion[] { Expression.Eq("Enginenumber", engineNumber.ToUpper()) });
                lst = iisDao.GetAll();
                if (lst.Count <= 0) return false;
                Iteminstance iis = (Iteminstance)lst[0];

                // check for item instock?
                if (!ItemHepler.IsInstock(iis.Status))
                {
                    AddError(ReturnItemErrorCode.ItemHasOutOfStock);
                    return false;
                }

                //
                iis.Status = (int)ItemStatus.Return;
                //iis.Releaseddate = DateTime.Now;

                // returnItem record
                riDao.SetCriteria(new ICriterion[] { Expression.Eq("Iteminstance.Id", iis.Id), Expression.Eq("Status", (int)ReturnItemStatus.Allowed), Expression.Eq("Dealercode", UserHelper.DealerCode), Expression.Eq("Branchcode", UserHelper.BranchCode) });
                lst = riDao.GetAll();
                if (lst.Count <= 0) return false;
                Returnitem ri = (Returnitem)lst[0];
                ri.Status = (int)ReturnItemStatus.Returned;
                ri.Confirmdate = DateTime.Now;
                if (ri.Vmepcomment == null) ri.Vmepcomment = "";
                if (ri.Returnnumber == null) ri.Returnnumber = "";

                if (InventoryHelper.IsInventoryLock(ri.Releasedate, UserHelper.DealerCode, UserHelper.BranchCode))
                {
                    //AddError(string.Format(ReturnItemErrorCode.InventoryLocked,lockdate.Month + "/" + lockdate.Year));
                    AddError(ReturnItemErrorCode.InventoryLocked);
                    return false;
                }

                iis.Releaseddate = ri.Releasedate;

                // tranHistory record
                TransHis trh = new TransHis();
                trh.Actualcost = 0;
                trh.Frombranch = branchCode;
                trh.Modifieddate = DateTime.Now;
                trh.Iteminstance = iis;
                trh.Transactiondate = ri.Releasedate;
                trh.Transactiontype = (int)ItemStatus.Return;
                trh.Modifiedby = UserHelper.Username;

                // daily tracking
                InventoryHelper.SaveInventoryDay(iis.Item.Id, ri.Releasedate, -1, (int)ItemStatus.Return, UserHelper.DealerCode, branchCode);

                // save data
                iisDao.SaveOrUpdate(iis);
                riDao.SaveOrUpdate(ri);
                trhDao.Save(trh);

                trans.IsValid = true;
                return true;
            }
            catch { trans.IsValid = false; return false; }
        }
    }
    private void SendToVMEP()
    {
        if (status == 0)
        {
            // Lay cac PartHeaderDataSource can gui
            // ExchangePartHeaderDataSource dsEph = new ExchangePartHeaderDataSource();
            List<Exchangepartheader> listEph = (new ExchangePartHeaderDataSource()).Select(fromDate, toDate, status, ddlDealer.SelectedValue);
            // Neu so luong lon hon 0 thi bat dau gui
            if (listEph.Count > 0)
            {
                using (TransactionBlock tran = new TransactionBlock())
                {
                    try
                    {
                        // Create new Exchangevoucherheader
                        IDao<Exchangevoucherheader, string> daoEvh = DaoFactory.GetDao<Exchangevoucherheader, string>();
                        Exchangevoucherheader evh = new Exchangevoucherheader();
                        evh.Createddate = DateTime.Now;
                        evh.Dealercode = ddlDealer.SelectedValue;
                        evh.Lastprocesseddate = toDate;
                        evh.Id = ExchangeVoucherBO.GenExchangeNumber(ddlDealer.SelectedValue);
                        evh.Status = (int)ExchangeVoucherStatus.Sent;
                        evh = daoEvh.Save(evh);

                        // Sent Exchangepartheader;
                        IDao<Exchangepartheader, long> daoEph = DaoFactory.GetDao<Exchangepartheader, long>();
                        foreach (Exchangepartheader eph in listEph)
                        {
                            if (eph.Status == (int)ExchangeVoucherStatus.New)
                            {
                                eph.Status = (int)ExchangeVoucherStatus.Sent;
                                eph.Exchangevoucherheader = evh;
                                daoEph.SaveOrUpdate(eph);
                            }
                        }
                        tran.IsValid = true;
                    }
                    catch
                    {
                        tran.IsValid = false;
                    }
                }
            }
            BindData();
        }
    }
Example #14
0
        public static AdjustmentErrorCode UpdateVerhicle(string enginNumber, DateTime moveDate, string from, string to, string dealerCode, string dbCode, bool voucher, AdjustmentTask task)
        {
            using (TransactionBlock trs = new TransactionBlock())
            {
                Shippingdetail shd;
                AdjustmentErrorCode error = GetItemInfos(enginNumber, dealerCode, dbCode, out shd);
                if (error != AdjustmentErrorCode.OK) return error;

                // change item status
                IDao<Iteminstance, long> dao = DaoFactory.GetDao<Iteminstance, long>();
                IDao<Shippingdetail, long> sdao = DaoFactory.GetDao<Shippingdetail, long>();
                Iteminstance item = dao.GetById(shd.PRODUCTINSTANCE.Id, false); //true -> false
                if (item == null) return AdjustmentErrorCode.InvalidEngineNumber;
                switch (task)
                {
                    case AdjustmentTask.Move:
                        //item.Status = (int)ItemStatus.Moved;
                        item.Branchcode = to;
                        break;
                    case AdjustmentTask.CheckLacked: item.Status = (int)ItemStatus.Lacked; item.Releaseddate = moveDate; break;
                    case AdjustmentTask.CheckRedundant: item.Status = (int)ItemStatus.Redundant; break;
                    case AdjustmentTask.AddVoucher: shd.Voucherstatus = voucher; break;
                }
                try
                {
                    switch (task)
                    {
                        case AdjustmentTask.Move:
                        case AdjustmentTask.CheckLacked:
                        case AdjustmentTask.CheckRedundant: dao.SaveOrUpdate(item); break;
                        case AdjustmentTask.AddVoucher: sdao.SaveOrUpdate(shd); break;
                    }
                }
                catch { trs.IsValid = false; return AdjustmentErrorCode.SaveDataFailed; }

                // write transHistory
                IDao<TransHis, long> trhdao = DaoFactory.GetDao<TransHis, long>();
                TransHis trans = new TransHis();
                TransHis transTo = new TransHis();
                trans.Actualcost = 0;
                if (from != null) trans.Frombranch = UserHelper.BuildFullBranch(dealerCode, from);
                if (to != null) trans.Tobranch = UserHelper.BuildFullBranch(dealerCode, to);
                trans.Transactiondate = moveDate;
                switch (task)
                {
                    case AdjustmentTask.Move:
                        trans.Transactiontype = (int)ItemStatus.Moved;
                        transTo.Actualcost = trans.Actualcost;
                        transTo.Frombranch = trans.Tobranch;
                        transTo.Tobranch = trans.Frombranch;
                        transTo.Transactiondate = trans.Transactiondate;
                        transTo.Transactiontype = (int)ItemStatus.ReceivedFromMoving;
                        transTo.Modifieddate = DateTime.Now;
                        transTo.Iteminstance = item;
                        transTo.Modifiedby = UserHelper.Username;
                        break;
                    case AdjustmentTask.CheckLacked: trans.Transactiontype = (int)ItemStatus.Lacked; break;
                    case AdjustmentTask.CheckRedundant: trans.Transactiontype = (int)ItemStatus.Redundant; break;
                    case AdjustmentTask.AddVoucher: trans.Transactiontype = (int)ItemStatus.VoucherCompensated; break;
                }
                trans.Modifieddate = DateTime.Now;
                trans.Iteminstance = item;
                trans.Modifiedby = UserHelper.Username;
                try
                {
                    trhdao.SaveOrUpdate(trans);
                    if (task == AdjustmentTask.Move)
                        trhdao.SaveOrUpdate(transTo);
                }
                catch { trs.IsValid = false; return AdjustmentErrorCode.SaveDataFailed; }

                // save xxx info
                Inventoryday invDay;
                try
                {
                    switch (task)
                    {
                        case AdjustmentTask.Move:
                            invDay = InventoryHelper.SaveInventoryDay(item.Item.Id, moveDate, -1, (int)ItemStatus.Moved, dealerCode, from);
                            if (invDay == null) { trs.IsValid = false; return AdjustmentErrorCode.SaveDataFailed; }
                            invDay = InventoryHelper.SaveInventoryDay(item.Item.Id, moveDate, 1, (int)ItemStatus.Moved, dealerCode, to);
                            if (invDay == null) { trs.IsValid = false; return AdjustmentErrorCode.SaveDataFailed; }
                            break;
                        case AdjustmentTask.CheckLacked:
                            invDay = InventoryHelper.SaveInventoryDay(item.Item.Id, moveDate, -1, (int)ItemStatus.Lacked, dealerCode, item.Branchcode);
                            if (invDay == null) { trs.IsValid = false; return AdjustmentErrorCode.SaveDataFailed; }
                            break;
                        case AdjustmentTask.CheckRedundant:
                            //invDay = InventoryHelper.SaveInventoryDay(item.Item.Id, moveDate, 1, (int)ItemStatus.Redundant, dealerCode, item.Branchcode);
                            //if (invDay == null) { trs.IsValid = false; return AdjustmentErrorCode.SaveDataFailed; }
                            break;
                    }
                }
                catch { trs.IsValid = false; return AdjustmentErrorCode.SaveDataFailed; }

                // after all
                trs.IsValid = true;
            }
            return AdjustmentErrorCode.OK;
        }