예제 #1
0
        /// <summary>
        /// 确定
        /// </summary>
        protected void OKButton_Click(object sender, EventArgs e)
        {
            if (ORDNO.Text.Trim().Length == 0 || Seq.Text.Trim().Length == 0)
            {
                this.ShowErrorMessage("参数错误");
                return;
            }

            SqlConnection con = LocalGlobal.DbConnect();

            con.Open();
            SqlTransaction tran = con.BeginTransaction();//使用事务
            SqlCommand     cmd  = new SqlCommand();

            cmd.Connection  = con;
            cmd.Transaction = tran;

            try
            {
                using (ContractProvider contProvider = new ContractProvider())
                {
                    string orno  = ORDNO.Text.Trim();
                    string orSeq = Seq.Text.Trim();

                    cmd.CommandText = contProvider.DeleteZbSkSql(orno, this.CurrentStNo, orSeq);
                    cmd.ExecuteNonQuery();

                    var table = ViewState["ViewDT"] as DataTable;
                    int seq = 0; decimal total = 0;
                    foreach (DataRow row in table.Rows)
                    {
                        seq++;
                        cmd.CommandText = contProvider.InsertZbSkSql(orno, orSeq, seq.ToString(), this.CurrentStNo, row["zbskamt"].ToString(), row["zbskdate"].ToString());

                        cmd.ExecuteNonQuery();

                        total += Util.ToDecimal(row["zbskamt"].ToString());
                    }

                    cmd.CommandText = contProvider.UpdateZbSkAmtSql(orno, orSeq, this.CurrentStNo, total.ToString());
                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception error)
            {
                tran.Rollback();
                this.ShowErrorMessage("保存失败!" + error.Message);
                return;
            }

            tran.Commit();

            //回调
            this.DialogCallback("'CloseRefresh'", "window");
        }