Esempio n. 1
1
        public static Hashtable GetImportedDate(IList<VDMS.I.Entity.ShippingDetail> shippingList)
        {
            Hashtable data = new Hashtable();
            if ((shippingList == null) || shippingList.Count == 0) return data;

            List<string> listEngines = new List<string>();
            foreach (VDMS.I.Entity.ShippingDetail item in shippingList)
            {
                listEngines.Add(item.EngineNumber);
            }

            //IDao<Iteminstance, long> IISdao = DaoFactory.GetDao<Iteminstance, long>();
            //IISdao.SetCriteria(new ICriterion[] { Expression.In("Enginenumber", listEngines) });
            //IList listIIS = IISdao.GetAll();

            //foreach (Iteminstance item in listIIS)
            //{
            //    data.Add(item.Enginenumber, item.Importeddate);
            //}
            using( var db = new VehicleDataContext() )
            {
                var query = from ii in db.ItemInstances
                            where
                                listEngines.Contains(ii.EngineNumber)
                            select ii;
                foreach (var itemInstance in query)
                {
                    data.Add(itemInstance.EngineNumber, itemInstance.ImportedDate);
                }
                return data;
            }
        }
        public static void SaveTransHis(VehicleDataContext dc, ItemInstance ItemIns, DateTime txtime, ItemStatus TransType, int cusPayType, decimal ActualCost, string Modifiefby, string OlderEngine,string from, string to)
        {
            var th = new SaleTransHistory();

            th.ActualCost = ActualCost;
            th.ReferenceOrderId = 0;
            th.FromBranch = from;
            th.ToBranch = to;
            th.ModifiedDate = DateTime.Now;
            th.ItemInstance = ItemIns;
            th.TransactionDate = txtime;
            th.TransactionType = (int)TransType;
            th.ModifiedBy = Modifiefby;
            th.OldEngineNo = (OlderEngine == null) ? null : OlderEngine;

            dc.SaleTransHistories.InsertOnSubmit(th);
        }
Esempio n. 3
0
        /// <summary>
        /// Check ready state to close dealer
        /// </summary>
        /// <param name="dealerCode"></param>
        /// <param name="year"></param>
        /// <param name="month"></param>
        /// <param name="dc1"></param>
        /// <returns></returns>
        public static bool CanCloseDealer(string dealerCode, int year, int month, VehicleDataContext dc1)
        {
            var dc = DCFactory.GetDataContext<PartDataContext>();
            //var dc1 = DCFactory.GetDataContext<VehicleDataContext>();

            // check all warehouse closed
            int whCount = dc.ActiveWarehouses.Where(wh => wh.DealerCode == dealerCode && wh.Type == VDMS.II.Entity.WarehouseType.Vehicle).Count();
            int closedWhCount = dc1.SaleInventoryLocks.Where(i => i.IsLocked == 1 && i.DealerCode.Contains(dealerCode) && ((i.Month >= month && i.Year == year) || (i.Year > year))).Count();

            // check all sub dealer closed
            bool childsOk = true;
            var dealers = DealerDAO.GetAllChildDealer(dealerCode);
            dealers.ForEach(d =>
            {
                var ilck = dc1.SaleInventoryLocks.SingleOrDefault(i => i.DealerCode == dealerCode && i.IsLocked == 0);
                if ((ilck == null) || (ilck.Month < month && ilck.Year == year) || (ilck.Year < year)) childsOk = false;
            });

            return childsOk && (whCount == closedWhCount);
        }
Esempio n. 4
0
        public static ItemInstance UpdateItemInstance(VehicleDataContext dc, string engineNo, ItemStatus action, DateTime adjustDate, int price, int paymentType, string toBranch)
        {
            if (action != ItemStatus.Sold && action != ItemStatus.Moved)
                return null;

            var instance = dc.ItemInstances.SingleOrDefault(i => i.EngineNumber == engineNo);
            if (instance != null)
            {
                if (action == ItemStatus.Sold)
                    instance.Status = (int)ItemStatus.Sold;
                instance.ReleasedDate = adjustDate;
                // Save transaction
                ItemInstanceHelper2.SaveTransHis(dc, instance, adjustDate, action, paymentType, price, UserHelper.Username, null, string.Format("{0}-{1}", UserHelper.DealerCode, instance.BranchCode), toBranch);
                // Save inventory day
                InventoryHelper2.SaveInventoryDay(dc, instance.Item.ItemCode, adjustDate, -1, (int)action, UserHelper.DealerCode, instance.BranchCode);

                if (!string.IsNullOrEmpty(toBranch))
                {
                    ItemInstanceHelper2.SaveTransHis(dc, instance, adjustDate, ItemStatus.Imported, paymentType, price, UserHelper.Username, null, string.Format("{0}-{1}", UserHelper.DealerCode, instance.BranchCode), null);
                    InventoryHelper2.SaveInventoryDay(dc, instance.Item.ItemCode, adjustDate, 1, (int)ItemStatus.Imported, UserHelper.DealerCode, toBranch);
                }
            }
            return instance;
        }
        public static void SaveInventoryDay(VehicleDataContext dc, string itemCode, DateTime actionTime, int quantity, int actionType, string dealerCode, string branchCode)
        {
            long actionDay = long.Parse(actionTime.ToString("yyyyMMdd"));
            var inv = dc.SaleInventoryDays.SingleOrDefault(iv => iv.ItemCode == itemCode &&
                                                                 iv.ActionDay == actionDay &&
                                                                 iv.ActionType== actionType &&
                                                                 iv.BranchCode == branchCode &&
                                                                 iv.DealerCode == dealerCode);
            if (inv == null)
            {
                inv = new SaleInventoryDay
                      {
                          ActionDay = actionDay,
                          ActionType = actionType,
                          BranchCode = branchCode,
                          DealerCode = dealerCode,
                          ItemCode = itemCode,
                          Quantity = 0,
                      };
                dc.SaleInventoryDays.InsertOnSubmit(inv);
            }

            inv.Quantity += quantity;
        }
