Example #1
0
        public JsonResult SaveBasSpecialDay(CBasSpecialDay BasSpecialDay)
        {
            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
            {
                CBasSpecialDay tmpBasSpecialDay = null;
                str = "<=SaveSuccess>";
                if (!string.IsNullOrEmpty(BasSpecialDay.BasSpecialDayId))
                {
                    tmpBasSpecialDay = _BasSpecialDayDBAccess.Get(BasSpecialDay.BasSpecialDayId);
                    TryUpdateModel <CBasSpecialDay>(tmpBasSpecialDay);
                }
                else
                {
                    tmpBasSpecialDay = BasSpecialDay;
                }
                string errMsg;
                bool   Success;
                Success = _BasSpecialDayDBAccess.Save(tmpBasSpecialDay, out errMsg);
                return(Json(new { Success = Success, Msg = Success ? str : errMsg, BasSpecialDay = tmpBasSpecialDay }, JsonRequestBehavior.AllowGet));
            }
        }
 public bool Save(CBasSpecialSchedule BasSpecialSchedule, out string errMsg)
 {
     errMsg = "";
     try
     {
         if (BasSpecialSchedule.ArrivalTimeStart > BasSpecialSchedule.ArrivalTimeEnd)
         {
             errMsg = "<=StartTimeGreaterThanEndTime>";
             return(false);
         }
         var basSpecialScheduleIndex = DataContext.CBasSpecialScheduleIndex.FirstOrDefault(p => p.BasSpecialScheduleIndexId == BasSpecialSchedule.BasSpecialScheduleIndexId);
         if (basSpecialScheduleIndex != null)
         {
             if (BasSpecialSchedule.PickupDay < basSpecialScheduleIndex.EffectiveDate || BasSpecialSchedule.PickupDay > basSpecialScheduleIndex.ExpirationDate)
             {
                 errMsg = "<=PickupDayError>";
                 return(false);
             }
         }
         Dashboard.Authentication.Authentication.UpdateEntity <CBasSpecialSchedule>(BasSpecialSchedule);
         if (string.IsNullOrEmpty(BasSpecialSchedule.BasSpecialScheduleId))
         {
             if (DataContext.CBasSpecialSchedule.Any(c => c.DealerCode == BasSpecialSchedule.DealerCode && c.PickupDay == BasSpecialSchedule.PickupDay && c.BasSpecialScheduleIndexId == BasSpecialSchedule.BasSpecialScheduleIndexId))
             {
                 errMsg = "<=DuplicatedSpecialSchedule>";
                 return(false);
             }
             BasSpecialSchedule.BasSpecialScheduleId = Guid.NewGuid().ToString();
             DataContext.CBasSpecialSchedule.Add(BasSpecialSchedule);
         }
         else
         {
             if (DataContext.CBasSpecialSchedule.Any(c => c.DealerCode == BasSpecialSchedule.DealerCode && c.PickupDay == BasSpecialSchedule.PickupDay && c.BasSpecialScheduleId != BasSpecialSchedule.BasSpecialScheduleId && c.BasSpecialScheduleIndexId == BasSpecialSchedule.BasSpecialScheduleIndexId))
             {
                 errMsg = "<=DuplicatedSpecialSchedule>";
                 return(false);
             }
         }
         if (!DataContext.CBasSpecialDay.Any(p => p.SpecialDay == BasSpecialSchedule.PickupDay))
         {
             CBasSpecialDay BasSpecialDay = new CBasSpecialDay();
             Dashboard.Authentication.Authentication.UpdateEntity <CBasSpecialDay>(BasSpecialDay);
             BasSpecialDay.SpecialDay = BasSpecialSchedule.PickupDay;
             BasSpecialDay.BasSpecialScheduleIndexId = BasSpecialSchedule.BasSpecialScheduleIndexId;
             BasSpecialDay.BasSpecialDayId           = Guid.NewGuid().ToString();
             DataContext.CBasSpecialDay.Add(BasSpecialDay);
         }
         DataContext.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         errMsg = "<=SaveError>";
         Log4netHelper.LoadADONetAppender();
         ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
         log.Info("BasSpecialSchedule Save方法出错。Author:chenjm ", ex);
         return(false);
     }
 }
        /// <summary>
        /// Special Schedule Import
        /// </summary>
        /// <param name="strPath"></param>
        private void SpecialScheduleImport(string BasSpecialScheduleIndexId, string strPath)
        {
            try
            {
                //清除
                var basSpecialScheduleIndex = DataContext.CBasSpecialScheduleIndex.FirstOrDefault(p => p.BasSpecialScheduleIndexId == BasSpecialScheduleIndexId);

                //保存上传的文件路径
                basSpecialScheduleIndex.SpecilScheduleFile       = strPath;
                DataContext.Entry(basSpecialScheduleIndex).State = System.Data.EntityState.Modified;

                var args = new DbParameter[] { new SqlParameter("@id", BasSpecialScheduleIndexId) };
                DataContext.Database.ExecuteSqlCommand("DELETE BAS_SPECIAL_DAY WHERE BAS_SPECIAL_SCHEDULE_INDEX_ID=@id", args);
                var argst = new DbParameter[] { new SqlParameter("@id", BasSpecialScheduleIndexId) };
                DataContext.Database.ExecuteSqlCommand("DELETE BAS_SPECIAL_SCHEDULE WHERE BAS_SPECIAL_SCHEDULE_INDEX_ID= @id", argst);

                //自动抓取的特殊日列表
                List <DateTime> ArrBasSpecialDay = new List <DateTime>();

                NpoiHelper npoiHelper = new NpoiHelper(strPath, false);
                DataTable  dt         = npoiHelper.ExcelToDataTable(0);
                Dictionary <string, string> dicDealerCode = new Dictionary <string, string>();
                if (dt != null && dt.Rows.Count > 0)
                {
                    int index = 2;
                    foreach (DataRow row in dt.Rows)
                    {
                        DataValidator(row, "Dealer_Code", index);
                        string dealerCode = row["Dealer_Code"].ToString();
                        string pickupTime = "";
                        #region 1st Stk
                        if (row["1st_S_Pickup_Date"] != null && !row["1st_S_Pickup_Date"].ToString().IsNullString())
                        {
                            DataValidator <DateTime>(row, "1st_S_Cutoff_Day", index);
                            DataValidator <DateTime>(row, "1st_S_Cutoff_Time", index);
                            DataValidator <DateTime>(row, "1st_S_Pickup_Date", index);
                            DataValidator <DateTime>(row, "1st_S_Pickup_Time", index);
                            DataValidator <DateTime>(row, "1st_S_Arrival_Date", index);
                            DataValidator(row, "1st_S_Arrival_Time", index);
                            DataValidator <DateTime>(row, "1st_S_Arrival_Time_Start", index);
                            DataValidator <DateTime>(row, "1st_S_Arrival_Time_End", index);

                            DateTime pickupDay = Convert.ToDateTime(row["1st_S_Pickup_Date"].ToString());
                            pickupTime = pickupDay.ToString("yyyy-MM-dd");
                            if (dicDealerCode.ContainsKey(dealerCode + "_" + pickupTime))
                            {
                                throw new Exception(string.Format(@"Dealer Code ""{0}"" 1st_S_Pickup_Date ""{1}"", <=Duplicate>", dealerCode, pickupDay.ToString("yyyy-MM-dd")));
                            }
                            dicDealerCode.Add(dealerCode + "_" + pickupTime, dealerCode + "_" + pickupTime);
                            var oldFirstSpecialSchedule = DataContext.CBasSpecialSchedule.Where(p => p.DealerCode == dealerCode && p.PickupDay == pickupDay).FirstOrDefault();
                            if (oldFirstSpecialSchedule == null)
                            {
                                oldFirstSpecialSchedule = new CBasSpecialSchedule();
                                Dashboard.Authentication.Authentication.UpdateEntity <CBasSpecialSchedule>(oldFirstSpecialSchedule);
                                oldFirstSpecialSchedule.BasSpecialScheduleId = Guid.NewGuid().ToString();
                                DataContext.CBasSpecialSchedule.Add(oldFirstSpecialSchedule);
                            }
                            else
                            {
                                Dashboard.Authentication.Authentication.UpdateEntity <CBasSpecialSchedule>(oldFirstSpecialSchedule);
                                DataContext.CBasSpecialSchedule.Attach(oldFirstSpecialSchedule);
                                DataContext.Entry(oldFirstSpecialSchedule).State = EntityState.Modified;
                            }
                            //标记特殊时效的归属关系
                            oldFirstSpecialSchedule.BasSpecialScheduleIndexId = BasSpecialScheduleIndexId;
                            oldFirstSpecialSchedule.DealerCode       = row["Dealer_Code"].ToString();
                            oldFirstSpecialSchedule.Definition       = "1st Stk";
                            oldFirstSpecialSchedule.FacingPdc        = row["Facing_PDC"].ToString();
                            oldFirstSpecialSchedule.DealerType       = row["Dealer_Type"].ToString();
                            oldFirstSpecialSchedule.DealerName       = row["Dealer_Name"].ToString();
                            oldFirstSpecialSchedule.Destination      = row["Destination"].ToString();
                            oldFirstSpecialSchedule.Province         = row["Province"].ToString();
                            oldFirstSpecialSchedule.CutoffDay        = Convert.ToDateTime(row["1st_S_Cutoff_Day"].ToString());
                            oldFirstSpecialSchedule.CutoffTime       = Convert.ToDateTime(row["1st_S_Cutoff_Time"].ToString());
                            oldFirstSpecialSchedule.PickupDay        = Convert.ToDateTime(row["1st_S_Pickup_Date"].ToString());
                            oldFirstSpecialSchedule.PickupTime       = Convert.ToDateTime(row["1st_S_Pickup_Time"].ToString());
                            oldFirstSpecialSchedule.TransMode        = row["1st_S_Trans_Mode"].ToString();
                            oldFirstSpecialSchedule.ArrivalDay       = Convert.ToDateTime(row["1st_S_Arrival_Date"].ToString());
                            oldFirstSpecialSchedule.ArrivalTime      = row["1st_S_Arrival_Time"].ToString();
                            oldFirstSpecialSchedule.ArrivalTimeStart = Convert.ToDateTime(row["1st_S_Arrival_Time_Start"].ToString());
                            oldFirstSpecialSchedule.ArrivalTimeEnd   = Convert.ToDateTime(row["1st_S_Arrival_Time_End"].ToString());
                            if (oldFirstSpecialSchedule.PickupDay < basSpecialScheduleIndex.EffectiveDate || oldFirstSpecialSchedule.PickupDay > basSpecialScheduleIndex.ExpirationDate)
                            {
                                throw new Exception(string.Format(@"Dealer Code ""{0}"", ""{1}"" <=PickupDayError>, <=Duplicate>", dealerCode, pickupDay.ToString("yyyy-MM-dd")));
                            }

                            #region 自动抓取特殊日
                            ArrBasSpecialDay.Add(oldFirstSpecialSchedule.PickupDay);
                            #endregion
                        }
                        #endregion
                        #region 2nd Stk
                        if (row["2nd_S_Pickup_Date"] != null && !row["2nd_S_Pickup_Date"].ToString().IsNullString())
                        {
                            DataValidator <DateTime>(row, "2nd_S_Cutoff_Day", index);
                            DataValidator <DateTime>(row, "2nd_S_Cutoff_Time", index);
                            DataValidator <DateTime>(row, "2nd_S_Pickup_Date", index);
                            DataValidator <DateTime>(row, "2nd_S_Pickup_Time", index);
                            DataValidator <DateTime>(row, "2nd_S_Arrival_Date", index);
                            DataValidator(row, "2nd_S_Arrival_Time", index);
                            DataValidator <DateTime>(row, "2nd_S_Arrival_Time_Start", index);
                            DataValidator <DateTime>(row, "2nd_S_Arrival_Time_End", index);

                            DateTime pickupDay = Convert.ToDateTime(row["2nd_S_Pickup_Date"].ToString());
                            pickupTime = pickupDay.ToString("yyyy-MM-dd");
                            if (dicDealerCode.ContainsKey(dealerCode + "_" + pickupTime))
                            {
                                throw new Exception(string.Format(@"Dealer Code ""{0}"" 2nd_S_Pickup_Date ""{1}"", <=Duplicate>", dealerCode, pickupDay.ToString("yyyy-MM-dd")));
                            }
                            dicDealerCode.Add(dealerCode + "_" + pickupTime, dealerCode + "_" + pickupTime);
                            var oldFirstSpecialSchedule = DataContext.CBasSpecialSchedule.Where(p => p.DealerCode == dealerCode && p.PickupDay == pickupDay).FirstOrDefault();
                            if (oldFirstSpecialSchedule == null)
                            {
                                oldFirstSpecialSchedule = new CBasSpecialSchedule();
                                Dashboard.Authentication.Authentication.UpdateEntity <CBasSpecialSchedule>(oldFirstSpecialSchedule);
                                oldFirstSpecialSchedule.BasSpecialScheduleId = Guid.NewGuid().ToString();
                                DataContext.CBasSpecialSchedule.Add(oldFirstSpecialSchedule);
                            }
                            else
                            {
                                Dashboard.Authentication.Authentication.UpdateEntity <CBasSpecialSchedule>(oldFirstSpecialSchedule);
                                DataContext.CBasSpecialSchedule.Attach(oldFirstSpecialSchedule);
                                DataContext.Entry(oldFirstSpecialSchedule).State = EntityState.Modified;
                            }
                            oldFirstSpecialSchedule.BasSpecialScheduleIndexId = BasSpecialScheduleIndexId;
                            oldFirstSpecialSchedule.DealerCode       = row["Dealer_Code"].ToString();
                            oldFirstSpecialSchedule.Definition       = "2nd Stk";
                            oldFirstSpecialSchedule.FacingPdc        = row["Facing_PDC"].ToString();
                            oldFirstSpecialSchedule.DealerType       = row["Dealer_Type"].ToString();
                            oldFirstSpecialSchedule.DealerName       = row["Dealer_Name"].ToString();
                            oldFirstSpecialSchedule.Destination      = row["Destination"].ToString();
                            oldFirstSpecialSchedule.Province         = row["Province"].ToString();
                            oldFirstSpecialSchedule.CutoffDay        = Convert.ToDateTime(row["2nd_S_Cutoff_Day"].ToString());
                            oldFirstSpecialSchedule.CutoffTime       = Convert.ToDateTime(row["2nd_S_Cutoff_Time"].ToString());
                            oldFirstSpecialSchedule.PickupDay        = Convert.ToDateTime(row["2nd_S_Pickup_Date"].ToString());
                            oldFirstSpecialSchedule.PickupTime       = Convert.ToDateTime(row["2nd_S_Pickup_Time"].ToString());
                            oldFirstSpecialSchedule.TransMode        = row["2nd_S_Trans_Mode"].ToString();
                            oldFirstSpecialSchedule.ArrivalDay       = Convert.ToDateTime(row["2nd_S_Arrival_Date"].ToString());
                            oldFirstSpecialSchedule.ArrivalTime      = row["2nd_S_Arrival_Time"].ToString();
                            oldFirstSpecialSchedule.ArrivalTimeStart = Convert.ToDateTime(row["2nd_S_Arrival_Time_Start"].ToString());
                            oldFirstSpecialSchedule.ArrivalTimeEnd   = Convert.ToDateTime(row["2nd_S_Arrival_Time_End"].ToString());
                            if (oldFirstSpecialSchedule.PickupDay < basSpecialScheduleIndex.EffectiveDate || oldFirstSpecialSchedule.PickupDay > basSpecialScheduleIndex.ExpirationDate)
                            {
                                throw new Exception(string.Format(@"Dealer Code ""{0}"", ""{1}"" <=PickupDayError>, <=Duplicate>", dealerCode, pickupDay.ToString("yyyy-MM-dd")));
                            }
                            #region 自动抓取特殊日
                            ArrBasSpecialDay.Add(oldFirstSpecialSchedule.PickupDay);
                            #endregion
                        }
                        #endregion
                        index++;
                    }
                    //添加自动抓取的特殊日到数据库
                    var ReArrBasSpecialDay = ArrBasSpecialDay.Distinct();
                    foreach (var item in ReArrBasSpecialDay)
                    {
                        CBasSpecialDay BasSpecialDay = new CBasSpecialDay();
                        Dashboard.Authentication.Authentication.UpdateEntity <CBasSpecialDay>(BasSpecialDay);
                        BasSpecialDay.SpecialDay = item;
                        BasSpecialDay.BasSpecialScheduleIndexId = BasSpecialScheduleIndexId;
                        BasSpecialDay.BasSpecialDayId           = Guid.NewGuid().ToString();
                        DataContext.CBasSpecialDay.Add(BasSpecialDay);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }