예제 #1
0
 public FormDS.FormApplyExpenseDetailDataTable GetFormApplyExpenseDetail(int FormApplySKUDetailID)
 {
     FormDS.FormApplyExpenseDetailDataTable newExpense = new FormDS.FormApplyExpenseDetailDataTable();
     newExpense = (FormDS.FormApplyExpenseDetailDataTable)this.FormDataSet.FormApplyExpenseDetail.Clone();
     DataRow[] dr = this.FormDataSet.FormApplyExpenseDetail.Select("FormApplySKUDetailID = " + FormApplySKUDetailID.ToString());
     for (int i = 0; i < dr.Length; i++) {
         newExpense.ImportRow((DataRow)dr[i]);
     }
     return newExpense;//返回的查询结果
 }
예제 #2
0
        public void AddFormApply(int? RejectedFormID, int UserID, int? ProxyUserID, int? ProxyPositionID, int OrganizationUnitID, int PositionID, SystemEnums.FormType FormTypeID, SystemEnums.FormStatus StatusID,
                        DateTime BeginPeriod, DateTime EndPeriod, int CustomerID, int ShopID, int PaymentTypeID, int ExpenseSubCategoryID, string ContractNo, DateTime PromotionBeginDate, DateTime PromotionEndDate,
                        DateTime DeliveryBeginDate, DateTime DeliveryEndDate, int PromotionScopeID, int PromotionTypeID, string PromotionDesc, int ShelfTypeID, int? FirstVolume, int? SecondVolume, int? ThirdVolume,
                        decimal? CustomerBudget, decimal? CustomerBudgetRemain, decimal? OUBudget, decimal? OUAppovedAmount, decimal? OUApprovingAmount, decimal? OUCompletedAmount, decimal? OUReimbursedAmount, decimal? OUBudgetRemain, decimal? OUBudgetRate,
                        string AttachedFileName, string RealAttachedFileName, string Remark, int PromotionPriceType, int ReimburseRequirements, string FlowTemplate, string FormApplyName)
        {
            SqlTransaction transaction = null;

            try {
                ////事务开始
                transaction = TableAdapterHelper.BeginTransaction(this.TAForm);
                TableAdapterHelper.SetTransaction(this.TAFormApply, transaction);
                TableAdapterHelper.SetTransaction(this.TAFormApplySKUDetail, transaction);
                TableAdapterHelper.SetTransaction(this.TAFormApplyExpenseDetail, transaction);
                TableAdapterHelper.SetTransaction(this.TAFormApplySplitRate, transaction);

                //处理单据的内容
                FormDS.FormRow formRow = this.FormDataSet.Form.NewFormRow();
                if (RejectedFormID != null) {
                    formRow.RejectedFormID = RejectedFormID.GetValueOrDefault();
                }
                formRow.UserID = UserID;

                UtilityBLL utility = new UtilityBLL();
                if (StatusID == SystemEnums.FormStatus.Awaiting) {
                    string formTypeString = utility.GetFormTypeString((int)FormTypeID);
                    formRow.FormNo = utility.GetFormNo(formTypeString);
                } else {
                    formRow.SetFormNoNull();
                }

                if (ProxyUserID != null) {
                    formRow.ProxyUserID = ProxyUserID.GetValueOrDefault();
                }
                if (ProxyPositionID != null) {
                    formRow.ProxyPositionID = ProxyPositionID.GetValueOrDefault();
                }
                formRow.OrganizationUnitID = OrganizationUnitID;
                formRow.PositionID = PositionID;
                formRow.FormTypeID = (int)FormTypeID;
                formRow.StatusID = (int)StatusID;
                formRow.SubmitDate = DateTime.Now;
                formRow.LastModified = DateTime.Now;
                formRow.InTurnUserIds = "P";//待改动
                formRow.InTurnPositionIds = "P";//待改动
                formRow.PageType = (int)SystemEnums.PageType.PromotionApply;
                this.FormDataSet.Form.AddFormRow(formRow);
                this.TAForm.Update(formRow);

                //处理申请表的内容
                FormDS.FormApplyRow formApplyRow = this.FormDataSet.FormApply.NewFormApplyRow();
                formApplyRow.FormApplyID = formRow.FormID;
                formApplyRow.Period = DateTime.Parse(BeginPeriod.Year.ToString() + "-" + BeginPeriod.Month.ToString() + "-01");
                formApplyRow.BeginPeriod = DateTime.Parse(BeginPeriod.Year.ToString() + "-" + BeginPeriod.Month.ToString() + "-01");
                formApplyRow.EndPeriod = DateTime.Parse(EndPeriod.Year.ToString() + "-" + EndPeriod.Month.ToString() + "-01");
                formApplyRow.ShopID = ShopID;
                formApplyRow.CustomerID = CustomerID;
                formApplyRow.PaymentTypeID = PaymentTypeID;
                formApplyRow.ExpenseSubCategoryID = ExpenseSubCategoryID;
                if (ContractNo != "") {
                    formApplyRow.ContractNo = ContractNo;
                }
                formApplyRow.PromotionBeginDate = PromotionBeginDate;
                formApplyRow.PromotionEndDate = PromotionEndDate;
                formApplyRow.DeliveryBeginDate = DeliveryBeginDate;
                formApplyRow.DeliveryEndDate = DeliveryEndDate;
                formApplyRow.PromotionScopeID = PromotionScopeID;
                formApplyRow.PromotionTypeID = PromotionTypeID;
                if (PromotionDesc != "") {
                    formApplyRow.PromotionDesc = PromotionDesc;
                }
                formApplyRow.ShelfTypeID = ShelfTypeID;
                if (FirstVolume != null) {
                    formApplyRow.FirstVolume = FirstVolume.GetValueOrDefault();
                }
                if (SecondVolume != null) {
                    formApplyRow.SecondVolume = SecondVolume.GetValueOrDefault();
                }
                if (ThirdVolume != null) {
                    formApplyRow.ThirdVolume = ThirdVolume.GetValueOrDefault();
                }
                if (CustomerBudget != null) {
                    formApplyRow.CustomerBudget = CustomerBudget.GetValueOrDefault();
                }
                if (CustomerBudgetRemain != null) {
                    formApplyRow.CustomerBudgetRemain = CustomerBudgetRemain.GetValueOrDefault();
                }
                if (OUBudget != null) {
                    formApplyRow.OUBudget = OUBudget.GetValueOrDefault();
                }
                if (OUAppovedAmount != null) {
                    formApplyRow.OUAppovedAmount = OUAppovedAmount.GetValueOrDefault();
                }
                if (OUApprovingAmount != null) {
                    formApplyRow.OUApprovingAmount = OUApprovingAmount.GetValueOrDefault();
                }
                if (OUCompletedAmount != null) {
                    formApplyRow.OUCompletedAmount = OUCompletedAmount.GetValueOrDefault();
                }
                if (OUReimbursedAmount != null) {
                    formApplyRow.OUReimbursedAmount = OUReimbursedAmount.GetValueOrDefault();
                }
                if (OUBudgetRemain != null) {
                    formApplyRow.OUBudgetRemain = OUBudgetRemain.GetValueOrDefault();
                }
                if (OUBudgetRate != null) {
                    formApplyRow.OUBudgetRate = OUBudgetRate.GetValueOrDefault();
                }
                if (AttachedFileName != null && AttachedFileName != string.Empty) {
                    formApplyRow.AttachedFileName = AttachedFileName;
                }
                if (RealAttachedFileName != null && RealAttachedFileName != string.Empty) {
                    formApplyRow.RealAttachedFileName = RealAttachedFileName;
                }
                if (Remark != null && Remark != string.Empty) {
                    formApplyRow.Remark = Remark;
                }
                formApplyRow.FormApplyName = FormApplyName;
                formApplyRow.PromotionPriceType = PromotionPriceType;
                formApplyRow.ReimburseRequirements = ReimburseRequirements;

                formApplyRow.Amount = 0;//先赋默认值
                formApplyRow.IsClose = false;
                formApplyRow.IsComplete = false;
                formApplyRow.IsAutoSplit = false;
                this.FormDataSet.FormApply.AddFormApplyRow(formApplyRow);
                this.TAFormApply.Update(formApplyRow);

                //处理明细
                decimal totalAmount = 0;//计算总申请金额
                if (RejectedFormID != null) {
                    FormDS.FormApplyExpenseDetailDataTable newExpenseTable = new FormDS.FormApplyExpenseDetailDataTable();
                    foreach (FormDS.FormApplySKUDetailRow skuRow in this.FormDataSet.FormApplySKUDetail) {
                        if (skuRow.RowState != System.Data.DataRowState.Deleted) {
                            FormDS.FormApplySKUDetailDataTable newSKUTable = new FormDS.FormApplySKUDetailDataTable();
                            FormDS.FormApplySKUDetailRow newSKURow = newSKUTable.NewFormApplySKUDetailRow();
                            newSKURow.FormApplyID = formApplyRow.FormApplyID;
                            newSKURow.SKUID = skuRow.SKUID;
                            newSKURow.SupplyPrice = skuRow.SupplyPrice;
                            newSKURow.PromotionPrice = skuRow.PromotionPrice;
                            newSKURow.BuyQuantity = skuRow.BuyQuantity;
                            newSKURow.GiveQuantity = skuRow.GiveQuantity;
                            newSKURow.EstimatedSaleVolume = skuRow.EstimatedSaleVolume;
                            if (!skuRow.IsAmountNull()) {
                                newSKURow.Amount = skuRow.Amount;
                            }
                            if (!skuRow.IsRemarkNull()) {
                                newSKURow.Remark = skuRow.Remark;
                            }
                            newSKUTable.AddFormApplySKUDetailRow(newSKURow);
                            this.TAFormApplySKUDetail.Update(newSKUTable);
                            int newID = newSKURow.FormApplySKUDetailID;
                            FormDS.FormApplyExpenseDetailRow[] dr = (FormDS.FormApplyExpenseDetailRow[])this.FormDataSet.FormApplyExpenseDetail.Select("FormApplySKUDetailID = " + skuRow.FormApplySKUDetailID.ToString());
                            for (int i = 0; i < dr.Length; i++) {
                                FormDS.FormApplyExpenseDetailRow newExpenseRow = newExpenseTable.NewFormApplyExpenseDetailRow();
                                newExpenseRow.FormApplySKUDetailID = newID;
                                newExpenseRow.ExpenseItemID = dr[i].ExpenseItemID;
                                newExpenseRow.Amount = dr[i].Amount;
                                newExpenseRow.PackageUnitPrice = dr[i].PackageUnitPrice;
                                newExpenseRow.RepeatFormInfo = UtilityBLL.GenerateRepeatFormStr(this.TAForm.GetRepeatFormApplyNo(formApplyRow.PromotionBeginDate, formApplyRow.PromotionEndDate, newExpenseRow.ExpenseItemID, formApplyRow.ShopID, formApplyRow.FormApplyID));
                                newExpenseTable.AddFormApplyExpenseDetailRow(newExpenseRow);
                                if (dr[i].RowState != DataRowState.Deleted) {
                                    totalAmount += dr[i].Amount;
                                }
                            }
                        }
                    }
                    this.TAFormApplyExpenseDetail.Update(newExpenseTable);
                } else {
                    foreach (FormDS.FormApplySKUDetailRow skuRow in this.FormDataSet.FormApplySKUDetail) {
                        // 与父表绑定
                        if (skuRow.RowState != DataRowState.Deleted) {
                            skuRow.FormApplyID = formApplyRow.FormApplyID;
                            int oldID = skuRow.FormApplySKUDetailID;
                            this.TAFormApplySKUDetail.Update(skuRow);
                            int newID = skuRow.FormApplySKUDetailID;
                            FormDS.FormApplyExpenseDetailRow[] dr = (FormDS.FormApplyExpenseDetailRow[])this.FormDataSet.FormApplyExpenseDetail.Select("FormApplySKUDetailID = " + oldID.ToString());
                            for (int i = 0; i < dr.Length; i++) {
                                dr[i].FormApplySKUDetailID = newID;
                                dr[i].PackageUnitPrice = dr[i].Amount / skuRow.EstimatedSaleVolume;
                                if (dr[i].RowState != DataRowState.Deleted) {
                                    totalAmount += dr[i].Amount;
                                }
                                dr[i].RepeatFormInfo = UtilityBLL.GenerateRepeatFormStr(this.TAForm.GetRepeatFormApplyNo(formApplyRow.PromotionBeginDate, formApplyRow.PromotionEndDate, dr[i].ExpenseItemID, formApplyRow.ShopID, formApplyRow.FormApplyID));
                            }
                        }
                    }
                    this.TAFormApplyExpenseDetail.Update(this.FormDataSet.FormApplyExpenseDetail);
                }

                //分摊比例
                foreach (FormDS.FormApplySplitRateRow item in FormDataSet.FormApplySplitRate) {
                    item.FormApplyID = formApplyRow.FormApplyID;
                }
                this.TAFormApplySplitRate.Update(FormDataSet.FormApplySplitRate);

                formApplyRow.Amount = totalAmount;
                TAFormApply.Update(formApplyRow);

                // 正式提交或草稿

                Dictionary<string, object> dic = new Dictionary<string, object>();
                dic["Apply_Amount"] = totalAmount;
                //dic["Dept"] = new AuthorizationDSTableAdapters.OrganizationUnitTableAdapter().GetOrganizationUnitCodeByOrganizationUnitID(formRow.OrganizationUnitID)[0].OrganizationUnitCode;
                dic["Expense_Category"] = getExpenseCategoryIDByExpenseSubCategoryID(ExpenseSubCategoryID).ToString();//此处待改动(目前市场部的ID为7)
                APHelper AP = new APHelper();
                new APFlowBLL().ApplyForm(AP, TAForm, RejectedFormID, formRow, OrganizationUnitID, FlowTemplate, StatusID, dic);

                transaction.Commit();
            } catch (ApplicationException ex) {
                transaction.Rollback();
                throw ex;
            } catch (Exception ex) {
                transaction.Rollback();
                throw new ApplicationException("Save Fail!" + ex.ToString());
            } finally {
                transaction.Dispose();
            }
        }