示例#1
0
        public decimal AddHeadersWithDetails(TS_OR_HEADER orHeader, TS_OR_HEADER altORHeader, List <TS_OR_DETAIL> detailList)
        {
            try
            {
                decimal nextVal = dal.GetOrderSqeNextVal();
                orHeader.ORDER_REQ_NO = nextVal;
                dal.Add(orHeader, false);

                if (altORHeader != null)
                {
                    altORHeader.ORDER_REQ_NO = nextVal;
                    dal.Add(altORHeader, false);
                }

                //detail part
                if (detailList != null && detailList.Count > 0)
                {
                    foreach (var item in detailList)
                    {
                        item.ORDER_REQ_NO = nextVal;
                        dal.Add(item, false);
                    }
                }

                dal.SaveChanges();
                return(nextVal);
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
                return(0);
            }
        }
示例#2
0
        public static TS_OR_HEADER ConvertExAliaAddr2Header(ExVAliasAddr addr, string seq, string dueDate, string orderType, string shipCompFlag, string customerPONO, string orderNote, bool isSpecialShip, string appUser, bool IsAltAddr = false)
        {
            TS_OR_HEADER header = new TS_OR_HEADER();

            header.ORDER_REQ_NO     = string.IsNullOrEmpty(seq)?0:decimal.Parse(seq); //sequence
            header.SHIPFROM_SEQ     = IsAltAddr ? 1 : 0;                              // 0 or 1
            header.TO_SYSTEM        = addr.SysID;
            header.ALIAS_NAME       = addr.AliasName;
            header.CUSTOMER_NO      = addr.CustomerNo;
            header.BILL_TO_LOCATION = (decimal)addr.Bill2Location;
            header.SHIP_TO_LOCATION = (decimal)addr.Ship2Location;
            header.DEST_LOCATION    = addr.DestLocation;
            header.DUE_DATE         = DateTime.Parse(dueDate);
            header.ORDER_TYPE       = orderType;
            header.CUSTOMER_PO_NO   = customerPONO;
            header.SPL_IND          = ValueConvert.BoolToNY(isSpecialShip);
            header.SHIPCOMP_FLAG    = shipCompFlag;
            header.ORDER_STATUS     = OrderStatusEnum.S.ToString(); //draft ind
            header.CREATION_DATE    = DateTime.Now;
            header.CREATED_BY       = appUser;                      //appuser get from local arg
            header.RECORD_DATE      = DateTime.Now;
            header.UPDATED_BY       = appUser;
            header.ORDER_NOTES      = orderNote;

            return(header);
        }
示例#3
0
 public void AddOrUpdateHeader(TS_OR_HEADER header, bool autoSave = true)
 {
     if (db.TS_OR_HEADER.Any(a => a.ORDER_REQ_NO == header.ORDER_REQ_NO && a.SHIPFROM_SEQ == header.SHIPFROM_SEQ))
     {
         Update(header, autoSave);
     }
     else
     {
         Add(header, autoSave);
     }
 }
