Example #1
0
    public XmlDocument GetApprovalInfoByFormID(int FormID)
    {
        MasterData myDS = new MasterData();
        MasterData.ApprovalInfoDataTable tbApprovalInfo = myDS.ApprovalInfo;
        AuthorizationDS.PositionDataTable tbPosition = null;
        int index = 1;

        AuthorizationBLL authBLL = new AuthorizationBLL();
        OUTreeBLL ouBLL = new OUTreeBLL();

        MasterData.ApprovalInfoRow rowApprovalInfo = tbApprovalInfo.NewApprovalInfoRow();

        FormDS.FormRow rowForm = new FormSaleBLL().GetFormByID(FormID)[0];
        rowApprovalInfo.ApprovalInfoID = index++;
        rowApprovalInfo.StuffName = authBLL.GetStuffUserById(rowForm.UserID).StuffName;
        rowApprovalInfo.ApprovalDate = rowForm.SubmitDate.ToString("yyyy-MM-dd HH:mm");
        rowApprovalInfo.Position = ouBLL.GetPositionById(rowForm.PositionID).PositionName;
        rowApprovalInfo.Comment = "";
        rowApprovalInfo.Status = "Submit";
        tbApprovalInfo.AddApprovalInfoRow(rowApprovalInfo);

        if (!rowForm.IsProcIDNull()) {
            APWorkFlow.NodeStatusDataTable nodeTable = new APHelper().getApprovalStatus(rowForm.ProcID);
            foreach (APWorkFlow.NodeStatusRow item in nodeTable) {
                if ((!item.IsSTATUSNull()) && item.STATUS != "ASSIGNED") {
                    rowApprovalInfo = tbApprovalInfo.NewApprovalInfoRow();
                    item.PARTICIPANT = item.PARTICIPANT.Replace("PP", "P");
                    rowApprovalInfo.ApprovalInfoID = index++;
                    int i = 0;
                    foreach (var userid in item.PARTICIPANT.Split('$')[0].Split('P')) {

                        if ((!string.IsNullOrEmpty(userid)) && authBLL.GetStuffUserById(int.Parse(userid)).StuffName.Trim().Equals(item.APPROVED_BY)) {
                            tbPosition = ouBLL.GetPositionsByID(int.Parse(item.PARTICIPANT.Split('$')[1].Split('P')[i]));
                            rowApprovalInfo.Position = tbPosition.Count > 0 ? tbPosition[0].PositionName : "";
                            break;
                        }
                        i++;
                    }
                    rowApprovalInfo.StuffName = item.APPROVED_BY;
                    rowApprovalInfo.ApprovalDate = item.IsCOMPLETED_DATENull() ? "" : item.COMPLETED_DATE;

                    rowApprovalInfo.Comment = item.IsCOMMENTSNull() ? "" : item.COMMENTS;
                    rowApprovalInfo.Status = item.IsSTATUSNull() ? "" : item.STATUS;
                    tbApprovalInfo.AddApprovalInfoRow(rowApprovalInfo);
                }
            }
        }

        return new XmlDataDocument(myDS);
    }
 public string GetApplyRemark(object FormSaleExpenseDetailID)
 {
     if (FormSaleExpenseDetailID.ToString() != string.Empty) {
         int id = Convert.ToInt32(FormSaleExpenseDetailID);
         FormDS.FormSaleExpenseDetailRow row = new FormSaleBLL().GetFormSaleExpenseDetailByID(id);
         if (row.IsRemarkNull()) {
             return null;
         } else {
             return row.Remark;
         }
     } else {
         return null;
     }
 }
Example #3
0
 public static bool CheckPeriod(int FormID)
 {
     FormDS.FormRow rowForm = new FormSaleBLL().GetFormByID(FormID)[0];
     DateTime Period = DateTime.Now;
     switch (rowForm.FormTypeID) {
         case (int)SystemEnums.FormType.FormMarketingApply:
             Period = new FormMarketingBLL().GetFormMarketingApplyByID(rowForm.FormID)[0].FPeriod;
             break;
         case (int)SystemEnums.FormType.RDApply:
             Period = new FormRDBLL().GetFormRDApplyByID(rowForm.FormID)[0].FPeriod;
             break;
         case (int)SystemEnums.FormType.SaleApply:
             Period = new FormSaleBLL().GetFormSaleApplyByID(rowForm.FormID)[0].FPeriod;
             break;
     }
     MasterData.PeriodSaleDataTable tbPeriodSale = new MasterDataBLL().GetPeriodSale();
     foreach (var rowPeriodSale in tbPeriodSale) {
         if (rowPeriodSale.PeriodSale == Period) {
             return false;
         }
     }
     return true;
 }
