Esempio n. 1
0
        public JsonResult SaveBasNormalScheduleS(CBasNormalScheduleS BasNormalScheduleS)
        {
            string str = string.Empty;

            if (!ModelState.IsValid)
            {
                List <string> errorList = ModelStateExtension.GetModelError(ViewData);
                str = string.Join(",", errorList.ToArray());
                return(Json(new { Success = false, Msg = str }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                CBasNormalScheduleS tmpBasNormalScheduleS = null;
                str = "<=SaveSuccess>";
                if (!string.IsNullOrEmpty(BasNormalScheduleS.BasNormalScheduleSId))
                {
                    tmpBasNormalScheduleS = _BasNormalScheduleSDBAccess.Get(BasNormalScheduleS.BasNormalScheduleSId);
                    TryUpdateModel <CBasNormalScheduleS>(tmpBasNormalScheduleS);
                }
                else
                {
                    tmpBasNormalScheduleS = BasNormalScheduleS;
                }
                string errMsg;
                bool   Success;
                Success = _BasNormalScheduleSDBAccess.Save(tmpBasNormalScheduleS, out errMsg);
                return(Json(new { Success = Success, Msg = Success ? str : errMsg, BasNormalScheduleS = tmpBasNormalScheduleS }, JsonRequestBehavior.AllowGet));
            }
        }
        /// <summary>
        /// Normal Schedule S Import
        /// </summary>
        /// <param name="basNormalScheduleId"></param>
        /// <param name="strPath"></param>
        private void NormalScheduleSImport(string basNormalScheduleId, string strPath)
        {
            try
            {
                NpoiHelper npoiHelper = new NpoiHelper(strPath, false);
                DataTable  dt         = npoiHelper.ExcelToDataTable(0);
                Dictionary <string, string> dicDealerCode          = new Dictionary <string, string>();
                Dictionary <string, string> dicDealerCodePickupDay = new Dictionary <string, string>();
                if (dt != null && dt.Rows.Count > 0)
                {
                    int index = 2;
                    foreach (DataRow row in dt.Rows)
                    {
                        NormalScheduleSImportCheckData(row, index);
                        string dealerCode = row["Dealer_Code"].ToString();
                        string definition = row["Definition"].ToString();
                        if (dicDealerCode.ContainsKey(dealerCode + "_" + definition))
                        {
                            throw new Exception(string.Format(@"Dealer Code ""{0}"" Definition ""{1}"" <=Duplicate>", dealerCode, definition));
                        }
                        dicDealerCode.Add(dealerCode + "_" + definition, dealerCode + "_" + definition);

                        string pickupDay = row["Pickup_Day"].ToString();
                        if (dicDealerCodePickupDay.ContainsKey(dealerCode + "_" + pickupDay))
                        {
                            throw new Exception(string.Format(@"Dealer Code ""{0}"",Pickup Day ""{1}"" <=Duplicate>", dealerCode, pickupDay));
                        }
                        dicDealerCodePickupDay.Add(dealerCode + "_" + pickupDay, dealerCode + "_" + pickupDay);

                        CBasNormalScheduleS item = new CBasNormalScheduleS();
                        Dashboard.Authentication.Authentication.UpdateEntity <CBasNormalScheduleS>(item);
                        item.BasNormalScheduleId  = basNormalScheduleId;
                        item.BasNormalScheduleSId = Guid.NewGuid().ToString();

                        item.DealerCode       = row["Dealer_Code"].ToString();
                        item.FacingPdc        = row["Facing_PDC"].ToString();
                        item.Definition       = row["Definition"].ToString();
                        item.DealerType       = row["Dealer_Type"].ToString();
                        item.ShortDealerName  = row["Short_Dealer_Name"].ToString();
                        item.Destination      = row["Destination"].ToString();
                        item.Province         = row["Province"].ToString();
                        item.CutoffDay        = Convert.ToInt32(row["Cutoff_Day"].ToString());
                        item.CutoffTime       = Convert.ToDateTime(row["Cutoff_Time"].ToString());
                        item.PickupDay        = Convert.ToInt32(row["Pickup_Day"].ToString());
                        item.PickupTime       = Convert.ToDateTime(row["Pickup_Time"].ToString());
                        item.TmsRouteName     = row["TMS_Route_Name"].ToString();
                        item.StopOrder        = Convert.ToInt32(row["Stop_Order"].ToString());
                        item.TransMode        = row["Trans_Mode"].ToString();
                        item.Overweek         = Convert.ToInt32(row["Overweek"].ToString());
                        item.ArrivalDay       = Convert.ToInt32(row["Arrival_Day"].ToString());
                        item.Eta              = Convert.ToDateTime(row["ETA"].ToString());
                        item.ArrivalTime      = row["Arrival_Time"].ToString();
                        item.ArrivalTimeStart = Convert.ToDateTime(row["Arrival_Time_Start"].ToString());
                        item.ArrivalTimeEnd   = Convert.ToDateTime(row["Arrival_Time_End"].ToString());
                        item.Forwarder        = row["Forwarder"].ToString();
                        DataContext.CBasNormalScheduleS.Add(item);

                        index++;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }