예제 #1
0
 public static BonusPlanDetail AddEditingItem(long PlanId, string type)
 {
     var o = new BonusPlanDetail()
     {
         Id = Guid.NewGuid(),
         BonusPlanHeaderId = PlanId,
         SessionId = HttpContext.Current.Session.SessionID,
         UserName = UserHelper.Username,
         CreatedDate = DateTime.Now,
         PlanType = type,
     };
     EditingItems.Add(o);
     return o;
 }
 private void detach_BonusPlanDetails(BonusPlanDetail entity)
 {
     this.SendPropertyChanging("BonusPlanDetails");
     entity.BonusPlanHeader = null;
 }
 private void attach_BonusPlanDetails(BonusPlanDetail entity)
 {
     this.SendPropertyChanging("BonusPlanDetails");
     entity.Dealer = this;
 }
예제 #4
0
 public static void AddEditingItem(BonusPlanDetail item)
 {
     item.Id = Guid.NewGuid();
     item.SessionId = HttpContext.Current.Session.SessionID;
     EditingItems.Add(item);
 }
예제 #5
0
 public static void UpdateEditingItem(BonusPlanDetail Item)
 {
     var o = EditingItems.SingleOrDefault(p => p.Id == Item.Id);
     if (o != null)
     {
         o.Amount = Item.Amount;
         o.BonusDate = Item.BonusDate;
         o.Description = Item.Description;
         o.Status = Item.Status;
         o.PlanType = Item.PlanType;
         o.DealerCode = Item.DealerCode;
     }
 }
예제 #6
0
        public static void SaveImportingBonus()
        {
            foreach (var item in EditingItems)
            {
                var planHeader = DC.BonusPlanHeaders.FirstOrDefault(h => h.BonusPlanName.ToUpper() == item.BonusHeaderPlanName.ToUpper());
                if (planHeader == null)
                {
                    planHeader = new BonusPlanHeader
                    {
                        BonusPlanName = item.BonusHeaderPlanName,
                        CreatedDate = DateTime.Now,
                        DatabaseCode = UserHelper.DatabaseCode == null ? "HTFDNF" : UserHelper.DatabaseCode,
                        FromDate = item.BonusHeaderPlanMonth == DateTime.MinValue ? DateTime.Now : item.BonusHeaderPlanMonth,
                        PlanType = BonusType.Vehicle,
                        Status = BonusStatus.Normal,
                        UserName = UserHelper.Username,
                    };

                    DC.BonusPlanHeaders.InsertOnSubmit(planHeader);
                }

                var planDetail = DC.BonusPlanDetails.Where(p => p.DealerCode.ToUpper() == item.DealerCode.ToUpper() && p.BonusPlanHeader.BonusPlanName.ToUpper() == planHeader.BonusPlanName.ToUpper()).FirstOrDefault();
                if (planDetail == null)
                {
                    planDetail = new BonusPlanDetail
                    {
                        BonusPlanHeader = planHeader,
                        CreatedDate = DateTime.Now,
                        Status = BonusStatus.Normal,
                        PlanType = BonusType.Vehicle,
                    };
                    DC.BonusPlanDetails.InsertOnSubmit(planDetail);
                }

                planDetail.Amount = item.Amount;
                planDetail.BonusDate = item.BonusDate;
                planDetail.DealerCode = item.DealerCode;
                planDetail.Description = item.Description;
                planDetail.UserName = UserHelper.Username;
                planDetail.BonusSourceId = item.BonusSourceId;
            }
            DC.SubmitChanges();
        }
예제 #7
0
 public static bool IsValidBonusDate(BonusPlanDetail item)
 {
     return item.BonusDate.HasValue && (
         !BonusCloser.IsLock(item.DealerCode, item.BonusDate.Value) //&&
         //item.BonusDate.Value.Date <= DateTime.Now.Date ||
         //item.Status == BonusStatus.Confirmed || item.Status == BonusStatus.Locked
         );
 }
