protected void btnUpdate_Click(object sender, EventArgs e) { try { string SessionIDName = "STM381_GridView1" + PageTimeStamp.Value; string V_Result = "0"; //同步GRIDVIEW至DT if(!DoUPD_DT()) return; #region UPDATE bool bResult = true; this.btnUpdate.Enabled = false; this.btnCancel.Enabled = false; this.btn_UPDATE_BATCH.Enabled = false; this.ErrorMsgLabel.Text = ""; DataTable dt = ((DataTable)Session[SessionIDName]); STMModel.VDS_STM38_BCO BCO = new STMModel.VDS_STM38_BCO(ConntionDB); DbTransaction DBT = null; //初始化DBT BCO.StartDBT(out DBT); if (hid_EdType.Value == "S") { DataTable dt1 = dt.Copy(); for (int i = 0; i <= dt.Rows.Count - 1; i++) { if (dt.Rows[i]["PROOF_FLG"].ToString() == "1" && bResult) { DataRow[] dr = dt1.Select(string.Format("PROMOTE_ID ='{0}' and PROOF_FLG ='0'", dt.Rows[i]["PROMOTE_ID"].ToString() )); if (dr.Length > 0) { this.ErrorMsgLabel.Text += "書展編號" + dt.Rows[i]["PROMOTE_ID"] + "書展折讓已回狀態應一致;"; bResult = false; } } if (rbl_proType.SelectedValue == "2" && dt.Rows[i]["SALE_QTY"].ToString().Trim() != "" && bResult) { DataRow[] dr = dt1.Select(string.Format("PROMOTE_ID ='{0}' and SALE_QTY is null ", dt.Rows[i]["PROMOTE_ID"].ToString() )); if (dr.Length > 0) { this.ErrorMsgLabel.Text += "書展編號" + dt.Rows[i]["PROMOTE_ID"] + "實銷數不可有空白資料;"; bResult = false; } } if (rbl_proType.SelectedValue == "1" && dt.Rows[i]["PRICE_SUM"].ToString().Trim() != string.Empty && bResult) { DataRow[] dr = dt1.Select(string.Format("PROMOTE_ID ='{0}' and PRICE_SUM is null ", dt.Rows[i]["PROMOTE_ID"].ToString() )); if (dr.Length > 0) { this.ErrorMsgLabel.Text += "書展編號" + dt.Rows[i]["PROMOTE_ID"] + "零售價小計不可有空白資料;"; bResult = false; } } if (bResult) { ParameterList.Clear(); ParameterList.Add(GetValueSetParameter(dt.Rows[i]["ID"].ToString(), "int", false));//0 ParameterList.Add(GetValueSetParameter(hid_ProType.Value, "int", false));//1 ParameterList.Add(GetValueSetParameter(dt.Rows[i]["PROMOTE_DT"].ToString(), "string", false));//2 ParameterList.Add(GetValueSetParameter(dt.Rows[i]["PROMOTE_ID"].ToString(), "string", false));//3 ParameterList.Add(GetValueSetParameter(dt.Rows[i]["PROOF_FLG"].ToString(), "int", false));//4 if (hid_ProType.Value == "1") { ParameterList.Add(DBNull.Value);//5 if (dt.Rows[i]["PRICE_SUM"].ToString() != "") { ParameterList.Add(GetValueSetParameter(dt.Rows[i]["PRICE_SUM"].ToString(), "int", false));//6 } else { ParameterList.Add(DBNull.Value);//6 } } else { if (dt.Rows[i]["SALE_QTY"].ToString() != "") { ParameterList.Add(GetValueSetParameter(dt.Rows[i]["SALE_QTY"].ToString(), "int", false));//5 } else { ParameterList.Add(DBNull.Value);//5 } ParameterList.Add(DBNull.Value);//6 } if (dt.Rows[i]["ADJUST_AMT"].ToString() != "") { ParameterList.Add(GetValueSetParameter(dt.Rows[i]["ADJUST_AMT"].ToString(), "float", false));//7 } else { ParameterList.Add(DBNull.Value);//7 } ParameterList.Add(GetValueSetParameter(Session["UID"].ToString(), "string", false));//8 V_Result = BCO.doUpdate_S(ParameterList, DBT); if (V_Result == "0") { if (hid_ProType.Value == "1") { this.ErrorMsgLabel.Text = "更新資料檔期編號" + dt.Rows[i]["PROMOTE_ID"].ToString() + "店號" + dt.Rows[i]["STORE"].ToString() + "供應商編號" + dt.Rows[i]["VENDOR"] + "發生錯誤!"; } else { this.ErrorMsgLabel.Text = "更新資料檔期編號" + dt.Rows[i]["PROMOTE_ID"].ToString() + "店號" + dt.Rows[i]["STORE"].ToString() + "品號" + dt.Rows[i]["ITEM"] + "期別" + dt.Rows[i]["PERIOD"] + "發生錯誤!"; } break; } } else { V_Result = "0"; break; } } } else { for (int i = 0; i <= dt.Rows.Count - 1; i++) { ParameterList.Clear(); ParameterList.Add(GetValueSetParameter(dt.Rows[i]["ID"].ToString(), "int", false));//0 ParameterList.Add(GetValueSetParameter(dt.Rows[i]["PROMOTE_TYPE"].ToString(), "int", false));//1 ParameterList.Add(GetValueSetParameter(dt.Rows[i]["PROMOTE_DT"].ToString(), "string", false));//2 ParameterList.Add(GetValueSetParameter(dt.Rows[i]["PROMOTE_ID"].ToString(), "string", false));//3 ParameterList.Add(GetValueSetParameter(dt.Rows[i]["CHECK_MONTH"].ToString(), "string", false));//4 if (dt.Rows[i]["COST_SUBSIDY_PERCENT"].ToString() != "") { ParameterList.Add(GetValueSetParameter(dt.Rows[i]["COST_SUBSIDY_PERCENT"].ToString(), "float", false));//5 } else { V_Result = "0"; break; } ParameterList.Add(GetValueSetParameter(Session["UID"].ToString(), "string", false));//6 V_Result = BCO.doUpdate_V(ParameterList, DBT); if (V_Result == "0") { if (dt.Rows[i]["PROMOTE_TYPE"].ToString() == "1") { this.ErrorMsgLabel.Text = "更新資料檔期編號" + dt.Rows[i]["PROMOTE_ID"].ToString() + "店號" + dt.Rows[i]["STORE"].ToString() + "供應商編號" + dt.Rows[i]["VENDOR"] + "發生錯誤!"; } else { this.ErrorMsgLabel.Text = "更新資料檔期編號" + dt.Rows[i]["PROMOTE_ID"].ToString() + "店號" + dt.Rows[i]["STORE"].ToString() + "品號" + dt.Rows[i]["ITEM"] + "期別" + dt.Rows[i]["PERIOD"] + "發生錯誤!"; } break; } } } if (V_Result != "0") { //完成交易 BCO.CommitDBT(DBT); ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "STM381", "alert('更新完成');location.replace('STM381.aspx?Code=STM38');", true); } else { if (DBT != null) DBT.Rollback(); ParameterList.Clear(); GridView1.DataSource = dt; GridView1.DataBind(); this.btnUpdate.Enabled = true; this.btnCancel.Enabled = true; } #endregion } catch (Exception ex) { WaringLogProcess(ex.Message); this.ErrorMsgLabel.Text = ex.Message.Split(Environment.NewLine.Replace(Environment.NewLine, "~").ToCharArray())[0]; //直接取第一個 } finally { Finally_Function(); } }