Esempio n. 6
0
 public static Entity.Item GetItemByCode(VehicleDataContext db, String itemCode)
 {
     return db.Items.FirstOrDefault(p => p.ItemCode.Equals(itemCode));
 }
Esempio n. 7
0
        /// <summary>
        /// DoInventory calulate follow dataiteminstance
        /// </summary>
        public static void DoInventory2(string code,string dealerCode, int month, int year,VehicleDataContext dc)
        {
            int nextM = month + 1, nextY = year;
            int prevM = month - 1, prevY = year;

            if (nextM == 13) { nextM = 1; nextY++; }
            if (prevM == 0) { prevM = 12; prevY--; }
            dc.SaleInventories.DeleteAllOnSubmit(dc.SaleInventories.Where(iv => iv.BranchCode == code && iv.DealerCode == dealerCode && iv.Year == year && iv.Month == month).ToList());
            var t = GetIOReportData(dealerCode,code, string.Empty, string.Empty,new DateTime(year, month, 1).ToShortDateString(), new DateTime(nextY, nextM, 1).AddTicks(-1).ToShortDateString());
            var result = from i in t
                         select new SaleInventory
                         {
                             ItemCode = i.ItemCode,
                             BranchCode = code,
                             DealerCode = dealerCode,
                             Month = month,
                             Year = year,
                             Quantity = i.Begin +  i.In + i.Out
                         };
            if (result.Count() > 0)
                dc.SaleInventories.InsertAllOnSubmit(result);
            dc.SubmitChanges();
        }
Esempio n. 8
0
        /// <summary>
        /// Do close inventory
        /// </summary>
        /// <param name="code"></param>
        /// <param name="dealerCode"></param>
        /// <param name="month"></param>
        /// <param name="year"></param>
        /// <param name="dc"></param>
        public static void DoInventory(string code, string dealerCode, int month, int year, VehicleDataContext dc)
        {
            //var dc = DCFactory.GetDataContext<VehicleDataContext>();
            int nextM = month + 1, nextY = year;
            int prevM = month - 1, prevY = year;

            if (nextM == 13) { nextM = 1; nextY++; }
            if (prevM == 0) { prevM = 12; prevY--; }

            var prevInv = dc.SaleInventories.Where(i => i.Year == prevY && i.Month == prevM && i.BranchCode == code && i.DealerCode == dealerCode).ToList();

            // delete all current data
            dc.SaleInventories.DeleteAllOnSubmit(dc.SaleInventories.Where(iv => iv.BranchCode == code && iv.DealerCode == dealerCode && iv.Year == year && iv.Month == month).ToList());

            // get all actions happend in closing month(group by item code)
            var invs = dc.SaleInventoryDays.Where(id => id.ActionDay >= DataFormat.DateToCompareNumber(1, month, year)
                    && id.ActionDay < DataFormat.DateToCompareNumber(1, nextM, nextY)
                    && id.BranchCode == code && id.DealerCode == dealerCode)
                    .GroupBy(id => id.ItemCode, (key, g) => new
                    {
                        Itemcode = key,
                        Quantity = (int)g.Sum(i => i.Quantity),
                    })
                .ToList();
            // all items already exist in sale_inventory and has transactions
            var udInvs = from pi in prevInv
                         join id in invs on pi.ItemCode equals id.Itemcode
                         select new SaleInventory
                         {
                             ItemCode = pi.ItemCode,
                             BranchCode = code,
                             DealerCode = dealerCode,
                             Month = month,
                             Year = year,
                             Quantity = id.Quantity + pi.Quantity,
                         };
            // new items has beem imported in closing month
            var nwInvs = invs.Where(i => prevInv.Where(p => p.ItemCode == i.Itemcode).Count() == 0).Select(i => new SaleInventory
            {
                ItemCode = i.Itemcode,
                BranchCode = code,
                DealerCode = dealerCode,
                Month = month,
                Year = year,
                Quantity = i.Quantity,
            });

            // all items already exist in sale_inventory and has no transactions
            var mvInvs = prevInv.Where(i => invs.Where(c => c.Itemcode == i.ItemCode).Count() == 0).Select(i => new SaleInventory
            {
                ItemCode = i.ItemCode,
                BranchCode = code,
                DealerCode = dealerCode,
                Month = month,
                Year = year,
                Quantity = i.Quantity,
            });

            // insert all to sale_inventory
            if (udInvs.Count() > 0)
                dc.SaleInventories.InsertAllOnSubmit(udInvs.Distinct());
            if (nwInvs.Count() > 0)
                dc.SaleInventories.InsertAllOnSubmit(nwInvs);
            if (mvInvs.Count() > 0)
                dc.SaleInventories.InsertAllOnSubmit(mvInvs);
            dc.SubmitChanges();
        }
Esempio n. 9
0
        /// <summary>
        /// Close warehouse vehicle inventory at specified month.
        /// </summary>
        /// <param name="code"></param>
        /// <param name="dealerCode"></param>
        /// <param name="month"></param>
        /// <param name="year"></param>
        /// <param name="dc"></param>
        public static void DoCloseW(string code, string dealerCode, int month, int year, VehicleDataContext dc)
        {
            if ((year > DateTime.Now.Year) //|| (year < 2000)
                 || ((year == DateTime.Now.Year) && (month > DateTime.Now.Month))
                 || (month > 12) || (month < 1)
               )
            {
                throw new Exception("Invalid closing month!");
            }

            // check for valid warehouse
            var wh = VDMS.II.BasicData.WarehouseDAO.GetWarehouse(code, dealerCode, VDMS.II.Entity.WarehouseType.Vehicle);
            if (wh == null) throw new Exception("Invalid closing warehouse!");

            // get lock record for current closed month
            var ilck = dc.SaleInventoryLocks.SingleOrDefault(i => i.DealerCode == GetWLockCode(dealerCode, code) && i.IsLocked == 1);
            if (ilck == null)// never closed before
            {
                if (year < 2007) throw new Exception("Invalid closing month at first time!");
                // lock month valid to first inventory action?
                SaleInventory frstIv = dc.SaleInventories.Where(i => i.BranchCode == code && i.DealerCode == dealerCode).OrderBy(i => i.Year).OrderBy(i => i.Month).FirstOrDefault();
                if (frstIv != null)
                {
                    DateTime fDt = new DateTime(frstIv.Year, frstIv.Month, 1);
                    DateTime cDt = new DateTime(year, month, 1);
                    if (fDt.AddMonths(1) < cDt)
                        throw new Exception("At first time, closing month cannot be greater than the first month that changing inventory action happen!");
                }
                ilck = new SaleInventoryLock
                {
                    DealerCode = GetWLockCode(wh.DealerCode, wh.Code),
                    Month = month,
                    Year = year,
                    IsLocked = 1
                };
                dc.SaleInventoryLocks.InsertOnSubmit(ilck);
            }
            else
            {
                // change locked month to new Closed month
                if (ilck.Month == 12) { ilck.Month = 1; ilck.Year++; }
                else ilck.Month++;
                if ((ilck.Year > DateTime.Now.Year) || ((ilck.Year == DateTime.Now.Year) && (ilck.Month > DateTime.Now.Month))) throw new Exception("Invalid closing month!");
            }

            dc.SubmitChanges();

            // summarization
            InventoryHelper.DoInventory2(code, dealerCode, (int)ilck.Month, (int)ilck.Year, dc);

            // gen excel file
            //new VDMS.II.Report.PartMonthlyReport(wId.ToString(), wh.DealerCode, ilck.Month, ilck.Year).DoReport();
        }
Esempio n. 10
0
        /// <summary>
        /// Close dealer vehicle inventory at specified month.
        /// </summary>
        /// <param name="dealerCode"></param>
        /// <param name="month"></param>
        /// <param name="year"></param>
        /// <param name="dc"></param>
        public static void DoCloseD(string dealerCode, int month, int year, VehicleDataContext dc)
        {
            if ((year > DateTime.Now.Year) //|| (year < 2000)
                 || ((year == DateTime.Now.Year) && (month > DateTime.Now.Month))
                 || (month > 12) || (month < 1)
               )
            {
                throw new Exception("Invalid closing month!");
            }

            // check Dealer exist
            var d = DealerDAO.GetDealerByCode(dealerCode);
            if (d == null) throw new Exception("Invalid closing dealer!");

            // check all warehouse and sub dealer are closed
            if (!InventoryHelper.CanCloseDealer(dealerCode, year, month, dc))
                throw new Exception(string.Format("Cannot close {0}! All sub components must be closed before.", dealerCode));

            // get lock record for current closed month
            var ilck = dc.SaleInventoryLocks.SingleOrDefault(i => i.DealerCode == dealerCode && i.IsLocked == 0);
            if (ilck == null)   // never closed before
            {
                if (year < 2007) throw new Exception("Invalid closing month at first time!");
                // create new lock record
                ilck = new SaleInventoryLock
                {
                    IsLocked = 0,
                    DealerCode = d.DealerCode,
                    Month = month,
                    Year = year
                };
                dc.SaleInventoryLocks.InsertOnSubmit(ilck);
            }
            else // update locked record to new closing month
            {
                if (ilck.Month == 12) { ilck.Month = 1; ilck.Year++; }
                else ilck.Month++;
                if ((ilck.Year > DateTime.Now.Year) || ((ilck.Year == DateTime.Now.Year) && (ilck.Month > DateTime.Now.Month))) throw new Exception("Invalid closing month!");
            }

            dc.SubmitChanges();
        }
Esempio n. 11
0
 public static IQueryable<ShippingDetail> GetShippingDetails(VehicleDataContext db, string engNo)
 {
     return db.ShippingDetails.Where(p => p.EngineNumber.Equals(engNo));
 }