Example #4
0
    protected void btnGenearate_Click(object sender, EventArgs e)
    {
        FormSaleBLL saleBLL = new FormSaleBLL();
        FormDS.FormDataTable tbForm = null;

        string FormNoStr = this.txtFormNo.Text;
        if (!string.IsNullOrEmpty(FormNoStr)) {
            string[] FormNos = FormNoStr.Split(',');
            if (FormNos.Length > 0) {
                foreach (string FormNo in FormNos) {
                    tbForm = saleBLL.GetDataByFormNo(FormNo);
                    if (tbForm != null && tbForm.Count > 0) {
                        try {
                            saleBLL.GenerateSettlement(tbForm[0].FormID);
                            this.lblError.Text += "申请单"+FormNo+ "生成结案单成功,结案单号为<br />";
                        } catch (Exception) {
                            this.lblError.Text+=e.ToString()+"<br />";
                            throw;
                        }
                    }
                }
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        if (!this.IsPostBack) {
            String title = this.GetLocalResourceObject("titleLabel.Text").ToString();
            PageUtility.SetContentTitle(this.Page, title);

            MasterDataBLL mdBLL = new MasterDataBLL();
            int formID = int.Parse(Request["ObjectId"]);
            this.ViewState["ObjectId"] = formID;
            FormDS.FormSalePaymentRow rowFormPayment = this.FormSaleBLL.GetFormSalePaymentByID(int.Parse(this.ViewState["ObjectId"].ToString()));

            FormDS.FormRow rowForm = this.FormSaleBLL.GetFormByID(formID)[0];
            if (rowForm.IsProcIDNull()) {
                ViewState["ProcID"] = "";
            } else {
                ViewState["ProcID"] = rowForm.ProcID;
            }

            this.FormNoCtl.Text = rowForm.FormNo;
            AuthorizationDS.StuffUserRow applicant = new AuthorizationBLL().GetStuffUserById(rowForm.UserID);
            this.StuffNameCtl.Text = CommonUtility.GetStaffFullName(applicant);
            this.PositionNameCtl.Text = new OUTreeBLL().GetPositionById(rowForm.PositionID).PositionName;
            if (new OUTreeBLL().GetOrganizationUnitById(rowForm.OrganizationUnitID) != null) {
                this.DepartmentNameCtl.Text = new OUTreeBLL().GetOrganizationUnitById(rowForm.OrganizationUnitID).OrganizationUnitName;
            }
            this.AttendDateCtl.Text = applicant.AttendDate.ToShortDateString();

            FormDS.FormSaleSettlementRow rowFormSettlement = this.FormSaleBLL.GetFormSaleSettlementByID(rowFormPayment.FormSaleSettlementID);
            FormDS.FormRow settlementForm = this.FormSaleBLL.GetFormByID(rowFormPayment.FormSaleSettlementID)[0];

            MasterData.CustomerRow customer = mdBLL.GetCustomerById(rowFormSettlement.CustomerID)[0];
            this.CustomerNameCtl.Text = customer.CustomerName;
            this.CustomerChannelCtl.Text = mdBLL.GetCustomerChannelById(customer.CustomerChannelID)[0].CustomerChannelName;
            this.CustomerRegionCtl.Text = mdBLL.GetCustomerRegionById(customer.CustomerRegionID).CustomerRegionName;
            this.CityCtl.Text = customer.City;
            this.BrandCtl.Text = mdBLL.GetBrandById(rowFormSettlement.BrandID)[0].BrandName;
            MasterData.ExpenseSubCategoryRow rowExpenseSubCategory = mdBLL.GetExpenseSubCategoryById(rowFormSettlement.ExpenseSubCategoryID);
            this.ExpenseCategoryCtl.Text = mdBLL.GetExpenseCategoryById(rowExpenseSubCategory.ExpenseCategoryID).ExpenseCategoryName;
            this.ExpenseSubCategoryCtl.Text = rowExpenseSubCategory.ExpenseSubCategoryName;
            this.CurrencyCtl.Text = mdBLL.GetCurrencyByID(rowFormSettlement.CurrencyID).CurrencyShortName;
            this.CostCenterCtl.Text = CommonUtility.GetMAACostCenterFullName(rowForm.CostCenterID);

            this.SettlementRemarkCtl.Text = rowFormSettlement.IsRemarkNull() ? "" : rowFormSettlement.Remark;
            if (!rowFormSettlement.IsAttachedFileNameNull())
                this.UCSettlementFile.AttachmentFileName = rowFormSettlement.AttachedFileName;
            if (!rowFormSettlement.IsRealAttachedFileNameNull())
                this.UCSettlementFile.RealAttachmentFileName = rowFormSettlement.RealAttachedFileName;

            if (!rowFormPayment.IsRemarkNull()) {
                this.RemarkCtl.Text = rowFormPayment.Remark;
            }
            if (!rowFormPayment.IsAttachedFileNameNull()) {
                this.UCPaymentFile.AttachmentFileName = rowFormPayment.AttachedFileName;
            }
            if (!rowFormPayment.IsRealAttachedFileNameNull()) {
                this.UCPaymentFile.RealAttachmentFileName = rowFormPayment.RealAttachedFileName;
            }
            this.PaymentTypeCtl.Text = new MasterDataBLL().GetPaymentTypeById(rowFormPayment.PaymentTypeID).PaymentTypeName;
            if (!rowFormPayment.IsVendorIDNull()) {
                MasterData.VendorRow vendor = new MasterDataBLL().GetVendorByID(rowFormPayment.VendorID);
                this.VendorCtl.Text = vendor.VendorName + "-" + vendor.VendorCode;
            }

            this.SettlementFormNoCtl.Text = settlementForm.FormNo;
            this.SettlementFormNoCtl.NavigateUrl = "javascript:window.showModalDialog('" + System.Configuration.ConfigurationManager.AppSettings["WebSiteUrl"] + "/FormSale/SettlementApproval.aspx?ShowDialog=1&ObjectId=" + rowFormPayment.FormSaleSettlementID + "','', 'dialogWidth:1000px;dialogHeight:750px;resizable:yes;')";

            //历史单据
            if (rowForm.IsRejectedFormIDNull()) {
                lblRejectFormNo.Text = "无";
            } else {
                FormDS.FormRow rejectedForm = this.FormSaleBLL.GetFormByID(rowForm.RejectedFormID)[0];
                this.lblRejectFormNo.Text = rejectedForm.FormNo;
                this.lblRejectFormNo.NavigateUrl = "javascript:window.showModalDialog('" + System.Configuration.ConfigurationManager.AppSettings["WebSiteUrl"] + "/FormSale/PaymentFreeGoodsApproval.aspx?ShowDialog=1&ObjectId=" + rejectedForm.FormID + "','', 'dialogWidth:1000px;dialogHeight:750px;resizable:yes;')";
            }

            //费用合计信息
            ApplyAmountRMBCtl.Text = rowFormSettlement.IsApplyAmountRMBNull() ? "" : rowFormSettlement.ApplyAmountRMB.ToString();
            ForecastOrderAmountCtl.Text = rowFormSettlement.IsForecastOrderAmountNull() ? "" : rowFormSettlement.ForecastOrderAmount.ToString();
            CostBenefitRateCtl.Text = rowFormSettlement.IsCostBenefitRateNull() ? "" : rowFormSettlement.CostBenefitRate.ToString();
            AmountRMBCtl.Text = rowFormSettlement.AmountRMB.ToString();
            ActualOrderAmountCtl.Text = rowFormSettlement.IsActualOrderAmountNull() ? "" : rowFormSettlement.ActualOrderAmount.ToString();
            ActualCostBenefitRateCtl.Text = rowFormSettlement.IsActualCostBenefitRateNull() ? "" : rowFormSettlement.ActualCostBenefitRate.ToString();

            //判断是Activity还是NoActivity,如果NoActivity那么需要隐藏
            if (settlementForm.PageType == (int)SystemEnums.PageType.NoActivitySettlementApply) {
                this.FeeSumTR.Visible = false;
                this.SKUDiv.Visible = false;
                this.gvSKUDetails.Visible = false;
            }

            //明细
            this.odsFreeGoods.SelectParameters["FormSalePaymentID"].DefaultValue = rowFormPayment.FormSalePaymentID.ToString();
            this.odsSKUDetails.SelectParameters["FormSaleSettlementID"].DefaultValue = rowFormPayment.FormSaleSettlementID.ToString();
            this.odsPaymentDetails.SelectParameters["FormSalePaymentID"].DefaultValue = rowFormPayment.FormSalePaymentID.ToString();

            //审批页面处理&按钮处理
            AuthorizationDS.StuffUserRow stuffUser = (AuthorizationDS.StuffUserRow)Session["StuffUser"];
            this.ViewState["StuffUserID"] = stuffUser.StuffUserId;
            if (rowForm.InTurnUserIds.Contains("P" + stuffUser.StuffUserId + "P")) {
                this.SubmitBtn.Visible = true;
                this.cwfAppCheck.IsView = false;
                this.ViewState["IsView"] = false;
            } else {
                this.SubmitBtn.Visible = false;
                this.cwfAppCheck.IsView = true;
                this.ViewState["IsView"] = true;
            }

            if (rowForm.StatusID == (int)SystemEnums.FormStatus.Rejected && stuffUser.StuffUserId == rowForm.UserID) {
                this.EditBtn.Visible = true;
                this.ScrapBtn.Visible = true;
            } else {
                this.EditBtn.Visible = false;
                this.ScrapBtn.Visible = false;
            }

            //如果是弹出,取消按钮不可见
            if (this.Request["ShowDialog"] != null) {
                if (this.Request["ShowDialog"].ToString() == "1") {
                    this.upButton.Visible = false;
                    this.Master.FindControl("divMenu").Visible = false;
                    this.Master.FindControl("tbCurrentPage").Visible = false;
                }
            }
            //单据打印
            this.ucPrint.FormID = rowForm.FormID;

            FormDS.FormDeliveryGoodsDataTable tbDelivery= new FormSaleBLL().GetFormDeliveryGoodByFormID(formID);
            if (tbDelivery.Count > 0) {
                this.gvDeliveryInfo.DataSource = tbDelivery;
                this.gvDeliveryInfo.DataBind();
            } else {
                this.divDeliveryInfo.Visible = false;
                this.gvDeliveryInfo.Visible = false;
            }

            //发货完成按钮权限
            int opManageId = BusinessUtility.GetBusinessOperateId(SystemEnums.BusinessUseCase.DeliveryComplete, SystemEnums.OperateEnum.Other);
            AuthorizationDS.PositionRow position = (AuthorizationDS.PositionRow)this.Session["Position"];
            PositionRightBLL positionRightBLL = new PositionRightBLL();
            if (positionRightBLL.CheckPositionRight(position.PositionId, opManageId) && (rowFormPayment.IsIsDeliveryCompleteNull() || rowFormPayment.IsDeliveryComplete == false)) {
                this.DeliveryCompleteBtn.Visible = false;
            }
        }
        this.cwfAppCheck.FormID = (int)this.ViewState["ObjectId"];
        this.cwfAppCheck.ProcID = this.ViewState["ProcID"].ToString();
        this.cwfAppCheck.IsView = (bool)this.ViewState["IsView"];
    }
    protected void CreateBtn_Click(object sender, EventArgs e)
    {
        string strFormID = string.Empty;
        string strFormNo = string.Empty;
        bool isSameCustID = true;
        bool isSameBrandID = true;
        bool isSameYear = true;
        bool isSameSubCategoryID = true;
        bool isSameCurrencyID = true;
        bool isSameCostCenter = true;
        int custID = 0;
        int brandID = 0;
        int year = 0;
        int subCategoryID = 0;
        int currencyID = 0;
        int pageType = 0;
        decimal NeedCreatePOAmount = Convert.ToDecimal(ConfigurationManager.AppSettings["NeedCreatePOAmount"]);
        int costCenterID = 0;
        String NeedPOFormNo = string.Empty;

        MasterDataBLL masterBLL = new MasterDataBLL();
        FormPurchaseBLL purchaseBLL = new FormPurchaseBLL();
        string intFormID = string.Empty;
        foreach (GridViewRow row in this.gvApplyList.Rows) {
            CheckBox CheckCtl = (CheckBox)row.FindControl("CheckCtl");
            if (CheckCtl.Checked) {
                QueryDS.FormSaleApplyViewRow formApply = new FormQueryBLL().GetFormSaleApplyViewByID((int)this.gvApplyList.DataKeys[row.RowIndex].Value);
                FormDS.FormRow form = new FormSaleBLL().GetFormByID((int)this.gvApplyList.DataKeys[row.RowIndex].Value)[0];
                intFormID = formApply.FormID.ToString();
                pageType = formApply.PageType;
                if (custID == 0) {
                    custID = formApply.CustomerID;
                } else {
                    if (custID != formApply.CustomerID) {
                        isSameCustID = false;
                        break;
                    }
                }
                if (brandID == 0) {
                    brandID = formApply.BrandID;
                } else {
                    if (brandID != formApply.BrandID) {
                        isSameBrandID = false;
                        break;
                    }
                }
                if (year == 0) {
                    year = formApply.FPeriod.AddMonths(5).Year;
                } else {
                    if (year != formApply.FPeriod.AddMonths(5).Year) {
                        isSameYear = false;
                        break;
                    }
                }
                if (subCategoryID == 0) {
                    subCategoryID = formApply.ExpenseSubCategoryID;
                } else {
                    if (subCategoryID != formApply.ExpenseSubCategoryID) {
                        isSameSubCategoryID = false;
                        break;
                    }
                }
                if (currencyID == 0) {
                    currencyID = formApply.CurrencyID;
                } else {
                    if (currencyID != formApply.CurrencyID) {
                        isSameCurrencyID = 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 (costCenterID == 0) {
                    costCenterID = formApply.CostCenterID;
                } else {
                    if (costCenterID != formApply.CostCenterID) {
                        isSameCostCenter = false;
                        break;
                    }
                }

                //�жϽ�����X����Ҫ�½�PO
                MasterData.ExpenseCategoryRow ecr = masterBLL.GetExpenseCategoryById(masterBLL.GetExpenseSubCategoryById(formApply.ExpenseSubCategoryID).ExpenseCategoryID);
                if (formApply.AmountRMB > NeedCreatePOAmount && ecr.NeedPO) {
                    if (purchaseBLL.QueryPOCountByParentFormID(formApply.FormID) <= 0) {
                        NeedPOFormNo += formApply.FormNo + ",";
                    }
                }
            }
        }

        if (strFormID == string.Empty) {
            PageUtility.ShowModelDlg(this, "��ѡ�����뵥!");
            return;
        }

        if (!isSameCustID) {
            PageUtility.ShowModelDlg(this, "��ѡ����ͬ�ͻ������뵥!");
            return;
        }
        if (!isSameBrandID) {
            PageUtility.ShowModelDlg(this, "��ѡ����ͬBrand�����뵥!");
            return;
        }
        if (!isSameYear) {
            PageUtility.ShowModelDlg(this, "��ѡ��ͬһ������뵥!");
            return;
        }
        if (!isSameSubCategoryID) {
            PageUtility.ShowModelDlg(this, "��ѡ��ͬһ����С������뵥!");
            return;
        }
        if (!isSameCurrencyID) {
            PageUtility.ShowModelDlg(this, "��ѡ��ͬһ���ֵ����뵥!");
            return;
        }
        if (!isSameCostCenter) {
            PageUtility.ShowModelDlg(this, "��ѡ��ͬһ�ɱ����ĵ����뵥!");
            return;
        }
        if (NeedPOFormNo != string.Empty) {
            PageUtility.ShowModelDlg(this, string.Format("���뵥{0}������{1}����Ҫ����PO��", NeedPOFormNo, NeedCreatePOAmount));
            return;
        }

        string url = string.Empty;

        if (pageType == (int)SystemEnums.PageType.ActivityApply) {
            if (this.ViewState["SearchCondition"] != null) {
                url = "~/FormSale/ActivitySettlementApply.aspx?FormApplyIds=" + strFormID +
                     "&CustomerID=" + custID.ToString() + "&BrandID=" + brandID.ToString() + "&ExpenseSubCategoryID=" + subCategoryID + "&CurrencyID=" + currencyID+"&CostCenterID="+costCenterID + "&FormApplyNos=" + strFormNo + "&Source=" + HttpUtility.UrlEncode("~/FormSale/SaleApplySelectList.aspx?" + this.ViewState["SearchCondition"].ToString());
            } else {
                url = "~/FormSale/ActivitySettlementApply.aspx?FormApplyIds=" + strFormID +
                     "&CustomerID=" + custID.ToString() + "&BrandID=" + brandID.ToString() + "&ExpenseSubCategoryID=" + subCategoryID + "&CurrencyID=" + currencyID + "&CostCenterID=" + costCenterID + "&FormApplyNos=" + strFormNo + "&Source=" + HttpUtility.UrlEncode("~/FormSale/SaleApplySelectList.aspx");
            }
        } else {
            if (this.ViewState["SearchCondition"] != null) {
                url = "~/FormSale/NoActivitySettlementApply.aspx?FormApplyIds=" + strFormID +
                     "&CustomerID=" + custID.ToString() + "&BrandID=" + brandID.ToString() + "&ExpenseSubCategoryID=" + subCategoryID + "&CurrencyID=" + currencyID + "&CostCenterID=" + costCenterID + "&FormApplyNos=" + strFormNo + "&Source=" + HttpUtility.UrlEncode("~/FormSale/SaleApplySelectList.aspx?" + this.ViewState["SearchCondition"].ToString());
            } else {
                url = "~/FormSale/NoActivitySettlementApply.aspx?FormApplyIds=" + strFormID +
                     "&CustomerID=" + custID.ToString() + "&BrandID=" + brandID.ToString() + "&ExpenseSubCategoryID=" + subCategoryID + "&CurrencyID=" + currencyID + "&CostCenterID=" + costCenterID + "&FormApplyNos=" + strFormNo + "&Source=" + HttpUtility.UrlEncode("~/FormSale/SaleApplySelectList.aspx");
            }
        }
        Response.Redirect(url);
    }
Example #7
0
 public void AddFormInvoice(int? FormID, string InvoiceNo, DateTime InvoiceDate, decimal InvoiceAmount, string Remark)
 {
     PurchaseDS.FormInvoiceRow rowDetail = this.PurchaseDataSet.FormInvoice.NewFormInvoiceRow();
     rowDetail.FormID = FormID.GetValueOrDefault();
     rowDetail.InvoiceNo = InvoiceNo;
     rowDetail.InvoiceDate = InvoiceDate;
     rowDetail.InvoiceAmount = InvoiceAmount;
     rowDetail.Remark = Remark;
     string systemInfo = new FormSaleBLL().GetRepeatedInvoiceFormNosByInvioceNo(InvoiceNo);
     if (systemInfo != string.Empty) {
         rowDetail.SystemInfo = "发票号码重复,报销单编号为:" + systemInfo;
     }
     // 填加行并进行更新处理
     this.PurchaseDataSet.FormInvoice.AddFormInvoiceRow(rowDetail);
 }
Example #8
0
    protected void gvApplyList_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "scrap") {
            int FormID = Int32.Parse(e.CommandArgument.ToString());
            QueryDS.FormSaleApplyViewRow row = new FormQueryBLL().GetFormSaleApplyViewByID(FormID);

            string SettledFormNo = new FormSaleBLL().GetSettledFormNoBySaleApplyID(row.FormID);
            if (SettledFormNo != "") {
                PageUtility.ShowModelDlg(this.Page, "���뵥�Ѿ����᰸�����᰸�����Ϊ��" + SettledFormNo);
                return;
            }
            string PaymentFormNo = new FormSaleBLL().GetPaymentFormNoBySaleApplyID(row.FormID);
            if (PaymentFormNo != "") {
                PageUtility.ShowModelDlg(this.Page, "���뵥�Ѿ����������������Ϊ��" + PaymentFormNo);
                return;
            }

            new APFlowBLL().ScrapForm(FormID);
            gvApplyList.DataBind();
        }
    }
Example #9
0
        /// <summary>
        ///  销售
        /// </summary>
        /// <param name="FormID"></param>
        /// <returns></returns>
        private bool ExportSaleDataByFormID(int FormID, int logId)
        {
            ExportDataDS.ExportDataDataTable l_dtExportData = new ExportDataDS.ExportDataDataTable();
            FormDS.FormSalePaymentRow l_drFormSalePayment = new FormDS.FormSalePaymentDataTable().NewFormSalePaymentRow();
            FormMarketingBLL formmarkbll = new FormMarketingBLL();
            FormTEBLL formtebll = new FormTEBLL();
            FormSaleBLL formsalebll = new FormSaleBLL();
            MasterDataBLL masterdatabll = new MasterDataBLL();
            FormPurchaseBLL formPurchaseBLL = new FormPurchaseBLL();
            int Count = 0;
            FormDS.FormDataTable l_dtform = formmarkbll.GetFormByID(FormID);
            FormDS.FormRow l_drform = l_dtform.NewFormRow();
            try {
                if (l_dtform.Rows.Count > 0) {
                    l_drform = l_dtform[0];
                    if (l_drform.IsFinanceRemarkNull()) {
                        logbll.InsertExportLogDetail(logId, "单据编号:" + l_drform.FormNo + ",提交人:" + new StuffUserBLL().GetStuffUserById(l_drform.UserID)[0].StuffName + ",错误信息:财务摘要为空,导出失败!");
                        return false;
                    }
                    l_drFormSalePayment = formsalebll.GetFormSalePaymentByID(l_drform.FormID);
                    //if (l_drFormSalePayment.PaymentTypeID == (int)SystemEnums.PaymentType.FreeGoods)
                    //{
                    //    logbll.InsertExportLogDetail(logId, "单据编号:" + l_drform.FormNo + ",提交人:" + new StuffUserBLL().GetStuffUserById(l_drform.UserID)[0].StuffName + ",错误信息:货补的数据不导出!");
                    //    return false;
                    //}
                    //if (l_drFormSalePayment.PaymentTypeID == (int)SystemEnums.PaymentType.Transfer)
                    //{
                    //    logbll.InsertExportLogDetail(logId, "单据编号:" + l_drform.FormNo + ",提交人:" + new StuffUserBLL().GetStuffUserById(l_drform.UserID)[0].StuffName + ",错误信息:帐扣的数据不导入!");
                    //    return false;
                    //}
                    //if (l_drFormSalePayment.PaymentTypeID == (int)SystemEnums.PaymentType.PiaoKou)
                    //{
                    //    logbll.InsertExportLogDetail(logId, "单据编号:" + l_drform.FormNo + ",提交人:" + new StuffUserBLL().GetStuffUserById(l_drform.UserID)[0].StuffName + ",错误信息:票扣的数据不导入!");
                    //    return false;
                    //}
                    //if (l_drFormSalePayment.PaymentTypeID == 5)
                    //{
                    //    logbll.InsertExportLogDetail(logId, "单据编号:" + l_drform.FormNo + ",提交人:" + new StuffUserBLL().GetStuffUserById(l_drform.UserID)[0].StuffName + ",错误信息:调整因子的数据不导入!");
                    //    return false;
                    //}
                    FormDS.FormSalePaymentDetailDataTable l_dtFormSalePaymentDetail = formsalebll.GetFormSalePaymentDetailByPaymentID(FormID);
                    for (int i = 0; i < l_dtFormSalePaymentDetail.Rows.Count; i++) {
                        if (l_dtFormSalePaymentDetail[i].AmountRMB == Decimal.Zero) {
                            Count++;
                            continue;
                        }
                        //PurchaseDS.FormInvoiceDataTable l_dtFormInvoice = formPurchaseBLL.GetFormInvoiceByFormID(FormID);
                        ExportDataDS.ExportDataRow l_drExportData = l_dtExportData.NewExportDataRow();
                        l_drExportData.FormID = FormID;
                        l_drExportData.CompanyCode = l_drExportData.CompanyCode = masterdatabll.GetCompanyById(masterdatabll.GetVendorTypeById(masterdatabll.GetVendorByID(l_drFormSalePayment.VendorID).VendorTypeID).CompanyID).CompanyCode;
                        l_drExportData.VendorCode = masterdatabll.GetVendorByID(l_drFormSalePayment.VendorID).VendorCode;
                        if (l_drExportData.IsVendorCodeNull() || string.IsNullOrEmpty(l_drExportData.VendorCode)) {
                            logbll.InsertExportLogDetail(logId, "单据编号:" + l_drform.FormNo + ",提交人:" + new StuffUserBLL().GetStuffUserById(l_drform.UserID)[0].StuffName + ",错误信息:Vendor Code为空,无法导出!");
                            return false;
                        }
                        //发票号码改为单据编号,单据编号变为10位
                        l_drExportData.Invoice = l_drform.FormNo;
                        l_drExportData.Invoicedate = l_drform.SubmitDate.ToString("yyyyMMdd");

                        //if (l_dtFormInvoice.Rows.Count > 1)
                        //    l_drExportData.Reference = l_dtFormInvoice[1].InvoiceNo;
                        //if (l_dtFormInvoice.Rows.Count > 0) {
                        //    l_drExportData.Invoice = l_dtFormInvoice[0].InvoiceNo;
                        //    l_drExportData.Invoicedate = l_dtFormInvoice[0].InvoiceDate.ToString("yyyyMMdd");
                        //} else {
                        //    l_drExportData.Invoice = l_drform.FormNo;
                        //    l_drExportData.Invoicedate = l_drform.SubmitDate.ToString("yyyyMMdd");
                        //}

                        l_drExportData.TotalMoney = l_drFormSalePayment.AmountBeforeTax;
                        //l_drExportData.Currency = masterdatabll.GetCurrencyByID(formsalebll.GetFormSaleApplyByID(l_dtFormSalePaymentDetail[i].FormSaleApplyID)[0].CurrencyID).CurrencyShortName;
                        //l_drExportData.ExchangeRate = formsalebll.GetFormSaleApplyByID(l_dtFormSalePaymentDetail[i].FormSaleApplyID)[0].ExchangeRate;
                        l_drExportData.ManageExpenseItem = masterdatabll.GetExpenseItemById(l_dtFormSalePaymentDetail[i].ExpenseItemID).ExpenseItemName;
                        //profit center取AccrualCode,如果没有报错
                        if (masterdatabll.GetCostCenterById(l_drform.CostCenterID).IsAccrualCodeNull()) {
                            logbll.InsertExportLogDetail(logId, "单据编号:" + l_drform.FormNo + ",提交人:" + new StuffUserBLL().GetStuffUserById(l_drform.UserID)[0].StuffName + ",错误信息:Profit Center Accrual Code为空,无法导出!");
                            return false;
                        } else {
                            l_drExportData.CostCenter = masterdatabll.GetCostCenterById(l_drform.CostCenterID).AccrualCode;
                        }

                        if (l_dtFormSalePaymentDetail[i].ApplyPeriod.AddMonths(5).Year == l_drform.SubmitDate.AddMonths(5).Year)
                            l_drExportData.AccountCode = masterdatabll.GetExpenseItemById(l_dtFormSalePaymentDetail[i].ExpenseItemID).AccrualAccountingCode;
                        else
                            l_drExportData.AccountCode = masterdatabll.GetExpenseItemById(l_dtFormSalePaymentDetail[i].ExpenseItemID).LastAccountingCode;

                        l_drExportData.DetailMoney = l_dtFormSalePaymentDetail[i].AmountBeforeTax;
                        //PO No 变为取报销单的PO的No
                        if (l_drFormSalePayment.IsFormPOIDNull()) {
                            //PurchaseDS.FormPODataTable formPO = formPurchaseBLL.GetFormPOByParentFormID(l_dtFormSalePaymentDetail[i].FormSaleApplyID);
                            //if (formPO.Rows.Count > 0) {
                            //    l_drExportData.PONumber = formPO[0].BPCSPONo;
                            //    PurchaseDS.FormPODetailDataTable formPODetail = formPurchaseBLL.GetPODetailByFormPOID(formPO[0].FormPOID);
                            //    l_drExportData.POLineNumber = formPODetail.Rows.Count.ToString();
                            //} else {
                            l_drExportData.PONumber = 0;
                            l_drExportData.POLineNumber = "0";
                            //}
                        } else {
                            //若已选PO,取所选PO信息
                            PurchaseDS.FormPORow formPO = formPurchaseBLL.GetFormPOByID(l_drFormSalePayment.FormPOID);
                            PurchaseDS.FormPODetailDataTable formPODetail = formPurchaseBLL.GetPODetailByFormPOID(l_drFormSalePayment.FormPOID);
                            l_drExportData.PONumber = formPO.BPCSPONo;
                            l_drExportData.POLineNumber = formPODetail.Count.ToString();
                        }

                        l_drExportData.FormNo = l_drform.FormNo;
                        l_drExportData.FinanceRemark = l_drform.FinanceRemark;
                        l_drExportData.TaxRateCode = masterdatabll.GetVatTypeById(l_drFormSalePayment.VatTypeID)[0].VatTypeName;
                        l_drExportData.TaxAmt = l_dtFormSalePaymentDetail[i].TaxAmount;
                        l_dtExportData.AddExportDataRow(l_drExportData);
                        Count++;
                    }
                    if (l_dtExportData.Rows.Count == 0) {
                        logbll.InsertExportLogDetail(logId, "单据编号:" + l_drform.FormNo + ",提交人:" + new StuffUserBLL().GetStuffUserById(l_drform.UserID)[0].StuffName + ",错误信息:无明细数据,无法导出!");
                        return false;
                    }
                    if (l_dtFormSalePaymentDetail.Rows.Count == Count)
                        ExportByFormView(l_dtExportData);
                    else {
                        logbll.InsertExportLogDetail(logId, "单据编号:" + l_drform.FormNo + ",提交人:" + new StuffUserBLL().GetStuffUserById(l_drform.UserID)[0].StuffName + ",错误信息:明细数据数量不一致,无法导出!");
                        return false;
                    }
                }
            } catch (Exception e) {

                logbll.InsertExportLogDetail(logId, "单据编号:" + l_drform.FormNo + ",提交人:" + new StuffUserBLL().GetStuffUserById(l_drform.UserID)[0].StuffName + ",错误信息:" + e.Message);
                return false;
            }
            return true;
        }
Example #10
0
        private void ExportData()
        {
            string FileName = ConfigurationManager.AppSettings["ExportService.FileName"];
            string ExportHour = ConfigurationManager.AppSettings["ExportService.hour"];
            string BakPath = ConfigurationManager.AppSettings["ExportService.BakPath"];

            ExportDate = DateTime.Now;

            path = ConfigurationManager.AppSettings["ExportService.Path"].ToString();
            bool Export = true;
            if (Export) {
                FormRDBLL formrdbll = new FormRDBLL();
                FormPurchaseBLL formPurchaseBLL = new FormPurchaseBLL();
                FormQueryBLL formquerybll = new FormQueryBLL();
                FormMarketingBLL formmarkbll = new FormMarketingBLL();
                FormSaleBLL formsalebll = new FormSaleBLL();
                QueryDS.FormViewDataTable l_dtformview = formquerybll.GetPagedFormView(" Form.StatusID=2 and (Form.IsExportLock='false' or Form.IsExportLock is null) AND Form.FormTypeID=4 ", 0, Int32.MaxValue, "Form.SubmitDate");
                //个人
                int logId = logbll.InsertExportLog(1, FileName, 0, 0, 0, 0);
                int SuccessCount = 0;
                int FailCount = 0;
                int TotalCount = l_dtformview.Rows.Count;
                foreach (QueryDS.FormViewRow l_drformview in l_dtformview) {
                    if (ExportPersonalReimburseDataByFormID(l_drformview.FormID, logId)) {
                        UpdateFormbyID(l_drformview.FormID, true);
                        SuccessCount++;
                    } else {
                        UpdateFormbyID(l_drformview.FormID, false);
                        FailCount++;
                    }
                }
                logbll.UpdateExportLog(logId, TotalCount, SuccessCount, FailCount);

                //差旅费
                logId = logbll.InsertExportLog(2, FileName, 0, 0, 0, 0);
                SuccessCount = 0;
                FailCount = 0;
                l_dtformview = formquerybll.GetPagedFormView("Form.StatusID=2 and (Form.IsExportLock='false' or Form.IsExportLock is null) AND Form.FormTypeID =1 ", 0, Int32.MaxValue, "SubmitDate");
                TotalCount = l_dtformview.Rows.Count;
                foreach (QueryDS.FormViewRow l_drformview in l_dtformview) {
                    if (ExportTravelReimburseDataByFormID(l_drformview.FormID, logId)) {
                        UpdateFormbyID(l_drformview.FormID, true);
                        SuccessCount++;
                    } else {
                        UpdateFormbyID(l_drformview.FormID, false);
                        FailCount++;
                    }
                }
                logbll.UpdateExportLog(logId, TotalCount, SuccessCount, FailCount);

                //pv
                logId = logbll.InsertExportLog(3, FileName, 0, 0, 0, 0);
                SuccessCount = 0;
                FailCount = 0;
                l_dtformview = formquerybll.GetPagedFormView("Form.StatusID=2 and (Form.IsExportLock='false' or Form.IsExportLock is null) AND Form.FormTypeID =24 ", 0, Int32.MaxValue, "SubmitDate");
                TotalCount = l_dtformview.Rows.Count;
                foreach (QueryDS.FormViewRow l_drformview in l_dtformview) {
                    if (ExportPVDataByFormID(l_drformview.FormID, logId)) {
                        UpdateFormbyID(l_drformview.FormID, true);
                        SuccessCount++;
                    } else {
                        UpdateFormbyID(l_drformview.FormID, false);
                        FailCount++;
                    }
                }
                logbll.UpdateExportLog(logId, TotalCount, SuccessCount, FailCount);

                //sale
                logId = logbll.InsertExportLog(4, FileName, 0, 0, 0, 0);
                SuccessCount = 0;
                FailCount = 0;
                l_dtformview = formquerybll.GetPagedFormView("Form.StatusID=2 and (Form.IsExportLock='false' or Form.IsExportLock is null)  AND Form.FormTypeID in (13,14) and Form.FormID  in (select FormSalePaymentID from FormSalePayment where PaymentTypeID = 1)", 0, Int32.MaxValue, "SubmitDate");
                TotalCount = l_dtformview.Rows.Count;
                foreach (QueryDS.FormViewRow l_drformview in l_dtformview) {
                    if (ExportSaleDataByFormID(l_drformview.FormID, logId)) {
                        UpdateFormbyID(l_drformview.FormID, true);
                        SuccessCount++;
                    } else {
                        UpdateFormbyID(l_drformview.FormID, false);
                        FailCount++;
                    }
                }
                logbll.UpdateExportLog(logId, TotalCount, SuccessCount, FailCount);

                //market
                logId = logbll.InsertExportLog(5, FileName, 0, 0, 0, 0);
                SuccessCount = 0;
                FailCount = 0;
                l_dtformview = formquerybll.GetPagedFormView(" (Form.IsExportLock='false' or Form.IsExportLock is null)  AND Form.StatusID=2 AND Form.FormTypeID=42 AND  Form.FormID  in (select FormMarketingPaymentID from FormMarketingPayment where PaymentTypeID = 1)", 0, Int32.MaxValue, "SubmitDate");
                TotalCount = l_dtformview.Rows.Count;
                foreach (QueryDS.FormViewRow l_drformview in l_dtformview) {
                    if (ExportMarketingDataByFormID(l_drformview.FormID, logId)) {
                        UpdateFormbyID(l_drformview.FormID, true);
                        SuccessCount++;
                    } else {
                        UpdateFormbyID(l_drformview.FormID, false);
                        FailCount++;
                    }
                }
                logbll.UpdateExportLog(logId, TotalCount, SuccessCount, FailCount);

                //RD
                logId = logbll.InsertExportLog(6, FileName, 0, 0, 0, 0);
                SuccessCount = 0;
                FailCount = 0;
                l_dtformview = formquerybll.GetPagedFormView(" Form.StatusID=2 and (Form.IsExportLock='false' or Form.IsExportLock is null)  AND Form.FormTypeID=32 AND Form.FormID in (select FormRDPaymentID from FormRDPayment where PaymentTypeID = 1)", 0, Int32.MaxValue, "SubmitDate");
                TotalCount = l_dtformview.Rows.Count;
                foreach (QueryDS.FormViewRow l_drformview in l_dtformview) {
                    if (ExportRDDataByFormID(l_drformview.FormID, logId)) {
                        UpdateFormbyID(l_drformview.FormID, true);
                        SuccessCount++;
                    } else {
                        UpdateFormbyID(l_drformview.FormID, false);
                        FailCount++;
                    }
                }
                logbll.UpdateExportLog(logId, TotalCount, SuccessCount, FailCount);
                if (File.Exists(path + FileName)) {
                    File.Copy(path + FileName, BakPath + FileName.Split('.')[0] + DateTime.Now.ToString("yyyyMMdd") + "." + FileName.Split('.')[1], true);
                } else {
                    File.AppendAllText(path + FileName, "", Encoding.Default);
                }

                //Vendor
                FileName = ConfigurationManager.AppSettings["ExportService.VendorAVMFileName"];
                logId = logbll.InsertExportLog(8, FileName, 0, 0, 0, 0);
                SuccessCount = 0;
                FailCount = 0;
                MasterData.VendorDataTable tbVendor = new MasterDataBLL().GetVendorToExport();
                TotalCount = tbVendor.Rows.Count;
                foreach (MasterData.VendorRow vendor in tbVendor) {
                    if (ExportVendorAVM(vendor, logId)) {
                        SuccessCount++;
                    } else {
                        FailCount++;
                    }
                }
                logbll.UpdateExportLog(logId, TotalCount, SuccessCount, FailCount);
                if (File.Exists(path + FileName))
                    File.Copy(path + FileName, BakPath + FileName.Split('.')[0] + DateTime.Now.ToString("yyyyMMdd") + "." + FileName.Split('.')[1], true);
                else
                    File.AppendAllText(path + FileName, "", Encoding.Default);
                //Vendor
                FileName = ConfigurationManager.AppSettings["ExportService.VendorAVMXFileName"];
                logId = logbll.InsertExportLog(8, FileName, 0, 0, 0, 0);
                SuccessCount = 0;
                FailCount = 0;
                tbVendor = new MasterDataBLL().GetAllVendor();
                TotalCount = tbVendor.Rows.Count;
                foreach (MasterData.VendorRow vendor in tbVendor) {
                    if (ExportVendorAVMX(vendor, logId)) {
                        SuccessCount++;
                    } else {
                        FailCount++;
                    }
                }
                logbll.UpdateExportLog(logId, TotalCount, SuccessCount, FailCount);
                if (File.Exists(path + FileName))
                    File.Copy(path + FileName, BakPath + FileName.Split('.')[0] + DateTime.Now.ToString("yyyyMMdd") + "." + FileName.Split('.')[1], true);

                //PO
                string POFileName = ConfigurationManager.AppSettings["ExportService.POFileName"];
                string POLineFileName = ConfigurationManager.AppSettings["ExportService.POLineFileName"];
                logId = logbll.InsertExportLog(9, POFileName + " And " + POLineFileName, 0, 0, 0, 0);
                SuccessCount = 0;
                FailCount = 0;
                l_dtformview = formquerybll.GetPagedFormView(" Form.StatusID=2 and (Form.IsExportLock='false' or Form.IsExportLock is null)  AND Form.FormTypeID=23", 0, Int32.MaxValue, "SubmitDate");
                TotalCount = l_dtformview.Rows.Count;
                foreach (QueryDS.FormViewRow l_drformview in l_dtformview) {
                    PurchaseDS.FormPORow formPO = formPurchaseBLL.GetFormPOByID(l_drformview.FormID);
                    if (ExportPO(l_drformview.FormID, logId)) {
                        UpdateFormbyID(l_drformview.FormID, true);
                        SuccessCount++;
                    } else {
                        UpdateFormbyID(l_drformview.FormID, false);
                        FailCount++;
                    }
                }
                logbll.UpdateExportLog(logId, TotalCount, SuccessCount, FailCount);
                if (File.Exists(path + POFileName))
                    File.Copy(path + POFileName, BakPath + POFileName.Split('.')[0] + DateTime.Now.ToString("yyyyMMdd") + "." + POFileName.Split('.')[1], true);
                else
                    File.AppendAllText(path + POFileName, "", Encoding.Default);

                if (File.Exists(path + POLineFileName))
                    File.Copy(path + POLineFileName, BakPath + POLineFileName.Split('.')[0] + DateTime.Now.ToString("yyyyMMdd") + "." + POLineFileName.Split('.')[1], true);
                else
                    File.AppendAllText(path + POLineFileName, "", Encoding.Default);

            }
        }
Example #11
0
        private void ImportTxtData(int importType, FileSystemInfo[] fsis)
        {
            foreach (FileSystemInfo fsi in fsis) {
                FormSampleRequestBLL formsamplerequestbll = new FormSampleRequestBLL();
                MasterDataBLL masterdatabll = new MasterDataBLL();
                LogBLL logbll = new LogBLL();
                FormSaleBLL formbll = new FormSaleBLL();
                int SuccessCount = 0;
                int FailCount = 0;
                string[] Content = File.ReadAllLines(fsi.FullName, Encoding.Default);
                //插入LOG主数据
                int logId = logbll.InsertImportLog(importType, fsi.Name, 27, Content.Length, SuccessCount, FailCount);
                for (int i = 0; i < Content.Length; i++) {
                    try {
                        //导入数据
                        #region 类型为SKU
                        if (importType == 0) {
                            string[] SKU = Content[i].Split('\t');
                            if (SKU.Length != 13) {
                                logbll.InsertImportLogDetail(logId, i + 1, "SKU数据COUNT错误!");
                                FailCount += 1;
                                continue;
                            }
                            //SKU = Content[i].Replace("\"", "").Split('\t');
                            Boolean active = false;
                            if (SKU[12].ToUpper().IndexOf("IM") >= 0) {
                                active = true;
                            } else if (SKU[12].ToUpper().IndexOf("IZ") >= 0) {
                                active = false;
                            } else {
                                logbll.InsertImportLogDetail(logId, i + 1, "active数据错误!");
                                FailCount += 1;
                                continue;
                            }

                            int BrandId = 0;
                            int SKUCategoryId = 0;
                            int SKUTypeID = 0;

                            MasterData.BrandDataTable Brand = masterdatabll.GetBrandByName(SKU[2]);
                            if (Brand.Rows.Count > 0) {
                                BrandId = Brand[0].BrandID;
                            } else {
                                logbll.InsertImportLogDetail(logId, i + 1, string.Format("编号为{0}的产品未找到Brand({1})!", SKU[0], SKU[2]));
                                FailCount += 1;
                                continue;
                            }
                            MasterData.SKUCategoryDataTable SKUCategory = masterdatabll.GetSKUCategoryByName(SKU[3]);
                            if (SKUCategory.Rows.Count > 0) {
                                SKUCategoryId = SKUCategory[0].SKUCategoryID;
                            } else {
                                logbll.InsertImportLogDetail(logId, i + 1, string.Format("编号为{0}的产品未找到SKU Category({1})!", SKU[0], SKU[3]));
                                FailCount += 1;
                                continue;
                            }
                            MasterData.SKUTypeDataTable SKUType = masterdatabll.GetSKUTypeByName(SKU[4]);
                            if (SKUType.Rows.Count > 0) {
                                SKUTypeID = SKUType[0].SKUTypeID;
                            }
                            MasterData.SKUDataTable dtSKU = masterdatabll.GetSKUBySKUNo(SKU[0]);
                            if (dtSKU.Rows.Count > 0) {
                                //Update
                                masterdatabll.UpdateSKU(dtSKU[0].SKUID, SKU[0], SKU[1], BrandId, SKUTypeID, SKUCategoryId, SKU[5], SKU[6], SKU[7], SKU[8], SKU[9], Decimal.Parse(SKU[10]), SKU[11], active);
                            } else if (active)//未找到数据  并且active 是ture的才做插入
                            {
                                //导入数据
                                masterdatabll.InsertSKU(SKU[0], SKU[1], BrandId, SKUTypeID, SKUCategoryId, SKU[5], SKU[6], SKU[7], SKU[8], SKU[9], Decimal.Parse(SKU[10]), SKU[11], active);
                            }
                        }
                        #endregion

                        #region 类型为Item
                        if (importType == 1) {
                            string[] Item = Content[i].Split('\t');
                            if (Item.Length != 6) {
                                logbll.InsertImportLogDetail(logId, i + 1, "Item数据COUNT错误!");
                                FailCount += 1;
                                continue;
                            }
                            //Item = Content[i].Replace("\"", "").Split('\t');

                            int ItemCategoryID = 0;
                            Boolean active = false;
                            if (Item[5].ToUpper().IndexOf("PC") >= 0) {
                                active = true;
                            } else if (Item[5].ToUpper().IndexOf("PZ") >= 0) {
                                active = false;
                            } else {
                                logbll.InsertImportLogDetail(logId, i + 1, "active数据错误!");
                                FailCount += 1;
                                continue;
                            }
                            MasterData.ItemCategoryDataTable ItemCategory = masterdatabll.GetItemCategoryByCode(Item[2]);
                            if (ItemCategory.Rows.Count > 0) {
                                ItemCategoryID = ItemCategory[0].ItemCategoryID;
                            } else {
                                logbll.InsertImportLogDetail(logId, i + 1, "未找到Item Category!");
                                FailCount += 1;
                                continue;
                            }
                            MasterData.ItemDataTable dtItem = masterdatabll.GetItemByCode(Item[0]);
                            if (dtItem.Rows.Count > 0) {
                                //Update
                                masterdatabll.UpdateItem(dtItem[0].ItemID, Item[0], Item[1], ItemCategoryID, Item[3], Item[4], active);
                            } else if (active)//未找到数据  并且active 是ture的才做插入
                            {
                                //导入数据
                                masterdatabll.InsertItem(Item[0], Item[1], ItemCategoryID, Item[3], Item[4], active);
                            }
                        }
                        #endregion

                        #region 类型为Customer
                        if (importType == 2) {
                            string[] Customer = Content[i].Split('\t');
                            if (Customer.Length != 14) {
                                logbll.InsertImportLogDetail(logId, i + 1, "Customer数据COUNT错误!");
                                FailCount += 1;
                                continue;
                            }
                            //Customer = Content[i].Replace("\"", "").Split('\t');
                            Boolean active = false;
                            if (Customer[12].ToUpper().IndexOf("CM") >= 0) {
                                active = true;
                            } else if (Customer[12].ToUpper().IndexOf("CZ") >= 0) {
                                active = false;
                            } else {
                                logbll.InsertImportLogDetail(logId, i + 1, "active数据错误!");
                                FailCount += 1;
                                continue;
                            }
                            int CustomerTypeID = 0;
                            int CustomerChannelID = 0;
                            int ProvinceID = 0;
                            int CustomerRegionID = 0;
                            //查询ID

                            MasterData.CustomerTypeDataTable CustomerType = masterdatabll.GetCustomerTypeByName(Customer[5]);
                            if (CustomerType.Rows.Count > 0) {
                                CustomerTypeID = CustomerType[0].CustomerTypeID;
                            } else {

                                logbll.InsertImportLogDetail(logId, i + 1, "未找到Customer Type!");
                                FailCount += 1;
                                continue;
                            }

                            MasterData.CustomerChannelDataTable CustomerChannel = masterdatabll.GetCustomerChanneByCode(Customer[6]);
                            if (CustomerChannel.Rows.Count > 0) {
                                CustomerChannelID = CustomerChannel[0].CustomerChannelID;
                            } else {
                                logbll.InsertImportLogDetail(logId, i + 1, "未找到Customer Channel!");
                                FailCount += 1;
                                continue;
                            }

                            MasterData.ProvinceDataTable Province = masterdatabll.GetProvinceByName(Customer[8]);
                            if (Province.Rows.Count > 0) {
                                ProvinceID = Province[0].ProvinceID;
                            } else {
                                logbll.InsertImportLogDetail(logId, i + 1, "未找到Province!");
                                FailCount += 1;
                                continue;
                            }

                            MasterData.CustomerRegionDataTable CustomerRegion = masterdatabll.GetCustomerRegionByName(Customer[9]);
                            if (CustomerRegion.Rows.Count > 0)
                                CustomerRegionID = CustomerRegion[0].CustomerRegionID;
                            else {
                                logbll.InsertImportLogDetail(logId, i + 1, "未找到Customer Region!");
                                FailCount += 1;
                                continue;
                            }
                            MasterData.CustomerDataTable dtCustomer = masterdatabll.GetCustomerByNo(Customer[0]);
                            if (dtCustomer.Rows.Count > 0) {
                                //Update
                                masterdatabll.UpdateCustomer(dtCustomer[0].CustomerID, Customer[0], Customer[1], Customer[2], Customer[3], Customer[4], Customer[4],
                                    CustomerTypeID, CustomerChannelID, Customer[7], ProvinceID, CustomerRegionID, Customer[10], Customer[11],
                                    "", "", "", "", active, Customer[13]);
                            } else if (active)//未找到数据  并且active 是ture的才做插入
                            {
                                //导入数据
                                masterdatabll.InsertCustomer(Customer[0], Customer[1], Customer[2], Customer[3], Customer[4], Customer[5],
                                    CustomerTypeID, CustomerChannelID, Customer[7], ProvinceID, CustomerRegionID, Customer[10], Customer[11],
                                    "", "", "", "", active, Customer[13]);
                            } else {
                                logbll.InsertImportLogDetail(logId, i + 1, "未激活的数据不导入!");
                                FailCount += 1;
                                continue;
                            }
                        }
                        #endregion

                        #region 类型为货补
                        if (importType == 3) {
                            string[] Delivery = Content[i].Split('\t');
                            if (Delivery.Length != 7) {
                                logbll.InsertImportLogDetail(logId, i + 1, "Delivery数据COUNT错误!");
                                FailCount += 1;
                                continue;
                            }
                            string l_strMaaNumber = Delivery[0].ToString();
                            string l_strSKUNo = Delivery[1].ToString();
                            string l_strPrice = Delivery[2].ToString();
                            string l_strDeliveryNo = Delivery[3].ToString();
                            string l_strQuantity = Delivery[4].ToString();
                            string l_strAmountRMB = Delivery[5].ToString();
                            string l_strDeliveryDate = Delivery[6].ToString();
                            int SkuID = 0;
                            int FormID = 0;
                            decimal Price = 0;
                            decimal AmountRMB = 0;
                            decimal Quantity = 0;
                            DateTime DeliveryDate = DateTime.Now;
                            if (string.IsNullOrEmpty(l_strMaaNumber) || string.IsNullOrEmpty(l_strSKUNo) || string.IsNullOrEmpty(l_strPrice) ||
                                string.IsNullOrEmpty(l_strDeliveryNo) || string.IsNullOrEmpty(l_strQuantity) || string.IsNullOrEmpty(l_strAmountRMB) ||
                                string.IsNullOrEmpty(l_strDeliveryDate)) {
                                logbll.InsertImportLogDetail(logId, i, "数据有空列,导入失败!");
                                FailCount++;
                                continue;
                            }
                            FormDS.FormDataTable l_dtForm = formbll.GetDataByFormNo(l_strMaaNumber);
                            if (l_dtForm.Rows.Count == 0) {
                                logbll.InsertImportLogDetail(logId, i, "未找到MAA号:" + l_strMaaNumber + "的单据,导入失败!");
                                FailCount++;
                                continue;
                            } else {
                                FormID = l_dtForm[0].FormID;
                            }
                            MasterData.SKUDataTable l_dtSKU = new MasterDataBLL().GetSKUBySKUNo(l_strSKUNo);
                            if (l_dtSKU.Rows.Count == 0) {
                                logbll.InsertImportLogDetail(logId, i, "未找到此SKU:" + l_strSKUNo + " NUMBER 下的SKU,导入失败!");
                                FailCount++;
                                continue;
                            } else {
                                SkuID = l_dtSKU[0].SKUID;
                            }
                            //价格是成本价,进入系统应该是
                            try {
                                Price = decimal.Round(decimal.Parse(l_strPrice) * (decimal)1.1 * (decimal)1.17, 2);
                            } catch {
                                logbll.InsertImportLogDetail(logId, i, "单价错误,导入失败!");
                                FailCount++;
                                continue;
                            }
                            try {
                                Quantity = decimal.Parse(l_strQuantity);
                            } catch {
                                logbll.InsertImportLogDetail(logId, i, "数量错误,导入失败!");
                                FailCount++;
                                continue;
                            }
                            try {
                                AmountRMB = Price * Quantity;
                            } catch {
                                logbll.InsertImportLogDetail(logId, i, "发货金额,导入失败!");
                                FailCount++;
                                continue;
                            }
                            try {
                                DeliveryDate = DateTime.Parse(l_strDeliveryDate);
                            } catch {
                                logbll.InsertImportLogDetail(logId, i, "日期错误,导入失败!");
                                FailCount++;
                                continue;
                            }
                            if (string.IsNullOrEmpty(l_strDeliveryNo)) {
                                logbll.InsertImportLogDetail(logId, i, "订单号为空,导入失败!");
                                FailCount++;
                                continue;
                            }
                            int result = 0;
                            FormDS.FormDeliveryGoodsDataTable l_dtFormDeliveryGoods = formbll.GetDataByDeliveryNoAndSkuID(l_strDeliveryNo, SkuID, l_strMaaNumber);
                            if (l_dtFormDeliveryGoods.Rows.Count > 0) {
                                result = formbll.UpdateFormDeliveryGoods(int.Parse(l_dtFormDeliveryGoods.Rows[0][0].ToString()), l_strDeliveryNo, DeliveryDate, Price, Quantity, AmountRMB);
                                if (result == 0) {
                                    logbll.InsertImportLogDetail(logId, i, "数据更新失败!");
                                    FailCount++;
                                    continue;
                                }
                            } else {
                                result = formbll.InsertFormDeliveryGoods(FormID, SkuID, l_strDeliveryNo, DeliveryDate, Price, Quantity, AmountRMB);
                                if (result == 0) {
                                    logbll.InsertImportLogDetail(logId, i, "数据插入失败!");
                                    FailCount++;
                                    continue;
                                }
                            }
                            formsamplerequestbll.UpdateFormAfterDeliveryComplete(FormID, 27);
                        }
                        #endregion

                        #region 类型为APH
                        if (importType == 4) {
                            string[] PaymentInfo = Content[i].Split('\t');
                            if (PaymentInfo.Length != 3) {
                                logbll.InsertImportLogDetail(logId, i + 1, "APH数据COUNT错误!");
                                FailCount += 1;
                                continue;
                            }
                            FormDS.FormDataTable l_dtform = new FormDS.FormDataTable();
                            l_dtform = formbll.GetDataByFormNo(PaymentInfo[0]);
                            if (l_dtform.Rows.Count == 0) {
                                logbll.InsertImportLogDetail(logId, i + 1, "未找到此Form单号:" + PaymentInfo[0] + "的单据");
                                FailCount += 1;
                                continue;
                            }
                            FormDS.FormRow l_drform = l_dtform[0];
                            if (l_drform.FormTypeID == (int)SystemEnums.FormType.FormMarketingPayment ||
                                l_drform.FormTypeID == (int)SystemEnums.FormType.PVApply ||
                                l_drform.FormTypeID == (int)SystemEnums.FormType.RDPayment ||
                                l_drform.FormTypeID == (int)SystemEnums.FormType.SalePayment ||
                                l_drform.FormTypeID == (int)SystemEnums.FormType.TravelReimburseApply ||
                                l_drform.FormTypeID == (int)SystemEnums.FormType.PersonalReimburseApply) {

                                try {
                                    if (!string.IsNullOrEmpty(PaymentInfo[1]))
                                        l_drform.PaymentDate = DateTime.Parse(PaymentInfo[1].Substring(0, 4) + "-" + PaymentInfo[1].Substring(4, 2) + "-" + PaymentInfo[1].Substring(6, 2));
                                    else {
                                        logbll.InsertImportLogDetail(logId, i + 1, "付款时间不能为空!");
                                        FailCount += 1;
                                        continue;
                                    }
                                } catch {
                                    logbll.InsertImportLogDetail(logId, i + 1, "时间格式不正确");
                                    FailCount += 1;
                                    continue;
                                }
                            } else {
                                logbll.InsertImportLogDetail(logId, i + 1, "单号:" + PaymentInfo[0] + " 不是正确的付款单号");
                                FailCount += 1;
                                continue;
                            }
                            try {
                                if (!string.IsNullOrEmpty(PaymentInfo[2])) {
                                    decimal PaymentAmount = decimal.Parse(PaymentInfo[2]);
                                    l_drform.PaymentAmount = PaymentAmount;
                                } else {
                                    logbll.InsertImportLogDetail(logId, i + 1, "付款金额不能为空!");
                                    FailCount += 1;
                                    continue;
                                }
                            } catch {
                                logbll.InsertImportLogDetail(logId, i + 1, "付款金额错误!");
                                FailCount += 1;
                                continue;
                            }
                            formbll.TAForm.Update(l_drform);
                        }
                        #endregion

                        SuccessCount += 1;
                    } catch (Exception ee) {
                        logbll.InsertImportLogDetail(logId, i + 1, ee.Message);
                        FailCount += 1;
                        continue;
                    }
                }
                //Update SuccessCount FailCount
                logbll.UpdateImportLog(logId, importType, fsi.Name, 1, Content.Length, SuccessCount, FailCount);
            }
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        AuthorizationDS.PositionRow position = (AuthorizationDS.PositionRow)this.Session["Position"];
        base.Page_Load(sender, e);
        if (!this.IsPostBack) {
            String title = this.GetLocalResourceObject("titleLabel.Text").ToString();
            PageUtility.SetContentTitle(this.Page, title);

            MasterDataBLL mdBLL = new MasterDataBLL();
            int formID = int.Parse(Request["ObjectId"]);
            this.ViewState["ObjectId"] = formID;
            FormDS.FormRow rowForm = this.FormSaleBLL.GetFormByID(formID)[0];
            FormDS.FormSaleApplyRow rowFormApply = this.FormSaleBLL.GetFormSaleApplyByID(formID)[0];
            if (rowForm.IsProcIDNull()) {
                ViewState["ProcID"] = "";
            } else {
                ViewState["ProcID"] = rowForm.ProcID;
            }

            this.FormNoCtl.Text = rowForm.FormNo;
            AuthorizationDS.StuffUserRow applicant = new AuthorizationBLL().GetStuffUserById(rowForm.UserID);
            this.StuffNameCtl.Text = CommonUtility.GetStaffFullName(applicant);
            this.PositionNameCtl.Text = new OUTreeBLL().GetPositionById(rowForm.PositionID).PositionName;
            if (new OUTreeBLL().GetOrganizationUnitById(rowForm.OrganizationUnitID) != null) {
                this.DepartmentNameCtl.Text = new OUTreeBLL().GetOrganizationUnitById(rowForm.OrganizationUnitID).OrganizationUnitName;
            }
            this.StuffNoCtl.Text = applicant.IsStuffNoNull() ? "" : applicant.StuffNo;
            this.AttendDateCtl.Text = applicant.AttendDate.ToShortDateString();

            this.PeriodCtl.Text = rowFormApply.FPeriod.ToString("yyyy-MM");

            MasterData.CustomerRow customer = new CustomerTableAdapter().GetDataByID(rowFormApply.CustomerID)[0];
            this.txtCustomerCode.Text = customer.CustomerNo;
            this.CustomerNameCtl.Text = customer.CustomerName;
            this.CustomerChannelCtl.Text = new CustomerChannelTableAdapter().GetDataByID(customer.CustomerChannelID)[0].CustomerChannelName;
            this.KATypeCtl.Text = customer.IsKaTypeNull() ? "" : customer.KaType;
            this.CustomerRegionCtl.Text = new CustomerRegionTableAdapter().GetDataByID(customer.CustomerRegionID)[0].CustomerRegionName;
            this.CityCtl.Text = customer.City;
            this.BrandCtl.Text = new BrandTableAdapter().GetDataByID(rowFormApply.BrandID)[0].BrandName;
            MasterData.ExpenseSubCategoryRow rowExpenseSubCategory = mdBLL.GetExpenseSubCategoryById(rowFormApply.ExpenseSubCategoryID);
            this.ExpenseCategoryCtl.Text = mdBLL.GetExpenseCategoryById(rowExpenseSubCategory.ExpenseCategoryID).ExpenseCategoryName;
            this.ExpenseSubCategoryCtl.Text = rowExpenseSubCategory.ExpenseSubCategoryName;
            this.CurrencyCtl.Text = new CurrencyTableAdapter().GetDataByID(rowFormApply.CurrencyID)[0].CurrencyShortName;
            this.ExchangeRateCtl.Text = rowFormApply.ExchangeRate.ToString();
            this.ShopNameCtl.Text = rowFormApply.IsShopNameNull() ? "" : rowFormApply.ShopName;
            this.ShopCountCtl.Text = rowFormApply.IsShopCountNull() ? "" : rowFormApply.ShopCount.ToString();
            this.ProjectNameCtl.Text = rowFormApply.IsProjectNameNull() ? "" : rowFormApply.ProjectName;
            this.CostCenterCtl.Text = CommonUtility.GetMAACostCenterFullName(rowForm.CostCenterID);

            //历史单据
            if (rowForm.IsRejectedFormIDNull()) {
                lblRejectFormNo.Text = "无";
            } else {
                FormDS.FormRow rejectedForm = this.FormSaleBLL.GetFormByID(rowForm.RejectedFormID)[0];
                this.lblRejectFormNo.Text = rejectedForm.FormNo;
                this.lblRejectFormNo.NavigateUrl = "javascript:window.showModalDialog('" + System.Configuration.ConfigurationManager.AppSettings["WebSiteUrl"] + "/SampleRequest/SaleSampleRequestApproval.aspx?ShowDialog=1&ObjectId=" + rejectedForm.FormID + "','', 'dialogWidth:1000px;dialogHeight:750px;resizable:yes;')";
            }

            this.ProjectDescCtl.Text = rowFormApply.IsProjectDescNull() ? "" : rowFormApply.ProjectDesc;
            if (!rowFormApply.IsApplyFileNameNull())
                this.UCFileUpload.AttachmentFileName = rowFormApply.ApplyFileName;
            if (!rowFormApply.IsApplyRealFileNameNull())
                this.UCFileUpload.RealAttachmentFileName = rowFormApply.ApplyRealFileName;

            if (!rowFormApply.IsActivityBeginDateNull()) {
                this.ActivityBeginCtl.Text = rowFormApply.ActivityBeginDate.ToString("yyyy-MM-dd");
            }
            if (!rowFormApply.IsActivityEndDateNull()) {
                this.ActivityEndCtl.Text = rowFormApply.ActivityEndDate.ToString("yyyy-MM-dd");
            }
            if (!rowFormApply.IsExpectDeliveryDateNull()) {
                this.txtExpectDeliveryDate.Text = rowFormApply.ExpectDeliveryDate.ToString("yyyy-MM-dd");
            }
            if (!rowFormApply.IsDeliveryAddressNull()) {
                this.txtDeliveryAddress.Text = rowFormApply.DeliveryAddress;
            }

            this.TotalBudgetCtl.Text = rowFormApply.TotalBudget.ToString("N");
            this.ApprovedAmountCtl.Text = rowFormApply.ApprovedAmount.ToString("N");
            this.ApprovingAmountCtl.Text = rowFormApply.ApprovingAmount.ToString("N");
            this.CompletedAmountCtl.Text = rowFormApply.CompletedAmount.ToString("N");
            this.ReimbursedAmountCtl.Text = rowFormApply.ReimbursedAmount.ToString("N");
            this.RemainBudgetCtl.Text = rowFormApply.RemainBudget.ToString("N");

            //明细
            this.odsDetails.SelectParameters["FormSaleApplyID"].DefaultValue = rowFormApply.FormSaleApplyID.ToString();

            //按钮控制
            //审批页面处理&按钮处理
            AuthorizationDS.StuffUserRow stuffUser = (AuthorizationDS.StuffUserRow)Session["StuffUser"];
            this.ViewState["StuffUserID"] = stuffUser.StuffUserId;
            if (rowForm.InTurnUserIds.Contains("P" + stuffUser.StuffUserId + "P")) {
                this.SubmitBtn.Visible = true;
                this.cwfAppCheck.IsView = false;
                this.ViewState["IsView"] = false;
            } else {
                this.SubmitBtn.Visible = false;
                this.cwfAppCheck.IsView = true;
                this.ViewState["IsView"] = true;
            }

            if (rowForm.StatusID == (int)SystemEnums.FormStatus.Rejected && stuffUser.StuffUserId == rowForm.UserID) {
                this.EditBtn.Visible = true;
                this.ScrapBtn.Visible = true;
            } else {
                this.EditBtn.Visible = false;
                this.ScrapBtn.Visible = false;
            }

            //如果是弹出,取消按钮不可见
            if (this.Request["ShowDialog"] != null) {
                if (this.Request["ShowDialog"].ToString() == "1") {
                    this.upButton.Visible = false;
                    this.Master.FindControl("divMenu").Visible = false;
                    this.Master.FindControl("tbCurrentPage").Visible = false;
                }
            }

            //查看报销单按钮
            if (rowForm.StatusID == (int)SystemEnums.FormStatus.ApproveCompleted) {
                this.IsVisible = "";
            } else {
                this.IsVisible = "none";
            }

            FormDS.FormDeliveryGoodsDataTable tbDelivery = new FormSaleBLL().GetFormDeliveryGoodByFormID(formID);
            if (tbDelivery.Count > 0) {
                this.gvDeliveryInfo.DataSource = tbDelivery;
                this.gvDeliveryInfo.DataBind();
            } else {
                this.divDeliveryInfo.Visible = false;
                this.gvDeliveryInfo.Visible = false;
            }

            //是否显示报销完成按钮
            this.CloseBtn.Visible = false;
            if ((!rowFormApply.IsClose) && rowForm.StatusID == (int)SystemEnums.FormStatus.ApproveCompleted) {
                if (stuffUser.StuffUserId == rowForm.UserID || new AuthorizationBLL().GetProxyReimburseByParameter(rowForm.UserID, stuffUser.StuffUserId, rowForm.SubmitDate).Count > 0) {
                    this.CloseBtn.Visible = true;
                }
            }

            //发货完成按钮权限
            int opManageId = BusinessUtility.GetBusinessOperateId(SystemEnums.BusinessUseCase.DeliveryComplete, SystemEnums.OperateEnum.Other);
            PositionRightBLL positionRightBLL = new PositionRightBLL();
            bool hasManageRight = positionRightBLL.CheckPositionRight(position.PositionId, opManageId);
            if (hasManageRight && (rowFormApply.IsIsDeliveryCompleteNull() || rowFormApply.IsDeliveryComplete == false)) {
                this.DeliveryCompleteBtn.Visible = true;
            } else {
                this.DeliveryCompleteBtn.Visible = false;
            }
        }

        //查看预算权限
        int opViewId = BusinessUtility.GetBusinessOperateId(SystemEnums.BusinessUseCase.ViewBudget, SystemEnums.OperateEnum.Manage);
        bool HasManageRight = new PositionRightBLL().CheckPositionRight(position.PositionId, opViewId);
        this.divBudgetInfo.Visible = HasManageRight;
        this.divBudgetInfoTitle.Visible = HasManageRight;

        //流程控件赋值
        this.cwfAppCheck.FormID = (int)this.ViewState["ObjectId"];
        this.cwfAppCheck.ProcID = this.ViewState["ProcID"].ToString();
        this.cwfAppCheck.IsView = (bool)this.ViewState["IsView"];
    }
    protected void gvApplyList_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Apply") {
            String[] param = e.CommandArgument.ToString().Split(',');
            int FormID = Convert.ToInt32(param[0]);
            decimal ApplyAmount = Convert.ToDecimal(param[1]);
            int PageType = Convert.ToInt32(param[2]);
            FormDS.FormSaleApplyRow formApply = new FormSaleBLL().GetFormSaleApplyByID(FormID)[0];
            MasterDataBLL masterBLL = new MasterDataBLL();
            MasterData.ExpenseCategoryRow ecr = masterBLL.GetExpenseCategoryById(masterBLL.GetExpenseSubCategoryById(formApply.ExpenseSubCategoryID).ExpenseCategoryID);

            decimal NeedCreatePOAmount = Convert.ToDecimal(ConfigurationManager.AppSettings["NeedCreatePOAmount"]);
            if (ApplyAmount > NeedCreatePOAmount && ecr.NeedPO) {
                if (FormPurchaseBLL.QueryPOCountByParentFormID(FormID) <= 0) {
                    PageUtility.ShowModelDlg(this, String.Format("���������{0}�������ȴ���PO!", NeedCreatePOAmount), String.Format("You need create po first when amount more than {0}!", NeedCreatePOAmount));
                    return;
                }
            }
            if (PageType == (int)SystemEnums.PageType.ActivityApply) {
                if (this.ViewState["SearchCondition"] != null) {
                    this.Response.Redirect("~/FormSale/ActivityAdvancedPaymentApply.aspx?FormSaleApplyID=" + FormID + "&Source=" + HttpUtility.UrlEncode("~/FormSale/SaleApplySelectListForAdvanced.aspx?" + this.ViewState["SearchCondition"].ToString()));
                } else {
                    this.Response.Redirect("~/FormSale/ActivityAdvancedPaymentApply.aspx?FormSaleApplyID=" + FormID + "&Source=" + HttpUtility.UrlEncode("~/FormSale/SaleApplySelectListForAdvanced.aspx"));
                }
            } else {
                if (this.ViewState["SearchCondition"] != null) {
                    this.Response.Redirect("~/FormSale/NoActivityAdvancedPaymentApply.aspx?FormSaleApplyID=" + FormID + "&Source=" + HttpUtility.UrlEncode("~/FormSale/SaleApplySelectListForAdvanced.aspx?" + this.ViewState["SearchCondition"].ToString()));
                } else {
                    this.Response.Redirect("~/FormSale/NoActivityAdvancedPaymentApply.aspx?FormSaleApplyID=" + FormID + "&Source=" + HttpUtility.UrlEncode("~/FormSale/SaleApplySelectListForAdvanced.aspx"));
                }
            }
        }
    }
 public void SaveDataToDB(string FullPath, string FileName, string RealFileName)
 {
     try {
         DataTable l_dt = null;
         LogBLL logbll = new LogBLL();
         FormSaleBLL Formsalebll = new FormSaleBLL();
         FormSampleRequestBLL formsamplerequestbll = new FormSampleRequestBLL();
         int stuffuserID = ((AuthorizationDS.StuffUserRow)Session["StuffUser"]).StuffUserId;
         l_dt = this.GetDataSet(FullPath).Tables[0];
         if (l_dt.Rows.Count < 1) {
             PageUtility.ShowModelDlg(this.Page, "文件中没有任何记录,请重新选择");
             return;
         }
         List<int> FormIDs = new List<int>();
         int logId = logbll.InsertImportLog(3, RealFileName, stuffuserID, 0, 0, 0);
         int SuccessCount = 0;
         int FailCount = 0;
         int TotalCount = l_dt.Rows.Count - 1;
         for (int i = 1; i < l_dt.Rows.Count; i++) {
             try {
                 string l_strMaaNumber = l_dt.Rows[i][0].ToString();
                 string l_strSKUNo = l_dt.Rows[i][1].ToString();
                 string l_strPrice = l_dt.Rows[i][2].ToString();
                 string l_strDeliveryNo = l_dt.Rows[i][3].ToString();
                 string l_strQuantity = l_dt.Rows[i][4].ToString();
                 string l_strAmountRMB = l_dt.Rows[i][5].ToString();
                 string l_strDeliveryDate = l_dt.Rows[i][6].ToString();
                 int SkuID = 0;
                 int FormID = 0;
                 decimal Price = 0;
                 decimal AmountRMB = 0;
                 decimal Quantity = 0;
                 DateTime DeliveryDate = DateTime.Now;
                 if (string.IsNullOrEmpty(l_strMaaNumber) && string.IsNullOrEmpty(l_strSKUNo) && string.IsNullOrEmpty(l_strPrice) &&
                     string.IsNullOrEmpty(l_strDeliveryNo) && string.IsNullOrEmpty(l_strQuantity) && string.IsNullOrEmpty(l_strAmountRMB) &&
                     string.IsNullOrEmpty(l_strDeliveryDate)) {
                     TotalCount--;
                     continue;
                 }
                 if (string.IsNullOrEmpty(l_strMaaNumber) || string.IsNullOrEmpty(l_strSKUNo) || string.IsNullOrEmpty(l_strPrice) ||
                     string.IsNullOrEmpty(l_strDeliveryNo) || string.IsNullOrEmpty(l_strQuantity) || string.IsNullOrEmpty(l_strAmountRMB) ||
                     string.IsNullOrEmpty(l_strDeliveryDate)) {
                     logbll.InsertImportLogDetail(logId, i, "数据有空列,导入失败!");
                     FailCount++;
                     continue;
                 }
                 FormDS.FormDataTable l_dtForm = Formsalebll.GetDataByFormNo(l_strMaaNumber);
                 if (l_dtForm.Rows.Count == 0) {
                     logbll.InsertImportLogDetail(logId, i, "未找到MAA号:" + l_strMaaNumber + "的单据,导入失败!");
                     FailCount++;
                     continue;
                 } else {
                     FormID = l_dtForm[0].FormID;
                 }
                 MasterData.SKUDataTable l_dtSKU = new MasterDataBLL().GetSKUBySKUNo(l_strSKUNo);
                 if (l_dtSKU.Rows.Count == 0) {
                     logbll.InsertImportLogDetail(logId, i, "未找到此SKU:" + l_strSKUNo + " NUMBER 下的SKU,导入失败!");
                     FailCount++;
                     continue;
                 } else {
                     SkuID = l_dtSKU[0].SKUID;
                 }
                 //价格是成本价,进入系统应该是
                 try {
                     Price = decimal.Round(decimal.Parse(l_strPrice) * (decimal)1.1 * (decimal)1.17, 2);
                 } catch {
                     logbll.InsertImportLogDetail(logId, i, "单价错误,导入失败!");
                     FailCount++;
                     continue;
                 }
                 try {
                     Quantity = decimal.Parse(l_strQuantity);
                 } catch {
                     logbll.InsertImportLogDetail(logId, i, "数量错误,导入失败!");
                     FailCount++;
                     continue;
                 }
                 try {
                     AmountRMB = Price * Quantity;
                 } catch {
                     logbll.InsertImportLogDetail(logId, i, "发货金额,导入失败!");
                     FailCount++;
                     continue;
                 }
                 try {
                     DeliveryDate = DateTime.Parse(l_strDeliveryDate);
                 } catch {
                     logbll.InsertImportLogDetail(logId, i, "日期错误,导入失败!");
                     FailCount++;
                     continue;
                 }
                 if (string.IsNullOrEmpty(l_strDeliveryNo)) {
                     logbll.InsertImportLogDetail(logId, i, "订单号为空,导入失败!");
                     FailCount++;
                     continue;
                 }
                 int result = 0;
                 FormDS.FormDeliveryGoodsDataTable l_dtFormDeliveryGoods = Formsalebll.GetDataByDeliveryNoAndSkuID(l_strDeliveryNo, SkuID, l_strMaaNumber);
                 if (l_dtFormDeliveryGoods.Rows.Count > 0) {
                     result = Formsalebll.UpdateFormDeliveryGoods(int.Parse(l_dtFormDeliveryGoods.Rows[0][0].ToString()), l_strDeliveryNo, DeliveryDate, Price, Quantity, AmountRMB);
                     if (result == 0) {
                         logbll.InsertImportLogDetail(logId, i, "数据更新失败!");
                         FailCount++;
                         continue;
                     }
                 } else {
                     result = Formsalebll.InsertFormDeliveryGoods(FormID, SkuID, l_strDeliveryNo, DeliveryDate, Price, Quantity, AmountRMB);
                     if (result == 0) {
                         logbll.InsertImportLogDetail(logId, i, "数据插入失败!");
                         FailCount++;
                         continue;
                     }
                 }
                 FormIDs.Add(FormID);
                 SuccessCount++;
             } catch (Exception ee) {
                 logbll.InsertImportLogDetail(logId, i, ee.Message);
                 FailCount++;
                 continue;
             }
         }
         logbll.UpdateImportLog(logId, 3, RealFileName, stuffuserID, TotalCount, SuccessCount, FailCount);
         this.odsApplyList.SelectParameters["queryExpression"].DefaultValue = string.Format(" LogId='{0}'", logId);
         gvFaillist.Visible = true;
         this.odsFailList.SelectParameters["logId"].DefaultValue = logId.ToString();
         gvFaillist.DataBind();
         string returnString = "成功导入" + TotalCount.ToString() + "条信息,其中成功" + SuccessCount.ToString() + "条,失败" + FailCount.ToString() + "条";
         foreach (int formID in FormIDs) {
             formsamplerequestbll.UpdateFormAfterDeliveryComplete(formID, stuffuserID);
         }
         PageUtility.ShowModelDlg(this.Page, returnString);
     } catch (Exception e) {
         throw e;
     }
 }
