コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!(null == Session["totleAuthority"]))
            {
                AuthAttributes usrAuthAttr = (AuthAttributes)Session["totleAuthority"];

                bool flag = usrAuthAttr.HasOneFlag(AuthAttributes.pay_receiptApply);
                if (!flag)
                {
                    Response.Redirect("~/Main/NoAuthority.aspx");
                }
            }
            else
            {
                string url = Request.FilePath;
                Session["backUrl"] = url;
                Response.Redirect("~/Account/Login.aspx");
            }

            if (null == Session["seldMainContract"])
            {
                Response.Redirect("~/Main/paymentReceiptManager/mainContractReceiptView.aspx");
            }

            if (!IsPostBack)
            {
                //DataRow sessionDr = Session["seldMainContract"] as DataRow;

                //System.Nullable<int> mainContractId = int.Parse(sessionDr["mainContractId"].ToString());

                //string selfReceipt = sessionDr["selfReceiptPercent"].ToString();

                int receiptId = int.Parse(Session["receiptId"] as string);

                Xm_db xmDataCont = Xm_db.GetInstance();

                var receiptApplyEdit =
                    (from receiptApply in xmDataCont.Tbl_receiptApply
                     where receiptApply.ReceiptId == receiptId
                     select receiptApply).First();

                float selfReceipt = receiptApplyEdit.HasReceiptPercent;
                System.Nullable <int>   mainContractId = receiptApplyEdit.MainContractId;
                System.Nullable <float> maxRtn         = 0;
                int rtn = xmDataCont.SubContract_MaxReceipt(mainContractId, ref maxRtn);

                lblSubContractReceipt.Text = maxRtn.Value.ToString("p");

                lblMainContractReceipt.Text = selfReceipt.ToString("p");

                //#region ddlSelfReceipt
                //ListItemCollection licNomal = new ListItemCollection();
                //int num = 0;
                //int max = int.Parse(maxReceipt) - int.Parse(selfReceipt) + 5;
                //string strValue = string.Empty;
                //string strPercent = "%";
                //string strText = string.Empty;
                //for (int i = num; i < max; i = i + 5)
                //{
                //    strValue = i.ToString();

                //    strText = strValue + strPercent;

                //    licNomal.Add(strText);
                //}

                //ListItemCollection licSpecial = new ListItemCollection();
                //num = max;
                //max = 110 - max;
                //strValue = string.Empty;
                //strText = string.Empty;
                //for (int i = num; i < max; i = i + 5)
                //{
                //    strValue = i.ToString();

                //    strText = strValue + strPercent;

                //    licSpecial.Add(strText);
                //}

                //Session["licNomal"] = licNomal;
                //Session["licSpecial"] = licSpecial;
                //#endregion

                Session["maxReceipt"] = maxRtn.Value;

                #region ddlSelfReceipt
                DataTable dtNomal = new DataTable();
                dtNomal.Columns.Add("DataTextField", Type.GetType("System.String"));
                dtNomal.Columns.Add("DataValueField", Type.GetType("System.Single"));

                float num = 0;
                float max = maxRtn.Value - selfReceipt + 0.05f;
                max = max <= 0.05f ? 0.05f : max;
                DataRow dr = null;
                for (float i = num; i < max; i = i + 0.05f)
                {
                    dr = dtNomal.NewRow();
                    dr["DataTextField"]  = i.ToString("p");
                    dr["DataValueField"] = i;
                    dtNomal.Rows.Add(dr);
                }

                DataTable dtSpecial = new DataTable();
                dtSpecial.Columns.Add("DataTextField", Type.GetType("System.String"));
                dtSpecial.Columns.Add("DataValueField", Type.GetType("System.Single"));

                num = 0;
                max = 1.05f - selfReceipt;
                dr  = null;
                for (float i = num; i < max; i = i + 0.05f)
                {
                    dr = dtSpecial.NewRow();
                    dr["DataTextField"]  = i.ToString("p");
                    dr["DataValueField"] = i;
                    dtSpecial.Rows.Add(dr);
                    //licNomal.Add(new ListItem(i.ToString("p"), i.ToString()));
                }

                Session["dtNomal"]   = dtNomal;
                Session["dtSpecial"] = dtSpecial;
                #endregion

                ddlSelfReceipt.DataSource     = Session["dtNomal"];
                ddlSelfReceipt.DataValueField = "DataValueField";
                ddlSelfReceipt.DataTextField  = "DataTextField";

                ddlSelfReceipt.DataBind();
                ddlSelfReceipt.SelectedIndex = 0;

                txtReceiptExplication.Text = receiptApplyEdit.ReceiptExplication;
            }
        }