Esempio n. 12
0
    private bool SaveShippingDetail()
    {
        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;
        VDMS.I.Entity.ShippingDetail SD;
        long Price;

        Item item = null;
        long shipID;

        using (var db = new VehicleDataContext())
        {
            //try
            //{
            System.Data.Common.DbTransaction transaction;
            db.Connection.Open();
            transaction = db.Connection.BeginTransaction();
            db.Transaction = transaction;
            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;
                }
                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)
                        {
                            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(db, itemCode);
                        if (item == null)
                        {
                            AddError(ImportErrorCode.ItemNotExist);
                            return false;
                        }
                    }
                }
                shipNumber = ViewState[VS_ShippingNumber].ToString();
                branchCode = ViewState[VS_BranchCode].ToString();
                shipTo = hdAddress.Value;

                // save Shipping header
                VDMS.I.Entity.ShippingHeader SH = CommonDAO.SaveOrUpdateShippingHeader(db, logedAreaCode, shipNumber,
                                                                                       shipTo,
                                                                                       impDate, UserHelper.DealerCode,
                                                                                       (GridView1.Rows.Count +
                                                                                        GridView3.Rows.Count),
                                                                                       UserHelper.Username);
                db.SubmitChanges();

                if (SH == null)
                {
                    return false;
                }
                shipID = db.ShippingHeaders.SingleOrDefault(p => p.ShippingNumber == shipNumber).ShippingId;

                #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 (errorCode.Count > 0)
                        {
                            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;
                        item = CommonDAO.GetItemByCode(db, itemCode);

                        if (status > 0) // nhap xe hoac tam nhap => save iteminstance n' transHistory
                        {
                            // clear instance for old shipping info
                            //foreach (var sd in CommonDAO.GetShippingDetails(db, engineNumber))
                            //{
                            //    sd.ProductInstanceId = 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(db, UserHelper.DealerCode, branchCode,
                                                                       engineNumber,
                                                                       shipNumber, orderNumber, itemType, item,
                                                                       itemImpDate,
                                                                       color, (int)IisStatus, madeDate,
                                                                       UserHelper.DatabaseCode);
                            db.SubmitChanges();

                            if (IInst == null)
                            {
                                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;
                            }
                            var t = CommonDAO.SaveTransHist(db, IInst, itemImpDate, hisItemStatus, Price,
                                                            UserHelper.DealerCode, UserHelper.BranchCode);

                            // save to Inventory of Day
                            var tt = InventoryHelper.SaveInventoryDay(db, itemCode, itemImpDate, 1, (int)IisStatus,
                                                                      UserHelper.DealerCode, branchCode);

                        }

                        // save shipping detail info
                        SD = CommonDAO.SaveOrUpdateShippingDetail(db, shipID, item, engineNumber, status,
                                                                  hasVoucher,
                                                                  exception, IInst, itemType, color,
                                                                  UserHelper.DealerCode,
                                                                  orderNumber);
                        //db.SubmitChanges();
                    }
                }

                #endregion
                #region Update order delivered status
                List<String> listOrderNumber = new List<string>();
                foreach (GridViewRow row in GridView3.Rows)
                {
                    listOrderNumber.Add(((Label)row.FindControl("lblOrderNumber")).Text);
                }

                List<VDMS.I.Entity.ShippingDetail> loh = db.ShippingDetails.Where(p => listOrderNumber.Contains(p.OrderNumber)).ToList();

                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)});
                    var list = db.OrderHeaders.FirstOrDefault(p => p.OrderNumber == orderNumber); //oDao.GetAll();)

                    if (list != null)
                    {
                        DataSet ds = InventoryDao.CheckOrderDetail(list.OrderHeaderId);
                        int Orderstatus = (int)DeliveredOrderStatus.DeliveredAll;
                        int Orderqty, OrderShipped;
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            item = CommonDAO.GetItemByCode(db, dr["itemcode"].ToString());
                            Orderqty = int.Parse(dr["orderqty"].ToString());

                            OrderShipped =
                                loh.Count(
                                    p =>
                                    p.OrderNumber == orderNumber && p.ItemCode == item.ItemCode &&
                                    p.Status == (int)ItemStatus.Imported);

                            if ((Orderqty - OrderShipped) != 0)
                            {
                                Orderstatus = (int)DeliveredOrderStatus.NotDeliveredAll;
                            }
                        }
                        list.DeliveredStatus = Orderstatus;
                        //  (Orderstatus.Equals((int)DeliveredOrderStatus.NotDeliveredAll)) ? (int)DeliveredOrderStatus.NotDeliveredAll : (int)DeliveredOrderStatus.DeliveredAll;
                    }
                }
                db.SubmitChanges();
                transaction.Commit();
                //trans.Complete();
                #endregion

            }
            catch
            {
                transaction.Rollback();
                return false;
            }
            finally
            {
                if (db.Connection != null)
                {
                    db.Connection.Close();
                }
            }

            //}
            //catch (Exception e)
            //{
            //    MessageBox.Show(e.Message);
            //    return false;
            //}

        } // transaction
        return true;
    }
Esempio n. 13
0
        public static ShippingDetail SaveOrUpdateShippingDetail(VehicleDataContext db,long shipId, Entity.Item item, string engineNumber, int status, bool voucher, string ex, ItemInstance itemInstance, string itemType, string color, string branchCode, string orderNumber)
        {
            //IDao<Shippingdetail, long> dao;
            //IDao<ShippingHeader, long> shdao;
            //List<Shippingdetail> list;
            ShippingDetail SD = null;

            //dao = DaoFactory.GetDao<Shippingdetail, long>();
            //dao.SetCriteria(new ICriterion[] { Expression.And(Expression.Eq("Shippingheader.Id", shipId), Expression.Eq("Enginenumber", engineNumber.Trim())) });
            //list = dao.GetAll();
            SD =
                db.ShippingDetails.FirstOrDefault(
                    p => p.ShippingId == shipId && p.EngineNumber == engineNumber.Trim());

            if (SD == null)
            {

                SD = new ShippingDetail();
                SD.ShippingId = shipId;
                SD.EngineNumber = engineNumber;
                db.ShippingDetails.InsertOnSubmit(SD);
            }

            SD.ItemType = itemType;
            SD.Color = color;
            SD.Item = item;
            SD.BranchCode = branchCode;
            SD.OrderNumber = orderNumber;
            SD.Status = status;
            SD.VoucherStatus = voucher? 1:0;
            SD.ItemCode = item.ItemCode;
            SD.VMEPResponseDate = DateTime.MinValue;
            if (itemInstance != null) SD.ProductInstanceId = itemInstance.ItemInstanceId;
            //if (!string.IsNullOrEmpty(ex))
            SD.Exception = ex;

            return SD;
        }
Esempio n. 14
0
        public static void DoOpenW(string wCode, string dCode, VehicleDataContext dc)
        {
            var ilck = InventoryHelper.GetInventoryLock(dCode, wCode);
            if (ilck == null)
            {
                throw new Exception("This warehouse never closed before!");
            }
            else
            {
                if (!CanOpenW(wCode, dCode, (int)ilck.Year, (int)ilck.Month)) throw new Exception("May try to open months before 'first month' or parent component has not been opened!");
                // change locked month to new Closed month
                if (ilck.Month == 1) { ilck.Month = 12; ilck.Year--; }
                else ilck.Month--;
            }

            dc.SubmitChanges();
        }
