Пример #1
0
        public static Iteminstance SaveOrUpdateItemInstance(string dealerCode, string branchCode, string engineNumber, string shipNumber, string invoice, string itemType, Item item, DateTime impDate, string color, int status, DateTime madeDate, string DatabaseCode)
        {
            IDao<Iteminstance, long> dao;
            //List<Iteminstance> list;
            Iteminstance IIS = null;

            dao = DaoFactory.GetDao<Iteminstance, long>();

            dao.SetCriteria(new ICriterion[] { Expression.Eq("Enginenumber", engineNumber.Trim()) });
            //// khong cho phep de` du lieu xe cu
            //if (dao.GetCount() > 0)
            //{
            //    Exception e = new Exception("Enginenumber exist: " + engineNumber);
            //    throw e;
            //}

            List<Iteminstance> list = dao.GetAll();
            if (list.Count > 0)
                IIS = (Iteminstance)list[0];
            else
            {
                IIS = new Iteminstance();
                IIS.Createddate = DateTime.Now;
            }

            // get shipping header to take some data
            ShippingHeader SH = GetShippingHeaderByShippingNumber(shipNumber);
            if (SH == null)
            {
                Exception e = new Exception("Shipping number does not exist: " + shipNumber);
                throw e;
            }
            else
            {
                // save to database
                //IIS.Dealercode = SH.Dealercode;
                IIS.Enginenumber = engineNumber;
                IIS.Itemtype = itemType;
                IIS.Item = item;
                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.MaxValue;

                dao.SaveOrUpdate(IIS);
            }
            return IIS;
        }
Пример #2
0
        public static Shippingdetail SaveOrUpdateShippingDetail(long shipId, 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();

            if (list.Count > 0) SD = (Shippingdetail)list[0];
            if (SD == null)
            {
                shdao = DaoFactory.GetDao<ShippingHeader, long>();
                SD = new Shippingdetail();
                SD.Shippingheader = shdao.GetById(shipId, false); //true -> false
                SD.Enginenumber = engineNumber;
            }

            SD.Itemtype = itemType;
            SD.Color = color;
            SD.Item = item;
            SD.Branchcode = branchCode;
            SD.Ordernumber = orderNumber;
            SD.Status = status;
            SD.Voucherstatus = voucher;
            if (itemInstance != null) SD.PRODUCTINSTANCE = itemInstance;
            //if (!string.IsNullOrEmpty(ex))
            SD.Exception = ex;

            dao.SaveOrUpdate(SD);
            return SD;
        }