示例#4
0
        public ActionResult SaveOrder(OrderSaveArg arg)
        {
            try
            {
                if (arg.headInfo == null)
                {
                    return(Content("fail"));
                }

                string appUser = Session[CHubConstValues.SessionUser].ToString();

                CHubEntities     db  = new CHubEntities();
                TS_OR_HEADER_BLL bll = new TS_OR_HEADER_BLL(db);

                //Header part
                TS_OR_HEADER orHeader    = ManualClassConvert.ConvertExAliaAddr2Header(arg.headInfo, arg.seq, arg.dueDate, arg.orderType, arg.shipCompFlag, arg.customerPONO, arg.orderNote, arg.isSpecialShip, appUser);
                TS_OR_HEADER altORHeader = null;
                if (arg.altHeadInfo != null)
                {
                    altORHeader = ManualClassConvert.ConvertExAliaAddr2Header(arg.altHeadInfo, arg.seq, arg.dueDate, arg.orderType, arg.shipCompFlag, arg.customerPONO, arg.orderNote, arg.isSpecialShip, appUser, true);
                }

                //Detail part
                List <TS_OR_DETAIL> detailList = null;
                if (arg.olList != null && arg.olList.Count > 0)
                {
                    detailList = new List <TS_OR_DETAIL>();
                    foreach (var item in arg.olList)
                    {
                        //ignore wrong lines
                        if (string.IsNullOrEmpty(item.PartNo) || string.IsNullOrEmpty(item.PriAVLCheckColor))
                        {
                            continue;
                        }
                        TS_OR_DETAIL detail = ManualClassConvert.ConvertOLItem2Detail(item, arg.seq, appUser);
                        detailList.Add(detail);
                    }
                }

                decimal seq = 0;
                if (string.IsNullOrEmpty(arg.seq))
                {
                    seq = bll.AddHeadersWithDetails(orHeader, altORHeader, detailList);
                }
                else
                {
                    seq = bll.UpdateHeadersWithDetails(orHeader, altORHeader, detailList);
                }

                if (seq != 0.00M)
                {
                    return(Content(seq.ToString()));
                }
                else
                {
                    Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                    return(Content("Fail to save order"));
                }
            }
            catch (Exception ee)
            {
                //log ee
                Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                return(Content(ee.Message));
            }
        }
示例#5
0
        /// <summary>
        /// update header and detail ,need to delete stage date if exist stage data
        /// </summary>
        /// <param name="orHeader"></param>
        /// <param name="altORHeader"></param>
        /// <param name="detailList"></param>
        /// <returns></returns>
        public decimal UpdateHeadersWithDetails(TS_OR_HEADER orHeader, TS_OR_HEADER altORHeader, List <TS_OR_DETAIL> detailList)
        {
            TS_OR_HEADER_STAGE_BLL hsBLL = new TS_OR_HEADER_STAGE_BLL(dal.db);
            //Or Header part => if exist stage =>delete stage and add header. if not exist stage => update header
            TS_OR_HEADER_STAGE headerStage = hsBLL.GetSpecifyHeaderStage(orHeader.ORDER_REQ_NO, orHeader.SHIPFROM_SEQ);

            if (headerStage != null)
            {
                //Must be save draft to save order
                dal.Delete(headerStage, false);
                dal.Add(orHeader, false);

                TS_OR_HEADER_STAGE altHeaderStage = hsBLL.GetSpecifyHeaderStage(orHeader.ORDER_REQ_NO, (decimal)ShipFromSeqEnum.Alternative);
                if (altHeaderStage != null)
                {
                    dal.Delete(altHeaderStage, false);
                }
                if (altORHeader != null)
                {
                    dal.Add(altORHeader);
                }

                TS_OR_DETAIL_STAGE_DAL dStageDal = new TS_OR_DETAIL_STAGE_DAL(dal.db);

                //Delete exist details
                List <TS_OR_DETAIL_STAGE> existDetails = dStageDal.GetDetailsStageByOrderSeq(orHeader.ORDER_REQ_NO);
                foreach (var item in existDetails)
                {
                    dal.Delete(item, false);
                }
            }
            else
            {
                //Must be override save order
                dal.Update(orHeader, false);
                if (altORHeader != null)
                {
                    dal.AddOrUpdateHeader(altORHeader, false);
                }
            }


            //Detail part
            TS_OR_DETAIL_DAL detailDal = new TS_OR_DETAIL_DAL(dal.db);
            //delete old part will insert new data
            List <TS_OR_DETAIL> oldDetails = detailDal.GetDetailsBySeq(orHeader.ORDER_REQ_NO);

            if (oldDetails != null && oldDetails.Count > 0)
            {
                foreach (var item in oldDetails)
                {
                    detailDal.Delete(item, false);
                }
            }

            if (detailList != null && detailList.Count > 0)
            {
                foreach (var item in detailList)
                {
                    detailDal.Add(item, false);
                }
            }

            dal.SaveChanges();
            return(orHeader.ORDER_REQ_NO);
        }