Beispiel #1
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();
        }
Beispiel #2
0
        public static BonusPlanHeader SaveEditingPlan(long PId, string planName, string type, string status, string desc, DateTime fromDate, DateTime toDate)
        {
            var plan = DC.BonusPlanHeaders.SingleOrDefault(p => p.BonusPlanHeaderId == PId);
            var eitems = GetEditingItems(PId);
            var ditems = GetDeletingItems(PId);
            if (eitems.Count() > 0 || ditems.Count() > 0)
            {
                DC.BonusPlanDetails.AttachAll(ditems, false);
                DC.BonusPlanDetails.DeleteAllOnSubmit(ditems);
                if (plan == null)
                {
                    plan = new BonusPlanHeader();
                    plan.UserName = UserHelper.Username;
                    plan.CreatedDate = DateTime.Now;
                    plan.DatabaseCode = UserHelper.DatabaseCode == null ? "HTFDNF" : UserHelper.DatabaseCode;
                    DC.BonusPlanHeaders.InsertOnSubmit(plan);
                }
                plan.BonusPlanName = planName;
                plan.Description = desc;
                plan.FromDate = fromDate;
                if (toDate > DateTime.MinValue) plan.ToDate = toDate;
                plan.PlanType = type;
                if (PId == 0) plan.Status = status;

                foreach (var i in eitems)
                {
                    if (i.BonusPlanDetailId == 0)
                    {
                        i.BonusPlanHeader = plan;
                        DC.BonusPlanDetails.InsertOnSubmit(i);
                    }
                    else
                    {
                        var d = DC.BonusPlanDetails.SingleOrDefault(p => p.BonusPlanDetailId == i.BonusPlanDetailId);
                        if (d != null)
                        {
                            d.Amount = i.Amount;
                            d.BonusDate = i.BonusDate;
                            d.BonusPlanHeaderId = i.BonusPlanHeaderId;
                            d.BonusSourceId = i.BonusSourceId;
                            d.DealerCode = i.DealerCode;
                            d.Description = i.Description;
                            d.PlanType = i.PlanType;
                            d.Status = i.Status;
                            d.UserName = i.UserName;
                        }
                    }
                }

                DC.SubmitChanges();
                return plan;
            }
            else return null;
        }