private void Datagrid2_UpdateCommand(object source, DataGridCommandEventArgs e)
        {
            string checkcount = ((TextBox)e.Item.Cells[8].Controls[0]).Text.Trim();
            string strmdate   = "";
            string strexpdate = "";
            string strflag    = "";

            if (e.Item.Cells[9].Text.Trim() == "" || e.Item.Cells[9].Text.Trim() == " ")
            {
                strmdate   = ((System.Web.UI.HtmlControls.HtmlInputText)e.Item.Cells[10].Controls[1]).Value;
                strexpdate = ((System.Web.UI.HtmlControls.HtmlInputText)e.Item.Cells[12].Controls[1]).Value;
            }
            else
            {
                strmdate   = e.Item.Cells[9].Text.Trim();
                strexpdate = e.Item.Cells[11].Text.Trim();
            }

            string checkno = e.Item.Cells[0].Text.Trim();

            if (checkcount == "" || !this.JudgeIsNum(checkcount))
            {
                this.Popup("盘点存量不能为空且必须是数字!");
                this.hidecontrol();
                return;
            }
            if (strmdate == "")
            {
                this.Popup("生产日期不能为空!");
                this.hidecontrol();
                return;
            }
            if (strexpdate == "")
            {
                this.Popup("过期日期不能为空!");
                this.hidecontrol();
                return;
            }
            StorageCheckLog scl = new StorageCheckLog();

            scl.cnnSerialNo   = decimal.Parse(e.Item.Cells[1].Text.Trim());
            scl.cnnCheckCount = Math.Round(decimal.Parse(checkcount), 2);
            scl.cnvcOperName  = this.oper.strOperName;
            if (e.Item.Cells[9].Text.Trim() == "" || e.Item.Cells[9].Text.Trim() == " ")
            {
                scl.cndMdate   = DateTime.Parse(strmdate);
                scl.cndExpDate = DateTime.Parse(strexpdate);
                strflag        = "up_date";
                if (scl.cndMdate.CompareTo(scl.cndExpDate) > 0)
                {
                    this.Popup("生产日期不能大于过期日期!");
                    this.hidecontrol();
                    return;
                }
            }
            StorageFacade sto = new StorageFacade();
            int           ret = sto.UpdateStorageCheckLog(scl, strflag);

            if (ret > 0)
            {
                this.Popup("修改盘点存货库存量成功!");
            }
            else
            {
                this.Popup("修改盘点存货库存量失败!");
            }

            this.DBBind();
            this.ddlDept.Enabled       = false;
            this.ddlWhouse.Enabled     = false;
            this.ddlDayCheckNo.Enabled = false;
            this.btnCheckOk.Enabled    = true;
        }
        private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            DataGridItem item = this.DataGrid1.SelectedItem;

            if (this.txtCheckCount.Text.Trim() == "" || !this.JudgeIsNum(this.txtCheckCount.Text.Trim()))
            {
                this.Popup("盘点存量不能为空且必须是数字!");
                return;
            }

            StorageCheckLog scl = new StorageCheckLog();

            scl.cnvcDeptID    = this.ddlDept.SelectedValue;
            scl.cnvcWhCode    = this.ddlWhouse.SelectedValue;
            scl.cnvcInvCode   = item.Cells[0].Text.Trim();
            scl.cnnSysCount   = Math.Round(decimal.Parse(item.Cells[5].Text.Trim()), 2);
            scl.cnnCheckCount = Math.Round(decimal.Parse(this.txtCheckCount.Text.Trim()), 2);
            scl.cnvcUnitCode  = item.Cells[2].Text.Trim();
            scl.cnvcOperName  = this.oper.strOperName;
            scl.cnvcFlag      = "0";
            string strMdate   = "";
            string strExpdate = "";

            if (item.Cells[6].Text.Trim() != "")
            {
                scl.cndMdate = DateTime.Parse(item.Cells[6].Text.Trim());
                strMdate     = scl.cndMdate.Year.ToString();
                if (scl.cndMdate.Month < 10)
                {
                    strMdate += "0" + scl.cndMdate.Month.ToString();
                }
                else
                {
                    strMdate += scl.cndMdate.Month.ToString();
                }
                if (scl.cndMdate.Day < 10)
                {
                    strMdate += "0" + scl.cndMdate.Day.ToString();
                }
                else
                {
                    strMdate += scl.cndMdate.Day.ToString();
                }
            }
            if (item.Cells[7].Text.Trim() != "")
            {
                scl.cndExpDate = DateTime.Parse(item.Cells[7].Text.Trim());
                strExpdate     = scl.cndExpDate.Year.ToString();
                if (scl.cndExpDate.Month < 10)
                {
                    strExpdate += "0" + scl.cndExpDate.Month.ToString();
                }
                else
                {
                    strExpdate += scl.cndExpDate.Month.ToString();
                }
                if (scl.cndExpDate.Day < 10)
                {
                    strExpdate += "0" + scl.cndExpDate.Day.ToString();
                }
                else
                {
                    strExpdate += scl.cndExpDate.Day.ToString();
                }
            }
            string strcheckno = "";

            string strisexist = "";

            if (strMdate == "" && strExpdate == "")
            {
                strisexist = Helper.Query("select count(*) from tbStorageCheckLog where cnvcWhCode='" + scl.cnvcWhCode + "' and cnvcInvCode='" + scl.cnvcInvCode + "' and cnvcFlag='0' and cnvcCheckNo like convert(char(8),getdate(),112)+'%'").Rows[0][0].ToString();
            }
            else
            {
                strisexist = Helper.Query("select count(*) from tbStorageCheckLog where cnvcWhCode='" + scl.cnvcWhCode + "' and cnvcInvCode='" + scl.cnvcInvCode + "' and cnvcFlag='0' and cnvcCheckNo like convert(char(8),getdate(),112)+'%' and convert(char(8),cndMdate,112)='" + strMdate + "' and convert(char(8),cndExpDate,112)='" + strExpdate + "'").Rows[0][0].ToString();
            }
            if (strisexist != "0")
            {
                this.Popup("本仓库的" + item.Cells[1].Text.Trim() + "在今日内还有未确认的盘点记录,不可添加!");
                return;
            }
            else
            {
                StorageFacade sto = new StorageFacade();
                int           ret = sto.AddStorageCheckLog(scl, this.txtCheckNo.Text.Trim(), out strcheckno);
                if (ret > 0)
                {
                    this.Popup("添加盘点存货成功!");
                    this.ddlState.SelectedIndex = this.ddlState.Items.IndexOf(this.ddlState.Items.FindByValue("0"));
                    DataTable dtcheckno = Helper.Query("select distinct cnvcCheckNo as cnvcCode,cnvcCheckNo as cnvcName from tbStorageCheckLog where cnvcWhCode='" + this.ddlWhouse.SelectedValue + "' and cnvcCheckNo like '" + this.txtCheckNo.Text.Trim() + "%'");
                    this.FillDropDownList(dtcheckno, this.ddlDayCheckNo);
                    this.ddlDayCheckNo.SelectedIndex = this.ddlDayCheckNo.Items.IndexOf(this.ddlDayCheckNo.Items.FindByValue(strcheckno));
                    this.ddlDept.Enabled             = false;
                    this.ddlWhouse.Enabled           = false;
                    this.ddlDayCheckNo.Enabled       = false;
                    this.ddlState.Enabled            = false;
                    this.btnCheckOk.Enabled          = true;
                }
                else
                {
                    if (ret < 0)
                    {
                        this.Popup("该仓库在盘点序号“" + strcheckno + "”中已经有此存货的盘点记录,请重试!");
                    }
                    else
                    {
                        this.Popup("添加盘点存货失败!");
                    }
                }

                this.DataGrid1.DataSource = null;
                this.DataGrid1.DataBind();
                this.DBBind();
            }
        }