예제 #8
0
        public static void ImportExcel(Stream excel, VDMS.VDMSSetting.SettingData.BonusExcelSetting setting)
        {
            IExcelDataReader spreadsheet = ExcelReaderFactory.CreateBinaryReader(excel);
            var amountCol = setting.Amount;
            var dateCol = setting.BonusDate;
            var planCol = setting.BonusPlan;
            var sourceCol = setting.BonusSource;
            var dateFormat = setting.DateFormat;
            var dealerCol = setting.DealerCode;
            var descCol = setting.Description;
            var startRow = setting.StartRow;
            var planMonthCol = setting.PlanMonth;

            var rows = spreadsheet.AsDataSet().Tables[0].AsEnumerable();
            var query = from r in rows
                        select new
                        {
                            Amount = amountCol == 0 || amountCol > r.ItemArray.Count() ? string.Empty : r.Field<string>(amountCol - 1),
                            Date = dateCol == 0 || dateCol > r.ItemArray.Count() ? string.Empty : r.Field<string>(dateCol - 1),
                            Plan = planCol == 0 || planCol > r.ItemArray.Count() ? string.Empty : r.Field<string>(planCol - 1),
                            Source = sourceCol == 0 || sourceCol > r.ItemArray.Count() ? string.Empty : r.Field<string>(sourceCol - 1),
                            DealerCode = dealerCol == 0 || dealerCol > r.ItemArray.Count() ? string.Empty : r.Field<string>(dealerCol - 1),
                            Description = descCol == 0 || descCol > r.ItemArray.Count() ? string.Empty : r.Field<string>(descCol - 1),
                            PlanMonth = planMonthCol == 0 || planMonthCol > r.ItemArray.Count() ? string.Empty : r.Field<string>(planMonthCol - 1),
                        };
            var data = query.Skip(startRow - 1).TakeWhile(v => !string.IsNullOrEmpty(v.Plan) ||
                                                               !string.IsNullOrEmpty(v.Amount) ||
                                                               !string.IsNullOrEmpty(v.DealerCode));

            foreach (var item in data)
            {
                //var planHeader = DC.BonusPlanHeaders.FirstOrDefault(h => h.BonusPlanName.ToUpper() == item.Plan.ToUpper());
                var bonusSource = DC.BonusSources.FirstOrDefault(s => s.BonusSourceName.ToUpper() == item.Source.ToUpper());
                var dealer = DC.Dealers.FirstOrDefault(s => s.DealerCode.ToUpper() == item.DealerCode.ToUpper());
                var planExisted = DC.BonusPlanDetails.Where(p => p.DealerCode.ToUpper() == item.DealerCode.ToUpper() && p.BonusPlanHeader.BonusPlanName.ToUpper() == item.Plan.ToUpper()).FirstOrDefault();
                if (bonusSource != null && dealer != null && (planExisted == null || planExisted.Status != BonusStatus.Confirmed))
                {
                    if (planExisted != null)
                    {
                        var o = AddEditingItem(planExisted.BonusPlanHeaderId, planExisted.PlanType);
                        o.BonusHeaderPlanName = item.Plan;
                        o.Amount = int.Parse(item.Amount);
                        o.BonusDate = DataFormat.DateFromExcel(item.Date, dateFormat);
                        o.BonusPlanDetailId = planExisted.BonusPlanDetailId;
                        o.BonusSourceId = bonusSource.BonusSourceId;
                        o.CreatedDate = DateTime.Now;
                        o.DealerCode = dealer.DealerCode;
                        o.Description = item.Description;
                        o.BonusSourceName = bonusSource.BonusSourceName;
                        o.BonusHeaderPlanMonth = DataFormat.DateFromExcel(item.PlanMonth, dateFormat);
                    }
                    else
                    {
                        var planDetail = new BonusPlanDetail();

                        planDetail.BonusHeaderPlanName = item.Plan;
                        planDetail.Amount = int.Parse(item.Amount);
                        planDetail.BonusDate = DataFormat.DateFromExcel(item.Date, dateFormat);
                        //planDetail.BonusPlanHeaderId = planHeader.BonusPlanHeaderId;
                        planDetail.BonusSourceId = bonusSource.BonusSourceId;
                        planDetail.CreatedDate = DateTime.Now;
                        planDetail.DealerCode = dealer.DealerCode;
                        planDetail.Description = item.Description;
                        planDetail.BonusSourceName = bonusSource.BonusSourceName;
                        planDetail.BonusHeaderPlanMonth = DataFormat.DateFromExcel(item.PlanMonth, dateFormat);
                        //AddEditingItem(planDetail.BonusPlanHeaderId, planDetail.BonusSourceId.Value, planDetail.BonusDate.Value, planDetail.DealerCode, BonusStatus.Normal, BonusType.Vehicle, planDetail.Amount, planDetail.Description);
                        AddEditingItem(planDetail);
                    }
                }
            }
        }
예제 #9
0
 public static void DeleteEditingItem(BonusPlanDetail Item)
 {
     var it = EditingItems.SingleOrDefault(t => t.Id == Item.Id);
     if (it != null && it.BonusPlanDetailId > 0)
         it.Deleted = true;
     else
         EditingItems.RemoveAll(i => i.Id == Item.Id);
 }
예제 #10
0
 public static void ConfirmItem(BonusPlanDetail item)
 {
     if (item.Status == BonusStatus.Normal && IsValidBonusDate(item))
     {
         item.Status = BonusStatus.Confirmed;
         MakeBonusTrans(DC, BonusTransactionType.ConfirmPlan, item.BonusDate.Value, item.DealerCode,
             null, item.Amount, item.BonusPlanDetailId, item.BonusSourceId,
             string.IsNullOrEmpty(item.Description) ?
                 (string.IsNullOrEmpty(item.BonusPlanHeader.Description) ? item.BonusPlanHeader.BonusPlanName : item.BonusPlanHeader.Description) :
                 item.Description);
     }
 }