Beispiel #1
0
    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);

            // 用户信息,职位信息
            AuthorizationDS.StuffUserRow stuffUser = (AuthorizationDS.StuffUserRow)Session["StuffUser"];
            AuthorizationDS.PositionRow rowUserPosition = (AuthorizationDS.PositionRow)Session["Position"];

            if (new StuffUserBLL().GetCostCenterIDByPositionID(rowUserPosition.PositionId) == 0) {
                this.Session["ErrorInfor"] = "未找到成本中心,请联系管理员";
                Response.Redirect("~/ErrorPage/SystemErrorPage.aspx");
            }
            this.ViewState["StuffUserID"] = stuffUser.StuffUserId;
            this.ViewState["PositionID"] = rowUserPosition.PositionId;

            this.StuffNameCtl.Text = CommonUtility.GetStaffFullName(stuffUser);
            this.PositionNameCtl.Text = rowUserPosition.PositionName;
            this.DepartmentNameCtl.Text = new OUTreeBLL().GetOrganizationUnitById(rowUserPosition.OrganizationUnitId).OrganizationUnitName;
            this.ViewState["DepartmentID"] = rowUserPosition.OrganizationUnitId;
            this.StuffNoCtl.Text = stuffUser.IsStuffNoNull() ? "" : stuffUser.StuffNo;
            this.AttendDateCtl.Text = stuffUser.AttendDate.ToShortDateString();

            if (this.Request["RejectObjectID"] != null) {
                this.ViewState["RejectedObjectID"] = int.Parse(this.Request["RejectObjectID"].ToString());
            }

            if (Request["ObjectId"] != null) {
                this.ViewState["ObjectId"] = int.Parse(Request["ObjectId"]);
                if (this.Request["RejectObjectID"] == null) {
                    this.DeleteBtn.Visible = true;
                } else {
                    this.DeleteBtn.Visible = false;
                }
                PurchaseDS.FormPORow rowFormPO = this.FormPurchaseBLL.GetFormPOByID(int.Parse(this.ViewState["ObjectId"].ToString()));
                this.ViewState["ParentFormID"] = rowFormPO.ParentFormID;
                this.ViewState["Period"] = rowFormPO.FPeriod.ToShortDateString();
                this.PeriodCtl.Text = rowFormPO.FPeriod.ToString("yyyy-MM");
                this.ViewState["VendorID"] = rowFormPO.VendorID.ToString();
                this.ViewState["ItemCategoryID"] = rowFormPO.ItemCategoryID.ToString();
                this.ViewState["PurchaseBudgetTypeID"] = rowFormPO.PurchaseBudgetTypeID.ToString();
                this.ViewState["CurrencyID"] = rowFormPO.CurrencyID.ToString();

                this.PurchaseTypeDDL.SelectedValue = rowFormPO.PurchaseTypeID.ToString();
                this.ShippingTermDDL.SelectedValue = rowFormPO.ShippingTermID.ToString();
                this.PaymentTermCtl.Text = rowFormPO.IsPaymentTermsNull() ? "" : rowFormPO.PaymentTerms;
                if (!rowFormPO.IsCompanyIDNull()) {
                    this.CompanyDDL.SelectedValue = rowFormPO.CompanyID.ToString();
                }
                this.RemarkCtl.Text = rowFormPO.IsRemarkNull() ? "" : rowFormPO.Remark;
                if (!rowFormPO.IsAttachedFileNameNull())
                    this.UCFileUpload.AttachmentFileName = rowFormPO.AttachedFileName;
                if (!rowFormPO.IsRealAttachedFileNameNull())
                    this.UCFileUpload.RealAttachmentFileName = rowFormPO.RealAttachedFileName;

                this.RealDeliveryAddressCtl.Text = rowFormPO.IsRealDeliveryAddressNull() ? "" : rowFormPO.RealDeliveryAddress;

                new FormPODetailTableAdapter().FillByFormPOID(this.InnerDS.FormPODetail, rowFormPO.FormPOID);
            } else {
                this.DeleteBtn.Visible = false;
                if (Request["ParentFormID"] != null) {
                    this.ViewState["ParentFormID"] = Request["ParentFormID"];
                } else {
                    this.Session["ErrorInfor"] = "未找到申请单,请联系管理员";
                    Response.Redirect("~/ErrorPage/SystemErrorPage.aspx");
                }
                if (Request["PeriodPurchaseID"] != null) {
                    DateTime Period = new MasterDataBLL().GetPeriodPurchaseById(int.Parse(Request["PeriodPurchaseID"].ToString())).PeriodPurchase;
                    this.ViewState["Period"] = Period.ToShortDateString();
                } else {
                    this.Session["ErrorInfor"] = "没有费用期间,请联系管理员";
                    Response.Redirect("~/ErrorPage/SystemErrorPage.aspx");
                }
                if (Request["VendorID"] != null) {
                    this.ViewState["VendorID"] = Request["VendorID"];
                } else {
                    this.Session["ErrorInfor"] = "未找到Vendor,请联系管理员";
                    Response.Redirect("~/ErrorPage/SystemErrorPage.aspx");
                }
                if (Request["ItemCategoryID"] != null) {
                    this.ViewState["ItemCategoryID"] = Request["ItemCategoryID"];
                } else {
                    this.Session["ErrorInfor"] = "未找到Item Category,请联系管理员";
                    Response.Redirect("~/ErrorPage/SystemErrorPage.aspx");
                }
                if (Request["PurchaseBudgetTypeID"] != null) {
                    this.ViewState["PurchaseBudgetTypeID"] = Request["PurchaseBudgetTypeID"];
                } else {
                    this.Session["ErrorInfor"] = "未找到预算类型,请联系管理员";
                    Response.Redirect("~/ErrorPage/SystemErrorPage.aspx");
                }
                if (Request["CurrencyID"] != null) {
                    this.ViewState["CurrencyID"] = Request["CurrencyID"];
                } else {
                    this.Session["ErrorInfor"] = "未找到币种,请联系管理员";
                    Response.Redirect("~/ErrorPage/SystemErrorPage.aspx");
                }

                this.PeriodCtl.Text = DateTime.Parse(this.ViewState["Period"].ToString()).ToString("yyyy-MM");
                MasterData.VendorRow vendor = new MasterDataBLL().GetVendorByID(int.Parse(this.ViewState["VendorID"].ToString()));
                MasterData.PaymentTermRow paymentTerm = new MasterDataBLL().GetPaymentTermById(vendor.PaymentTermID)[0];
                if (paymentTerm != null && !paymentTerm.IsPaymentTermNameNull()) {
                    this.PaymentTermCtl.Text = paymentTerm.PaymentTermName;
                }
            }
            MasterData.VendorRow vendor1 = new VendorTableAdapter().GetDataByID(int.Parse(this.ViewState["VendorID"].ToString()))[0];
            this.VendorCodeCtl.Text = vendor1.VendorCode;
            this.VendorNameCtl.Text = vendor1.VendorName;
            this.VendorAddressCtl.Text = vendor1.VendorAddress;

            this.ItemCategoryCtl.Text = new ItemCategoryTableAdapter().GetDataByID(int.Parse(this.ViewState["ItemCategoryID"].ToString()))[0].ItemCategoryName;
            this.CurrencyCtl.Text = new CurrencyTableAdapter().GetDataByID(int.Parse(this.ViewState["CurrencyID"].ToString()))[0].CurrencyShortName;
            this.PurchaseBudgetTypeCtl.Text = new PurchaseBudgetTypeTableAdapter().GetDataByID(int.Parse(this.ViewState["PurchaseBudgetTypeID"].ToString()))[0].PurchaseBudgetTypeName;
            this.ViewState["ExchangeRate"] = new MasterDataBLL().GetExchangeRateByPeriod(int.Parse(ViewState["CurrencyID"].ToString()), DateTime.Parse(ViewState["Period"].ToString()));
            if (decimal.Parse(this.ViewState["ExchangeRate"].ToString()) == 0) {
                this.Session["ErrorInfor"] = "未找到汇率,请联系管理员";
                Response.Redirect("~/ErrorPage/SystemErrorPage.aspx");
            }
            this.ExchangeRateCtl.Text = this.ViewState["ExchangeRate"].ToString();

            //判断费用期间是否正确
            MasterDataBLL bll = new MasterDataBLL();
            if (!new MasterDataBLL().IsValidPeriodPurchase(DateTime.Parse(this.ViewState["Period"].ToString()))) {
                this.SubmitBtn.Visible = false;
                PageUtility.ShowModelDlg(this, "不允许申请本月项目,请删除草稿并联系财务部!");
                return;
            }
            //申请单编号和申请单金额
            PurchaseDS.FormRow applyFormRow = this.FormPurchaseBLL.GetFormByID(int.Parse(this.ViewState["ParentFormID"].ToString()))[0];
            this.ApplyFormNoCtl.Text = applyFormRow.FormNo;
            this.ViewState["ParentFormNo"] = applyFormRow.FormNo;
            string url = string.Empty;
            switch (applyFormRow.PageType) {
                case (int)SystemEnums.PageType.ActivityApply:
                    url = "/FormSale/ActivityApproval.aspx?ShowDialog=1&ObjectId=" + applyFormRow.FormID;
                    this.ViewState["POType"] = SystemEnums.POType.Sale;
                    this.ViewState["ApplyAmountRMB"] = new FormSaleBLL().GetFormSaleApplyByID(applyFormRow.FormID)[0].AmountRMB;
                    break;
                case (int)SystemEnums.PageType.NoActivityApply:
                    url = "/FormSale/NoActivityApproval.aspx?ShowDialog=1&ObjectId=" + applyFormRow.FormID;
                    this.ViewState["POType"] = SystemEnums.POType.Sale;
                    this.ViewState["ApplyAmountRMB"] = new FormSaleBLL().GetFormSaleApplyByID(applyFormRow.FormID)[0].AmountRMB;
                    break;
                case (int)SystemEnums.PageType.FormMarketingApply:
                    url = "/FormMarketing/MarketingApproval.aspx?ShowDialog=1&ObjectId=" + applyFormRow.FormID;
                    this.ViewState["POType"] = SystemEnums.POType.Marketing;
                    this.ViewState["ApplyAmountRMB"] = new FormMarketingBLL().GetFormMarketingApplyByID(applyFormRow.FormID)[0].AmountRMB;
                    break;
                case (int)SystemEnums.PageType.RDApply:
                    url = "/FormRD/RDApproval.aspx?ShowDialog=1&ObjectId=" + applyFormRow.FormID;
                    this.ViewState["POType"] = SystemEnums.POType.RD;
                    this.ViewState["ApplyAmountRMB"] = new FormRDBLL().GetFormRDApplyByID(applyFormRow.FormID)[0].AmountRMB;
                    break;
            }

            this.ApplyFormNoCtl.NavigateUrl = "javascript:window.showModalDialog('" + System.Configuration.ConfigurationManager.AppSettings["WebSiteUrl"] + url + "','', 'dialogWidth:1000px;dialogHeight:750px;resizable:yes;')";
            this.ApplyAmountCtl.Text = this.ViewState["ApplyAmountRMB"].ToString();

        }
    }