Esempio n. 15
0
        public static ItemInstance SaveOrUpdateItemInstance(VehicleDataContext db, string dealerCode, string branchCode, string engineNumber, string shipNumber, string invoice, string itemType, Entity.Item item, DateTime impDate, string color, int status, DateTime madeDate, string DatabaseCode)
        {
            var IIS = db.ItemInstances.FirstOrDefault(p => p.EngineNumber.Equals(engineNumber.Trim()));

            if (IIS == null)
            {
                IIS = new ItemInstance { CreatedDate = DateTime.Now };
                IIS.EngineNumber = engineNumber;
                db.ItemInstances.InsertOnSubmit(IIS);
            }

            // get shipping header to take some data
            //var SH = db.ShippingHeaders.FirstOrDefault(p => p.ShippingNumber == (shipNumber.Trim()));
            //if (SH == null)
            //{
            //    Exception e = new Exception("Shipping number does not exist: " + shipNumber);
            //    throw e;
            //}
            //else
            //{
                // save to database
                //IIS.Dealercode = SH.Dealercode;

                IIS.ItemType = itemType;
                IIS.ItemCode = item.ItemCode;
                IIS.ImportedDate = impDate;
                IIS.Color = color;
                IIS.Status = status;
                IIS.DealerCode = dealerCode;
                IIS.VMEPInvoice = invoice;
                IIS.DatabaseCode = DatabaseCode;
                if (madeDate > DateTime.MinValue) IIS.MadeDate = madeDate;
                IIS.BranchCode = branchCode;

                IIS.ReleasedDate = DateTime.Parse("9999/12/31");
               // }
            return IIS;
        }
 public static List<VDMS.I.Entity.ShippingDetail> Select(Int64 shipID)
 {
     using (var db = new VehicleDataContext())
     {
         return db.ShippingDetails.Where(p => p.ShippingId == shipID).ToList();
     }
 }
        public static bool SaveUpdate(string branchcode, string issueNumber, string shipnumber, string areacode, DateTime baseImportDate, string dealercode)
        {
            string exception, itemCode, engineNumber, itemType, color, orderNumber, shipTo;
            Collection<ImportErrorCode> errorCode = new Collection<ImportErrorCode>();
            Int32 status;
            bool hasVoucher;
            ImportItemStatus IisStatus;
            ItemInstance IInst = null;
            ItemStatus hisItemStatus;
            DateTime madeDate, impDate, itemImpDate;
            VDMS.I.Entity.ShippingDetail SD;
            long Price;

            Item item = null;
            long shipID;

            using (var db = new VehicleDataContext())
            {
                System.Data.Common.DbTransaction transaction;
                db.Connection.Open();
                transaction = db.Connection.BeginTransaction();
                db.Transaction = transaction;
                try
                {
                    impDate = CalculateInitImportDate(baseImportDate);
                    if (impDate < baseImportDate)
                    {
                        AddError(ImportErrorCode.ImportDateLessThanBaseDate, errorCode);
                        return false;
                    }
                    var tt = TipTop_ShippingDetail(issueNumber);
                    foreach (var m in tt)
                    {
                        exception = m.Exception;
                        status = 1;
                        hasVoucher = IsOrderConfirmed(m.TipTopOrderNumber);
                        itemCode = m.ItemCode;
                        engineNumber = m.EngineNumber;
                        itemType = m.Model;
                        if (m.Status == (int)ImportItemStatus.Imported || m.Status == (int)ImportItemStatus.AdmitTemporarily)
                        {
                            continue;
                        }

                        if (ItemInstanceHelper.EngineNumberExist(engineNumber))
                        {
                            LogError("IssueNumber: " + issueNumber + ", branchcode: " + branchcode + ", DealerCode:" + dealercode + ", Shipdate:" + baseImportDate + ", EngineNumber in dataItemInstance:" + engineNumber);//Log
                            continue;
                            //throw new Exception( engineNumber +  " avaliable in ItemInstance");
                            //return false;
                        }
                        if (isExsitDataItemInstance(engineNumber))
                            return false;

                        color = m.ColorCode + " (" + m.ColorName + ")";
                        orderNumber = m.TipTopOrderNumber;
                        DateTime.TryParse(m.OutStockDate.ToString(),
                                          Thread.CurrentThread.CurrentCulture,
                                          DateTimeStyles.AllowWhiteSpaces, out madeDate);
                        long.TryParse(m.Price.ToString(), out Price);

                        // custom imported date for item
                        string impDateString = CalculateInitImportDate(baseImportDate).ToShortDateString();
                        if (string.IsNullOrEmpty(impDateString)) impDateString = DateTime.Now.ToShortDateString();

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

                        if (itemImpDate < baseImportDate) AddError(ImportErrorCode.ImportDateLessThanBaseDate, errorCode);
                        if (itemImpDate > DateTime.Now) AddError(ImportErrorCode.ImportDateTooLate, errorCode);
                        if (InventoryHelper.IsInventoryLock(itemImpDate, dealercode, branchcode))
                            AddError(ImportErrorCode.ImportDateLocked, errorCode);
                        if (errorCode.Count > 0)
                        {
                            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(db, itemCode);
                        if (item == null)
                        {
                            AddError(ImportErrorCode.ItemNotExist, errorCode);
                            return false;
                        }

                    }
                    shipTo = branchcode;

                    // save Shipping header
                    VDMS.I.Entity.ShippingHeader SH = CommonDAO.SaveOrUpdateShippingHeader(db, areacode, shipnumber,
                                                                                           shipTo,
                                                                                           impDate, dealercode,
                                                                                           (tt.Count +
                                                                                            tt.Count),
                                                                                           dealercode);
                    db.SubmitChanges();

                    if (SH == null)
                    {
                        return false;
                    }
                    shipID = db.ShippingHeaders.SingleOrDefault(p => p.ShippingNumber == shipnumber).ShippingId;

                    #region save shipping

                    foreach (var m in tt)
                    {
                        exception = m.Exception;
                        status = 1;
                        hasVoucher = IsOrderConfirmed(m.TipTopOrderNumber);
                        itemCode = m.ItemCode;
                        engineNumber = m.EngineNumber;
                        itemType = m.Model;

                        color = m.ColorCode + " (" + m.ColorName + ")";
                        orderNumber = m.TipTopOrderNumber;
                        DateTime.TryParse(m.OutStockDate.ToString(),
                                          Thread.CurrentThread.CurrentCulture,
                                          DateTimeStyles.AllowWhiteSpaces, out madeDate);
                        long.TryParse(m.Price.ToString(), out Price);

                        if (m.Status == (int)ImportItemStatus.Imported || m.Status == (int)ImportItemStatus.AdmitTemporarily)
                        {
                            continue;
                        }

                        if (ItemInstanceHelper.EngineNumberExist(engineNumber))
                        {
                            LogError("IssueNumber: " + issueNumber + ", branchcode: " + branchcode + ", DealerCode:" + dealercode + ", Shipdate:" + baseImportDate + ", EngineNumber in dataItemInstance:" + engineNumber);//Log
                            continue;
                            //throw new Exception( engineNumber +  " avaliable in ItemInstance");
                            //return false;
                        }

                        // custom imported date for item
                        string impDateString = impDate.ToShortDateString();
                        if (
                            !DateTime.TryParse(impDateString, Thread.CurrentThread.CurrentCulture,
                                               DateTimeStyles.AllowWhiteSpaces, out itemImpDate))
                        {
                            AddError(ImportErrorCode.InvalidImportDate, errorCode);
                        }

                        if (itemImpDate < baseImportDate) AddError(ImportErrorCode.ImportDateLessThanBaseDate, errorCode);
                        if (itemImpDate > DateTime.Now) AddError(ImportErrorCode.ImportDateTooLate, errorCode);
                        if (InventoryHelper.IsInventoryLock(itemImpDate, dealercode, branchcode))
                            AddError(ImportErrorCode.ImportDateLocked, errorCode);
                        if (errorCode.Count > 0)
                        {
                            return false;
                        }

                        if ((hasVoucher) && (status == 1)) exception = string.Empty;
                        item = CommonDAO.GetItemByCode(db, itemCode);
                        if (status > 0) // nhap xe hoac tam nhap => save iteminstance n' transHistory
                        {
                            // clear instance for old shipping info
                            //foreach (var sd in CommonDAO.GetShippingDetails(db, engineNumber))
                            //{
                            //    sd.ProductInstanceId = 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;
                            }
                            //db.SubmitChanges();
                            IInst = CommonDAO.SaveOrUpdateItemInstance(db, dealercode, branchcode,
                                                                       engineNumber,
                                                                       shipnumber, orderNumber, itemType, item,
                                                                       itemImpDate,
                                                                       color, (int)IisStatus, madeDate,
                                                                       DealerHelper.GetDatabaseCode(dealercode));
                            db.SubmitChanges();

                            if (IInst == null)
                            {
                                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;
                            }
                            var t = CommonDAO.SaveTransHist(db, IInst, itemImpDate, hisItemStatus, Price,
                                                            dealercode, branchcode);

                            // save to Inventory of Day
                            var ttt = InventoryHelper.SaveInventoryDay(db, itemCode, itemImpDate, 1, (int)IisStatus,
                                                                      dealercode, branchcode);

                        }

                        // save shipping detail info
                        SD = CommonDAO.SaveOrUpdateShippingDetail(db, shipID, item, engineNumber, status,
                                                                  hasVoucher,
                                                                  exception, IInst, itemType, color,
                                                                  dealercode,
                                                                  orderNumber);
                        //db.SubmitChanges();

                    }

                    #endregion

                    #region Update order delivered status
                    List<String> listOrderNumber = new List<string>();
                    foreach (var m in tt)
                    {
                        listOrderNumber.Add((m.TipTopOrderNumber));
                    }

                    List<VDMS.I.Entity.ShippingDetail> loh = db.ShippingDetails.Where(p => listOrderNumber.Contains(p.OrderNumber)).ToList();

                    foreach (var m in tt)
                    {
                        orderNumber = m.TipTopOrderNumber;
                        var list = db.OrderHeaders.FirstOrDefault(p => p.OrderNumber == orderNumber); //oDao.GetAll();)
                        //list.CanUndoAutoReceive = true;
                        if (list != null)
                        {
                            DataSet ds = InventoryDao.CheckOrderDetail(list.OrderHeaderId);
                            int Orderstatus = (int)DeliveredOrderStatus.DeliveredAll;
                            int Orderqty, OrderShipped;
                            foreach (DataRow dr in ds.Tables[0].Rows)
                            {
                                item = CommonDAO.GetItemByCode(db, dr["itemcode"].ToString());
                                Orderqty = int.Parse(dr["orderqty"].ToString());

                                OrderShipped =
                                    loh.Count(
                                        p =>
                                        p.OrderNumber == orderNumber && p.ItemCode == item.ItemCode &&
                                        p.Status == (int)ItemStatus.Imported);

                                if ((Orderqty - OrderShipped) != 0)
                                {
                                    Orderstatus = (int)DeliveredOrderStatus.NotDeliveredAll;
                                }
                            }
                            list.DeliveredStatus = Orderstatus;
                            //  (Orderstatus.Equals((int)DeliveredOrderStatus.NotDeliveredAll)) ? (int)DeliveredOrderStatus.NotDeliveredAll : (int)DeliveredOrderStatus.DeliveredAll;
                        }
                    }
                    db.SubmitChanges();
                    transaction.Commit();
                    //trans.Complete();

                    #endregion

                    return true;
                }
                catch(Exception e)
                {
                    LogError("IssueNumber: " + issueNumber + ", branchcode: " + branchcode + ", DealerCode:" + dealercode + ", Shipdate:" + baseImportDate + ", System Error:" + e.Message );//Log
                    transaction.Rollback();
                    return false;
                }
                finally
                {
                    if (db.Connection != null)
                    {
                        db.Connection.Close();
                    }
                }
            }
        }
Esempio n. 18
0
 public static void SysInit()
 {
     var dc = new VehicleDataContext();
     try
     {
         var l = dc.OrderHeaders.Where(h => h.OrderDetails.Count() == 0 && !string.IsNullOrEmpty(h.OrderNumber));
         var p = dc.SaleOrderPayments.Where(h => h.OrderHeader.OrderDetails.Count() == 0 && !string.IsNullOrEmpty(h.OrderHeader.OrderNumber));
         dc.SaleOrderPayments.DeleteAllOnSubmit(p);
         dc.OrderHeaders.DeleteAllOnSubmit(l);
         dc.SubmitChanges();
     }
     catch { }
     finally
     {
         dc.Dispose();
     }
 }
Esempio n. 19
0
        public bool DoCloseAll(DateTime defaultCloseDate)
        {
            if (this.Closing) return false;
            this.Closing = true;
            VehicleDataContext vdc = new VehicleDataContext();
            PartDataContext pdc = new PartDataContext();

            DateTime crrMonth = DataFormat.DateOfFirstDayInMonth(DateTime.Now);
            LogMessage(string.Format("Starting Close {0} ----------", this.ForceClose ? ", forced by user" : "Automaticaly"));
            foreach (var d in pdc.Dealers)
            {
                bool hasW = false;
                LogMessage(string.Format("Closing dealer {0}: ", d.DealerCode));
                try
                {
                    // close warehouses
                    foreach (var w in d.ActiveWarehouses.Where(w => w.Type == VDMS.II.Entity.WarehouseType.Vehicle))
                    {
                        LogBeginMessage(string.Format("     Close warehouse {0}: ", w.Code));
                        try
                        {
                            hasW = true;
                            SaleInventoryLock wlck = InventoryHelper.GetInventoryLock(w.DealerCode, w.Code);
                            if (wlck == null)
                            {
                                InventoryHelper.DoCloseW(w.Code, w.DealerCode, defaultCloseDate.Month, defaultCloseDate.Year, vdc);
                            }
                            else
                            {
                                DateTime lastWLock = new DateTime((int)wlck.Year, (int)wlck.Month, 1);
                                lastWLock = lastWLock.AddMonths(1);
                                while (lastWLock < crrMonth)
                                {
                                    InventoryHelper.DoCloseW(w.Code, w.DealerCode, lastWLock.Month, lastWLock.Year, vdc);
                                    lastWLock = lastWLock.AddMonths(1);
                                }
                            }
                            LogEndMessage("Done!");
                        }
                        catch (Exception ex)
                        {
                            LogEndMessage(string.Format("Failed: {0}", DataFormat.TraceExceptionMessage(ex)));
                        }
                    }
                    // close Dealers
                    if (hasW)
                    {
                        SaleInventoryLock dlck = InventoryHelper.GetInventoryLock(d.DealerCode, 0);
                        if (dlck == null)
                        {
                            InventoryHelper.DoCloseD(d.DealerCode, defaultCloseDate.Month, defaultCloseDate.Year, vdc);
                        }
                        else
                        {
                            DateTime lastDLock = new DateTime((int)dlck.Year, (int)dlck.Month, 1);
                            lastDLock = lastDLock.AddMonths(1);
                            while (lastDLock < crrMonth)
                            {
                                InventoryHelper.DoCloseD(d.DealerCode, lastDLock.Month, lastDLock.Year, vdc);
                                lastDLock = lastDLock.AddMonths(1);
                            }
                        }
                        LogMessage(string.Format("Close dealer {0} done!", d.DealerCode));
                    }
                    else
                    {
                        LogMessage(string.Format("{0} has no warehouses!", d.DealerCode));
                    }
                }
                catch (Exception ex)
                {
                    LogMessage(string.Format("Close dealer {0} failed: {1}", d.DealerCode, DataFormat.TraceExceptionMessage(ex)));
                }
                LogEndMessage(" ");
            }
            LogMessage("AutoClose finished ----------");
            LogEndMessage(" ");

            vdc.Dispose();
            pdc.Dispose();
            this.Closing = false;
            return true;
        }