Example #15
0
        public void UpdateMarketingApplyAfterDeliveryComplete(int FormID, int UserID)
        {
            SqlTransaction transaction = null;
            try {
                transaction = TableAdapterHelper.BeginTransaction(TAFormMarketingApply);
                TableAdapterHelper.SetTransaction(TAFormMarketingApplyDetail, transaction);
                FormDS.FormMarketingApplyRow rowApply = this.TAFormMarketingApply.GetDataByID(FormID)[0];
                FormDS.FormDeliveryGoodsDataTable tbDelivery = new FormSaleBLL().GetFormDeliveryGoodByFormID(FormID);
                FormDS.FormMarketingApplyDetailDataTable tbApplyDetail = this.GetFormMarketingApplyDetailByMarketingApplyID(FormID);
                //发货总金额
                decimal DeliveryAmount = 0;
                //申请总金额
                decimal ApplyAmount = rowApply.AmountRMB;
                //已分配金额,按比例分配的最后一项,要用申请金额-已分配金额
                decimal UsedAmount = 0;
                foreach (FormDS.FormDeliveryGoodsRow item in tbDelivery) {
                    DeliveryAmount += item.AmountRMB;
                }

                if (tbApplyDetail.Count > 0) {
                    //FormDS.FormMarketingApplyDetailRow rowExpenseDetail = null;
                    for (int i = 0; i < tbApplyDetail.Count; i++) {
                        FormDS.FormMarketingApplyDetailRow rowExpenseDetail = tbApplyDetail[i];
                        if (i == tbApplyDetail.Count - 1) {
                            rowExpenseDetail.GoodAmount = DeliveryAmount - UsedAmount;
                        } else {
                            rowExpenseDetail.GoodAmount = decimal.Round(DeliveryAmount * (rowExpenseDetail.AmountRMB / ApplyAmount), 2);
                            UsedAmount += rowExpenseDetail.GoodAmount;
                        }
                    }
                }
                this.TAFormMarketingApplyDetail.Update(tbApplyDetail);
                rowApply.IsDeliveryComplete = true;
                rowApply.DeliveryCompleteDate = DateTime.Now;
                rowApply.DeliveryCompleteUserID = UserID;
                //rowApply.IsClose = true;
                //rowApply.CloseDate = DateTime.Now;
                this.TAFormMarketingApply.Update(rowApply);
                transaction.Commit();
            } catch (Exception) {
                throw;
            }
        }