/// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Dianda.Model.Cash_CardsDetail GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ID,CardID,DetailID,Balance,Unit,TypesName,Oldbalance,KYbalance,DetailName from Cash_CardsDetail ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ID;

            Dianda.Model.Cash_CardsDetail model = new Dianda.Model.Cash_CardsDetail();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CardID"] != null && ds.Tables[0].Rows[0]["CardID"].ToString() != "")
                {
                    model.CardID = int.Parse(ds.Tables[0].Rows[0]["CardID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["DetailID"] != null && ds.Tables[0].Rows[0]["DetailID"].ToString() != "")
                {
                    model.DetailID = int.Parse(ds.Tables[0].Rows[0]["DetailID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Balance"] != null && ds.Tables[0].Rows[0]["Balance"].ToString() != "")
                {
                    model.Balance = decimal.Parse(ds.Tables[0].Rows[0]["Balance"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Unit"] != null && ds.Tables[0].Rows[0]["Unit"].ToString() != "")
                {
                    model.Unit = int.Parse(ds.Tables[0].Rows[0]["Unit"].ToString());
                }
                if (ds.Tables[0].Rows[0]["TypesName"] != null && ds.Tables[0].Rows[0]["TypesName"].ToString() != "")
                {
                    model.TypesName = ds.Tables[0].Rows[0]["TypesName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Oldbalance"] != null && ds.Tables[0].Rows[0]["Oldbalance"].ToString() != "")
                {
                    model.Oldbalance = decimal.Parse(ds.Tables[0].Rows[0]["Oldbalance"].ToString());
                }
                if (ds.Tables[0].Rows[0]["KYbalance"] != null && ds.Tables[0].Rows[0]["KYbalance"].ToString() != "")
                {
                    model.KYbalance = decimal.Parse(ds.Tables[0].Rows[0]["KYbalance"].ToString());
                }
                if (ds.Tables[0].Rows[0]["DetailName"] != null && ds.Tables[0].Rows[0]["DetailName"].ToString() != "")
                {
                    model.DetailName = ds.Tables[0].Rows[0]["DetailName"].ToString();
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Dianda.Model.Cash_CardsDetail model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Cash_CardsDetail set ");
            strSql.Append("CardID=@CardID,");
            strSql.Append("DetailID=@DetailID,");
            strSql.Append("Balance=@Balance,");
            strSql.Append("Unit=@Unit,");
            strSql.Append("TypesName=@TypesName,");
            strSql.Append("Oldbalance=@Oldbalance,");
            strSql.Append("KYbalance=@KYbalance,");
            strSql.Append("DetailName=@DetailName");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@CardID",     SqlDbType.Int,       4),
                new SqlParameter("@DetailID",   SqlDbType.Int,       4),
                new SqlParameter("@Balance",    SqlDbType.Float,     8),
                new SqlParameter("@Unit",       SqlDbType.Int,       4),
                new SqlParameter("@TypesName",  SqlDbType.VarChar,  50),
                new SqlParameter("@Oldbalance", SqlDbType.Float,     8),
                new SqlParameter("@KYbalance",  SqlDbType.Float,     8),
                new SqlParameter("@DetailName", SqlDbType.NVarChar,  8),
                new SqlParameter("@ID",         SqlDbType.Int, 4)
            };
            parameters[0].Value = model.CardID;
            parameters[1].Value = model.DetailID;
            parameters[2].Value = model.Balance;
            parameters[3].Value = model.Unit;
            parameters[4].Value = model.TypesName;
            parameters[5].Value = model.Oldbalance;
            parameters[6].Value = model.KYbalance;
            parameters[7].Value = model.DetailName;
            parameters[8].Value = model.ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Dianda.Model.Cash_CardsDetail model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Cash_CardsDetail(");
            strSql.Append("CardID,DetailID,Balance,Unit,TypesName,Oldbalance,KYbalance,DetailName)");
            strSql.Append(" values (");
            strSql.Append("@CardID,@DetailID,@Balance,@Unit,@TypesName,@Oldbalance,@KYbalance,@DetailName)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@CardID",     SqlDbType.Int,       4),
                new SqlParameter("@DetailID",   SqlDbType.Int,       4),
                new SqlParameter("@Balance",    SqlDbType.Float,     8),
                new SqlParameter("@Unit",       SqlDbType.Int,       4),
                new SqlParameter("@TypesName",  SqlDbType.VarChar,  50),
                new SqlParameter("@Oldbalance", SqlDbType.Float,     8),
                new SqlParameter("@KYbalance",  SqlDbType.Float,     8),
                new SqlParameter("@DetailName", SqlDbType.NVarChar, 8)
            };
            parameters[0].Value = model.CardID;
            parameters[1].Value = model.DetailID;
            parameters[2].Value = model.Balance;
            parameters[3].Value = model.Unit;
            parameters[4].Value = model.TypesName;
            parameters[5].Value = model.Oldbalance;
            parameters[6].Value = model.KYbalance;
            parameters[7].Value = model.DetailName;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
        /// <summary>
        ///点击确定按钮触发的事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button_sumbit_Click(object sender, EventArgs e)
        {
            try
            {
                // string NAME = this.txtControlInfo.Text;//获取到资金卡名称

                //资金调整说明
                string  NAME  = "";
                decimal money = 0;

                foreach (GridViewRow item in GridView1.Rows)
                {
                    Label       la          = (Label)item.FindControl("Label_Name");
                    TextBox     tx          = (TextBox)item.FindControl("txtBalance");
                    Label       lb          = (Label)item.FindControl("LB_Balance");
                    HiddenField HF_DetailID = (HiddenField)item.FindControl("HF_DetailID");
                    string      ID          = GridView1.DataKeys[item.RowIndex].Value.ToString();
                    string      cashmoney   = "";

                    Model.Cash_CardsDetail CardDetail_model = new Dianda.Model.Cash_CardsDetail();
                    BLL.Cash_CardsDetail   CardDetail_bll   = new Dianda.BLL.Cash_CardsDetail();
                    CardDetail_model = CardDetail_bll.GetModel(int.Parse(HF_DetailID.Value));

                    if (rblDoType.SelectedValue == "2")
                    {
                        //if (double.Parse(tx.Text.ToString()) > double.Parse(lb.Text.ToString()))
                        //{
                        //    tag.Text = la.Text + "减少的金额不能大于可用金额!";
                        //    tag2.Text = la.Text + "减少的金额不能大于可用金额!";
                        //    return;
                        //}

                        if (decimal.Parse(tx.Text) == 0)
                        {
                            cashmoney = tx.Text;
                        }
                        else
                        {
                            cashmoney = "-" + tx.Text;
                        }
                        //在原来该细目的可用金额基础上减去输入的值 
                        CardDetail_model.Balance = Decimal.Parse(CardDetail_model.Balance.ToString()) - Decimal.Parse(tx.Text.ToString());
                        CardDetail_bll.Update(CardDetail_model);
                    }
                    else
                    {
                        cashmoney = tx.Text;
                        //在原来该细目的可用金额基础上加上输入的值 
                        CardDetail_model.Balance = Decimal.Parse(CardDetail_model.Balance.ToString()) + Decimal.Parse(tx.Text.ToString());
                        CardDetail_bll.Update(CardDetail_model);
                    }

                    NAME  += ID + "," + la.Text + "," + cashmoney + "|";
                    money += decimal.Parse(tx.Text);
                }
                NAME = NAME.Remove(NAME.LastIndexOf("|"));
                if (String.IsNullOrEmpty(NAME))
                {
                    tag.Text  = "调整说明不能为空,请填写调整说明!";
                    tag2.Text = "调整说明不能为空,请填写调整说明!";
                    return;
                }
                mCash_Cards         = new Dianda.Model.Cash_Cards();
                mCash_Cards         = bCash_Cards.GetModel(Int32.Parse(common.cleanXSS(Request["ID"]))); //Cash_Cards的ID)
                mCash_Apply_History = new Dianda.Model.Cash_Apply_History();
                mCash_Apply_History.CashCertificateID = Int32.Parse(common.cleanXSS(Request["ID"]));     //Cash_Cards的ID
                //mCash_Apply_History.ControlInfo = this.txtControlInfo.Text;
                //资金调整说明
                mCash_Apply_History.ControlInfo = NAME;
                if (this.rblDoType.SelectedValue == "1")//增加
                {
                    mCash_Apply_History.Balance = Decimal.Parse(this.lblLimitNums.Text) + money;
                }
                else//减少
                {
                    mCash_Apply_History.Balance = Decimal.Parse(this.lblLimitNums.Text) - money;
                }
                mCash_Apply_History.DATETIME = DateTime.Now;
                mCash_Apply_History.DoUser   = ((Model.USER_Users)Session["USER_Users"]).USERNAME;
                mCash_Apply_History.DoType   = rblDoType.SelectedValue == "1" ? "增加" + money + "元" : "减少" + money + "元";
                mCash_Apply_History.NOTES    = TextBox1.Text;
                bCash_Apply_History.Add(mCash_Apply_History);

                string oldLimitNums = mCash_Cards.LimitNums.ToString();
                //要在对应的资金卡中增加或是减少的可用金额
                if (this.rblDoType.SelectedValue == "1")//增加
                {
                    mCash_Cards.YEBalance = (mCash_Cards.YEBalance + money);
                    //mCash_Cards.TEMP0 = mCash_Cards.TEMP0 + "&nbsp;&nbsp;" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + ",增加" + money + "元,可用金额由" + oldLimitNums + "元调整为" + mCash_Cards.LimitNums + "元<br> ";
                }
                else//减少
                {
                    mCash_Cards.YEBalance = (mCash_Cards.YEBalance - money);
                    //mCash_Cards.TEMP0 = mCash_Cards.TEMP0 + "&nbsp;&nbsp;" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + ",减少" + money + "元,可用金额由" + oldLimitNums + "元调整为" + mCash_Cards.LimitNums + "元<br> ";
                }
                bCash_Cards.Update(mCash_Cards);
                //this.ucshow1.BindData();
                Read_Data(common.cleanXSS(Request["id"].ToString()));

                /*给业务申请者发信息*/
                Model.FaceShowMessage mFaceShowMessage = new Dianda.Model.FaceShowMessage();
                BLL.FaceShowMessage   bFaceShowMessage = new Dianda.BLL.FaceShowMessage();

                mFaceShowMessage.DATETIME  = DateTime.Now;
                mFaceShowMessage.FromTable = "经费";
                mFaceShowMessage.IsRead    = 0;
                mFaceShowMessage.NewsID    = null;
                mFaceShowMessage.NewsType  = "经费";
                mFaceShowMessage.ReadTime  = null;
                mFaceShowMessage.Receive   = mCash_Cards.CardholderID;
                mFaceShowMessage.DELFLAG   = 0;
                mFaceShowMessage.URLS      = ((Model.USER_Users)Session["USER_Users"]).REALNAME + "(" + ((Model.USER_Users)Session["USER_Users"]).USERNAME.ToString() + ")调整了您的资金卡[" + mCash_Cards.CardName + "]!<a href='/Admin/cashCardManage/showHistory.aspx?id=" + Request["ID"] + "' target='_self' title='操作记录查看'>点击查看</a>";
                bFaceShowMessage.Add(mFaceShowMessage);
                /*给业务申请者发信息*/

                tag.Text  = "操作成功!";
                tag2.Text = "操作成功!";

                //添加操作日志
                Dianda.BLL.SYS_LogsExt bsyslog    = new Dianda.BLL.SYS_LogsExt();
                Model.USER_Users       user_model = (Model.USER_Users)Session["USER_Users"];
                bsyslog.addlogs(((Model.USER_Users)Session["USER_Users"]).REALNAME + "(" + ((Model.USER_Users)Session["USER_Users"]).USERNAME + ")", "资金卡调整", "资金卡" + ((rblDoType.SelectedValue == "1") ? "增加" : "减少") + money + "成功");
                //添加操作日志

                if (((Button)sender).ID == "Button_sumbit")
                {
                    string coutws = "<script language=\"javascript\" type=\"text/javascript\">alert(\"操作成功!现在进入明细页面\"); ";
                    if (PageStr == "add")
                    {
                        coutws += "location.href = \"" + _PageAdd1 + ReturnCS() + "\";</script>";
                    }
                    else
                    {
                        coutws += "location.href = \"showHistory.aspx?id=" + common.cleanXSS(Request["id"]) + "&PageRole=manage\";</script>";
                    }
                    Response.Write(coutws);
                }
                else
                {
                    //foreach (GridViewRow item1 in GridView1.Rows)
                    //{
                    //    TextBox tx = (TextBox)item1.FindControl("txtBalance");
                    //    tx.Text = "0";

                    //}
                    ShowDDLControlInfo(common.cleanXSS(Request["id"]));
                    TextBox1.Text = "";
                    //tag.Text = "";
                }
            }
            catch
            {
                tag.Text  = "操作失败,请重试!";
                tag2.Text = "操作失败,请重试!";
            }
        }