Esempio n. 20
0
        /// <summary>
        /// Save to inventory actions of day for each item code
        /// If data for item in same day exist, quantity will be update
        /// </summary>
        /// <param name="ItemCode"></param>
        /// <param name="ActionTime"></param>
        /// <param name="Quantity"></param>
        /// <param name="ActionType"></param>
        /// <param name="DealerCode"></param>
        /// <param name="BranchCode"></param>
        /// <returns></returns>
        public static SaleInventoryDay SaveInventoryDay(VehicleDataContext db, string ItemCode, DateTime ActionTime, int Quantity, int ActionType, string DealerCode, string BranchCode)
        {
            //var daoItem = DaoFactory.GetDao<VDMS.Core.Domain.Item, string>();
            //var item = daoItem.GetById(ItemCode, false); //true -> false

            //var daoInven = DaoFactory.GetDao<Inventoryday, long>();

            long ActionDay = long.Parse(ActionTime.ToString("yyyyMMdd"));
            //daoInven.SetCriteria(new ICriterion[] { Expression.Eq("Item", item), Expression.Eq("Actionday", ActionDay)
            //        , Expression.Eq("Actiontype", ActionType), Expression.Eq("Dealercode", DealerCode), Expression.Eq("Branchcode", BranchCode)});

            //var list = daoInven.GetAll();
            var ivd =
                db.SaleInventoryDays.FirstOrDefault(
                    p =>
                    p.ItemCode == ItemCode && p.ActionDay == ActionDay && p.ActionType == ActionType &&
                    p.DealerCode == DealerCode && p.BranchCode == BranchCode);

            if (ivd == null)
            {
                ivd = new SaleInventoryDay();
                ivd.ItemCode = ItemCode;
                ivd.ActionDay = ActionDay;
                ivd.ActionType = ActionType;
                ivd.DealerCode = DealerCode;
                ivd.BranchCode = BranchCode;
                ivd.Quantity = 0;
                db.SaleInventoryDays.InsertOnSubmit(ivd);
            }
            ivd.Quantity += Quantity;
            return ivd;
        }
