Exemple #1
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            #region 检测

            if (PRNo.Text.Trim().Length <= 0)
            {
                this.ShowWarningMessage("请输入请购单号!");
                return;
            }

            #endregion

            SqlConnection con = LocalGlobal.DbConnect();
            con.Open();
            SqlTransaction tran = con.BeginTransaction();//使用事务
            SqlCommand     cmd  = new SqlCommand();
            cmd.Connection  = con;
            cmd.Transaction = tran;

            var dateModel = LocalGlobal.GetDateModel();

            using (PurProvider purProvider = new PurProvider())
            {
                try
                {
                    bool flag = false;
                    foreach (GridViewRow row in List.Rows)
                    {
                        HtmlInputCheckBox rowCheckControl = (HtmlInputCheckBox)row.FindControl("RowCheck");
                        if (rowCheckControl.Checked)
                        {
                            string seq        = row.Cells[2].Text.Trim();
                            string price      = ((TextBox)row.FindControl("prlpacst")).Text.Trim();
                            string vendorNo   = ((TextBox)row.FindControl("prlvnd")).Text.Trim();
                            string vendorName = ((TextBox)row.FindControl("prlvndm")).Text.Trim();
                            string curr       = ((TextBox)row.FindControl("prlcur")).Text.Trim();
                            string isWeight   = IsWeight.Checked ? "Y" : "";

                            #region 检测

                            if (Util.ToDecimal(price) <= 0)
                            {
                                tran.Rollback();
                                this.ShowWarningMessage("请填写单价");
                                return;
                            }
                            if (vendorNo.Length <= 0)
                            {
                                tran.Rollback();
                                this.ShowWarningMessage("请填写厂商代码");
                                return;
                            }
                            if (vendorName.Length <= 0)
                            {
                                tran.Rollback();
                                this.ShowWarningMessage("请填写厂商名称");
                                return;
                            }

                            #endregion

                            cmd.CommandText = purProvider.UpdatePRDetailSql(PRNo.Text.Trim(), seq.ToString(), price, vendorNo, vendorName, curr, isWeight, dateModel.DateStr);
                            cmd.ExecuteNonQuery();

                            flag = true;
                        }
                    }

                    if (flag)
                    {
                        //更新状态
                        cmd.CommandText = purProvider.UpdatePRStatusSql(PRNo.Text.Trim(), "UP");
                        cmd.ExecuteNonQuery();
                    }
                    else
                    {
                        this.ShowInfoMessage(this.GetGlobalResourceString("NotSelectMessage"));
                        tran.Rollback();
                        return;
                    }
                }
                catch (Exception error)
                {
                    tran.Rollback();
                    this.ShowErrorMessage("保存失败。" + error.Message);
                    return;
                }

                tran.Commit();
            }

            this.BindList();
            this.PostButton.Enabled = true;
        }