protected void NextButton_Click(object sender, EventArgs e) { string startPeriod = ((TextBox)(this.UCPeriodBegin.FindControl("txtDate"))).Text.Trim(); string endPeriod = ((TextBox)(this.UCPeriodEnd.FindControl("txtDate"))).Text.Trim(); if (startPeriod == string.Empty) { PageUtility.ShowModelDlg(this, "请选择起始费用期间!"); return; } if (endPeriod == string.Empty) { PageUtility.ShowModelDlg(this, "请选择截止费用期间!"); return; } DateTime dtstartPeriod = DateTime.Parse(startPeriod.Substring(0, 4) + "-" + startPeriod.Substring(4, 2) + "-01"); DateTime dtendPeriod = DateTime.Parse(endPeriod.Substring(0, 4) + "-" + endPeriod.Substring(4, 2) + "-01"); if (dtstartPeriod > dtendPeriod) { PageUtility.ShowModelDlg(this, "起始费用期间大于截止费用期间!"); return; } MasterDataBLL bll = new MasterDataBLL(); if (dtstartPeriod.AddMonths(-3).Year != dtendPeriod.AddMonths(-3).Year) { PageUtility.ShowModelDlg(this, "起始和截止费用期间必须在同一财年内!"); return; } if (!bll.IsValidApplyYear(dtstartPeriod.AddMonths(-3).Year)) { PageUtility.ShowModelDlg(this, "不允许申请本财年项目,请联系财务部!"); return; } if (this.CustomerDDL.SelectedValue == null || this.CustomerDDL.SelectedValue == string.Empty) { PageUtility.ShowModelDlg(this, "请选择客户!"); return; } if (this.SubCategoryDDL.SelectedValue == "0") { PageUtility.ShowModelDlg(this, "请选择费用小类!"); return; } ERS.ExpenseSubCategoryRow subCategory = bll.GetExpenseSubCategoryById(int.Parse(this.SubCategoryDDL.SelectedValue)); //检查如果是返利,只能填写一个月的 if (subCategory.PageType == (int)SystemEnums.PageType.RebateApply) { if (dtstartPeriod.Year != dtendPeriod.Year || dtstartPeriod.Month != dtendPeriod.Month) { PageUtility.ShowModelDlg(this, "返利申请不能跨月!"); return; } if (new SalesApplyBLL().GetRebateApplyCountByParameter(int.Parse(this.CustomerDDL.SelectedValue), dtstartPeriod.Year, dtstartPeriod.Month, int.Parse(this.SubCategoryDDL.SelectedValue)) > 0) { PageUtility.ShowModelDlg(this, "系统中已经存在该客户的返利申请,返利申请每月只能申请一次!"); return; } } switch (subCategory.PageType) { case (int)SystemEnums.PageType.PromotionApply: this.Response.Redirect("~/SalesForm/SalesPromotionApply.aspx?CustomerID=" + this.CustomerDDL.SelectedValue + "&ExpenseSubCategoryID=" + this.SubCategoryDDL.SelectedValue + "&BeginPeriod=" + dtstartPeriod.ToShortDateString() + "&EndPeriod=" + dtendPeriod.ToShortDateString() + "&PromotionPriceType=" + this.PromotionPriceTypeDDL.SelectedValue); break; case (int)SystemEnums.PageType.GeneralApply: this.Response.Redirect("~/SalesForm/SalesGeneralApply.aspx?CustomerID=" + this.CustomerDDL.SelectedValue + "&ExpenseSubCategoryID=" + this.SubCategoryDDL.SelectedValue + "&BeginPeriod=" + dtstartPeriod.ToShortDateString() + "&EndPeriod=" + dtendPeriod.ToShortDateString()); break; case (int)SystemEnums.PageType.RebateApply: this.Response.Redirect("~/SalesForm/SalesRebateApply.aspx?CustomerID=" + this.CustomerDDL.SelectedValue + "&ExpenseSubCategoryID=" + this.SubCategoryDDL.SelectedValue + "&BeginPeriod=" + dtstartPeriod.ToShortDateString() + "&EndPeriod=" + dtendPeriod.ToShortDateString()); break; } }
//protected void gvApplyList_PageIndexChanging(object sender, GridViewPageEventArgs e) { // this.ViewState["CheckedFormIds"] = this.GetCheckedFormIds(); //} //protected void gvApplyList_DataBound(object sender, EventArgs e) { // List<int> checkedFormIds = (List<int>)this.ViewState["CheckedFormIds"]; // if (checkedFormIds == null) { // checkedFormIds = new List<int>(); // } // foreach (GridViewRow gridViewRow in this.gvApplyList.Rows) { // if (gridViewRow.RowType == DataControlRowType.DataRow) { // int FormId = (int)this.gvApplyList.DataKeys[gridViewRow.RowIndex].Value; // CheckBox checkCtl = (CheckBox)gridViewRow.FindControl("CheckCtl"); // if (checkedFormIds.Contains(FormId)) { // checkCtl.Checked = true; // } else { // checkCtl.Checked = false; // } // } // } //} //private List<int> GetCheckedFormIds() { // List<int> checkedFormIds = (List<int>)this.ViewState["CheckedFormIds"]; // if (checkedFormIds == null) { // checkedFormIds = new List<int>(); // } // foreach (GridViewRow gridViewRow in this.gvApplyList.Rows) { // if (gridViewRow.RowType == DataControlRowType.DataRow) { // int FormId = (int)this.gvApplyList.DataKeys[gridViewRow.RowIndex].Value; // CheckBox checkCtl = (CheckBox)gridViewRow.FindControl("CheckCtl"); // if (checkCtl.Checked) { // if (!checkedFormIds.Contains(FormId)) { // checkedFormIds.Add(FormId); // } // } else { // if (checkedFormIds.Contains(FormId)) { // checkedFormIds.Remove(FormId); // } // } // } // } // return checkedFormIds; //} protected void CreateBtn_Click(object sender, EventArgs e) { string strFormID = string.Empty; string strFormNo = string.Empty; bool isSameCustID = true; bool isSamePaymentType = true; bool isSameYear = true; bool isSameCategory = true; int paymentTypeID = 0; int custID = 0; int year = 0; int categoryID = 0; MasterDataBLL masterBLL = new MasterDataBLL(); string intFormID = string.Empty; foreach (GridViewRow row in this.gvApplyList.Rows) { CheckBox CheckCtl = (CheckBox)row.FindControl("CheckCtl"); if (CheckCtl.Checked) { FormDS.FormApplyRow formApply = new SalesApplyBLL().GetFormApplyByID((int)this.gvApplyList.DataKeys[row.RowIndex].Value)[0]; FormDS.FormRow form = new SalesApplyBLL().GetFormByID((int)this.gvApplyList.DataKeys[row.RowIndex].Value)[0]; intFormID = formApply.FormApplyID.ToString(); if (custID == 0) { custID = formApply.CustomerID; } else { if (custID != formApply.CustomerID) { isSameCustID = false; break; } } if (paymentTypeID == 0) { paymentTypeID = formApply.PaymentTypeID; } else { if (paymentTypeID != formApply.PaymentTypeID) { isSamePaymentType = false; break; } } if (year == 0) { year = formApply.Period.AddMonths(-3).Year; } else { if (year != formApply.Period.AddMonths(-3).Year) { isSameYear = false; break; } } if (categoryID == 0) { categoryID = masterBLL.GetExpenseSubCategoryById(formApply.ExpenseSubCategoryID).ExpenseCategoryID; } else { if (categoryID != masterBLL.GetExpenseSubCategoryById(formApply.ExpenseSubCategoryID).ExpenseCategoryID) { isSameCategory = false; break; } } if (strFormID == string.Empty) { strFormID = this.gvApplyList.DataKeys[row.RowIndex].Value.ToString(); } else { strFormID = strFormID + "," + this.gvApplyList.DataKeys[row.RowIndex].Value.ToString(); } if (strFormNo == string.Empty) { strFormNo = "P" + form.FormNo + "P"; } else { strFormNo = strFormNo + "P" + form.FormNo + "P";; } } } if (strFormID == string.Empty) { PageUtility.ShowModelDlg(this, "请选择申请单!"); return; } if (!isSameCustID) { PageUtility.ShowModelDlg(this, "请选择相同客户的申请单!"); return; } if (!isSamePaymentType) { PageUtility.ShowModelDlg(this, "请选择相同支付方式的申请单!"); return; } if (!isSameYear) { PageUtility.ShowModelDlg(this, "请选择同一年的申请单!"); return; } if (!isSameCategory) { PageUtility.ShowModelDlg(this, "请选择同一费用大类的申请单!"); return; } string url = string.Empty; if (paymentTypeID == (int)SystemEnums.PaymentType.ShiWu) { //如果支付方式是实物,那么只能对应一张申请单 if (strFormID.Contains(",")) { PageUtility.ShowModelDlg(this, "实物报销只能对应一张申请单!"); return; } //如果有多个费用项,不能报销 if (new SalesReimburseBLL().QueryExpenseItemCountByReimburseID(int.Parse(strFormID)) > 1) { PageUtility.ShowModelDlg(this, "实物报销对应申请单只能有一个费用项!"); return; } if (this.ViewState["SearchCondition"] != null) { url = "~/SalesForm/ReimburseGoodsApply.aspx?FormApplyIds=" + strFormID + "&CustomerID=" + custID.ToString() + "&PaymentTypeID=" + paymentTypeID.ToString() + "&FormApplyNos=" + strFormNo + "&Source=" + HttpUtility.UrlEncode("~/SalesForm/FormApplySelectList.aspx?" + this.ViewState["SearchCondition"].ToString()); } else { url = "~/SalesForm/ReimburseGoodsApply.aspx?FormApplyIds=" + strFormID + "&CustomerID=" + custID.ToString() + "&PaymentTypeID=" + paymentTypeID.ToString() + "&FormApplyNos=" + strFormNo + "&Source=" + HttpUtility.UrlEncode("~/SalesForm/FormApplySelectList.aspx"); } } else { if (this.ViewState["SearchCondition"] != null) { url = "~/SalesForm/ReimburseMoneyApply.aspx?FormApplyIds=" + strFormID + "&CustomerID=" + custID.ToString() + "&PaymentTypeID=" + paymentTypeID.ToString() + "&FormApplyNos=" + strFormNo + "&Source=" + HttpUtility.UrlEncode("~/SalesForm/FormApplySelectList.aspx?" + this.ViewState["SearchCondition"].ToString()); } else { url = "~/SalesForm/ReimburseMoneyApply.aspx?FormApplyIds=" + strFormID + "&CustomerID=" + custID.ToString() + "&PaymentTypeID=" + paymentTypeID.ToString() + "&FormApplyNos=" + strFormNo + "&Source=" + HttpUtility.UrlEncode("~/SalesForm/FormApplySelectList.aspx"); } } Response.Redirect(url); }