Esempio n. 21
0
 public static Entity.SaleTransHistory SaveTransHist(VehicleDataContext db, ItemInstance IInst, DateTime tranDate, ItemStatus status, long ActualCost, string dCode, string bCode)
 {
     var transHis = new SaleTransHistory
                        {
                            ActualCost = ActualCost,
                            FromBranch = "",
                            ToBranch = string.Format("{0}-{1}", dCode, bCode),
                            ModifiedDate = DateTime.Now,
                            ItemInstance = IInst,
                            TransactionDate = tranDate,
                            TransactionType = (int) status,
                            ModifiedBy = UserHelper.Username
                        };
     db.SaleTransHistories.InsertOnSubmit(transHis);
     return transHis;
 }
Esempio n. 22
0
 public static Entity.ShippingHeader SaveOrUpdateShippingHeader(VehicleDataContext db, string areaCode, string shipNumber, string shipTo, DateTime shipDate, string dealerCode, int itemCount, string createBy)
 {
     var query = db.ShippingHeaders.FirstOrDefault(p => p.ShippingNumber.Equals(shipNumber.Trim()));
         if (query == null)
         {
             query = new Entity.ShippingHeader { CreatedDate = DateTime.Now, CreatedBy = createBy };
             db.ShippingHeaders.InsertOnSubmit(query);
         }
         query.ShippingNumber = shipNumber;
         query.ShippingTo = shipTo;
         query.ShippingDate = shipDate;
         query.DealerCode = dealerCode;
         query.AreaCode = areaCode;
         if (query.ItemCount < itemCount) query.ItemCount = itemCount;
     return query;
 }
Esempio n. 23
0
    protected void GridView3_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            GridView gv = (GridView)sender;

            // set Item No
            //Literal lit = (Literal)e.Row.FindControl("litNo");
            //if (lit == null) return;
            int no = gv.PageIndex * gv.PageSize + e.Row.RowIndex + 1;
            //lit.Text = no.ToString();
            e.Row.Cells[0].Text = no.ToString();

            // setup data
            string branch = e.Row.Cells[9].Text;

            string eng = ((Label)e.Row.FindControl("lblEngineNumber")).Text;
            TextBox txt = (TextBox)e.Row.FindControl("txtException");
            TextBox txtItemDate = (TextBox)e.Row.FindControl("txtItemImportDate");
            RadioButtonList rbl = (RadioButtonList)e.Row.FindControl("rblStatus");
            CheckBox chb = (CheckBox)e.Row.FindControl("chbVoucherStatus");
            CheckBox chbConfirmed = (CheckBox)e.Row.FindControl("chbOrderComfirmed");
            ImageButton imgDt = (ImageButton)e.Row.FindControl("imgbItemCarlendar");
            if (UserHelper.BranchCode != branch && !errorCode.Contains(ImportErrorCode.OrdersDoesNotConfirmed))
            {
                txt.Text = UserHelper.BranchCode;
                txt.Attributes["disabled"] = "disabled";
                e.Row.Enabled = false;
            }

            //check trang thai hien thoi cua xe
            using (var dc = new VehicleDataContext())
            {
                if (dc.ItemInstances.FirstOrDefault(i => i.EngineNumber == eng && ItemHepler.GetInstockItemStatus().Contains(i.Status)) != null)
                {
                    txt.Text = "Vehicle already instock!";
                    txt.Attributes["disabled"] = "disabled";
                    e.Row.Enabled = false;
                }
                if (dc.ItemInstances.FirstOrDefault(i => i.EngineNumber == eng && i.Status == (int)ItemStatus.Sold) != null)
                {
                    txt.Text = "Vehicle already sold out!";
                    txt.Attributes["disabled"] = "disabled";
                    e.Row.Enabled = false;
                }
            }

            //if ((txt == null) || (rbl == null) || (chb == null)) return;
            txt.Enabled = ((!chb.Checked) || (rbl.SelectedValue != "1"));
            string js = "Import_StatusChanged(document.getElementById('" + btnAccept.ClientID +
                                          "'),document.getElementById('" + txt.ClientID +
                                          "'),document.getElementById('" + rbl.ClientID +
                                        "_1'),document.getElementById('" + chb.ClientID +
                                          "'),document.getElementById('" + rbl.ClientID +
                                        "_0'),document.getElementById('" + txtItemDate.ClientID +
                                          "'),document.getElementById('" + txtImportDate.ClientID +
                                          "'),document.getElementById('" + imgDt.ClientID + "'))";
            rbl.Attributes.Add("OnClick", js);
            chb.Attributes.Add("OnClick", js);
            txt.Attributes.Add("onkeyup", js);
            txt.Attributes.Add("onblur", js);
            //txtItemDate.Attributes.Add("disabled", "disabled");

            //clientScript += " txtList[" + e.Row.RowIndex + "] = document.getElementById('" + txt.ClientID + "'); \n";
            clientScript += " document.getElementById('" + txt.ClientID + "'), ";
            clientFunc += "function(){" + js + ";}, ";

            //string OrderNumber = (string)((e.Row.DataItem as DataRowView)["OrderNumber"]);
            string OrderNumber = "";
            if (e.Row.DataItem is VDMS.I.Entity.IShippingDetail)
                OrderNumber = (e.Row.DataItem as VDMS.I.Entity.IShippingDetail).TipTopOrderNumber;
            else
                OrderNumber = (string)((e.Row.DataItem as DataRowView)["TipTopOrderNumber"]);

            IsAllOrderConfirmed &= chbConfirmed.Checked;
            // set import date range
            RangeValidator rv = (RangeValidator)e.Row.FindControl("rvItemImportDate");
            if (rv != null)
            {
                if ((ViewState[VS_BaseShipDate] == null) || (DateTime)ViewState[VS_BaseShipDate] > DateTime.Now)
                    Validator.SetDateRange(rv, DateTime.Now, DateTime.Now, true, e.Row.RowIndex + 1);
                else
                    Validator.SetDateRange(rv, (DateTime)ViewState[VS_BaseShipDate], DateTime.Now, true, e.Row.RowIndex + 1);
            }
        }
    }