SMbtn5604
using Salien.Utility; using Salien.Utility.SUWF; using System; using System.Data; using System.Web.UI.WebControls; namespace SM5604btnTJ { public class SM5604btnTJ : ISuwfBus { private SlnSuwfPage _page; public enum Action { SQ = 0, DSH = 1, DSP = 10, DCG = 20, DRK = 30, DJZ = 40 , YJZ = 50 , GB = 60 , ZZ = 99 /*0,申请;1,待审核;10,待审批;20,待采购;30,待入库;40,待结账;50,已结账;60,关闭;99,终止*/ } void ISuwfBus.Initial(SlnSuwfPage page) { this._page = page; BindButtonEvent(_page, "btnTJ", this.BtnTJ_Click); } #region BindButtonEvent public void BindButtonEvent(SlnSuwfPage _page, string strBtnName, EventHandler ev) { System.Web.UI.Control control = _page.FindControl(strBtnName); if (control != null) { Button button = (Button)control; if (button != null) { button.Click += ev; button.Attributes.Add("onclick", "javascript:if(!confirm('是否确认提交?')){return false;}"); } else { _page.ShowMessage("【" + strBtnName + "】按钮不存在"); } } else { _page.ShowMessage("【" + strBtnName + "】控件不存在"); } } #endregion #region 采购员提交 BtnTJ_Click private void BtnTJ_Click(object sender, EventArgs e) { string sSelectRow = _page.GetRowDataPrimaryKeys(); if (sSelectRow.Length == 0) { _page.ShowMessage("请选择网格数据"); return; } string CGZBIDList_TJ = string.Empty; string CGZBIDList_NOTJ = string.Empty; GridView grd = _page.MainGrid; foreach (GridViewRow gridRow in grd.Rows) { if (_page.GridRowIsSelected(gridRow.RowIndex)) { string ID = _page.GetRowDataByKey(gridRow.RowIndex, "ID"); string DJBH = _page.GetRowDataByKey(gridRow.RowIndex, "DJBH"); if (_page.GetRowDataByKey(gridRow.RowIndex, "ZT") == "2" && _page.GetRowDataByKey(gridRow.RowIndex, "RKLB") == "9") { CGZBIDList_TJ = CGZBIDList_TJ + "," + ID; continue; } if (_page.GetRowDataByKey(gridRow.RowIndex, "ZT")=="2" && _page.GetRowDataByKey(gridRow.RowIndex, "WRKS") == "0") { CGZBIDList_TJ = CGZBIDList_TJ + "," + ID; continue; } CGZBIDList_NOTJ = CGZBIDList_NOTJ + "," + ID; } } if (!SlnString.IsNull(CGZBIDList_TJ)) { SlnDataAccess.ExecuteSQL($"update SM_CG_CGZB_TB set DJZT={(int)Action.DJZ} " + $"where DJZT=30 and id in ({CGZBIDList_TJ.TrimStart(',')})"); } CGZBIDList_NOTJ = CGZBIDList_NOTJ.TrimStart(','); if (SlnString.IsNull(CGZBIDList_NOTJ) == false) { string sql = @"select t.ID,t.ZT,(case when exists (select 1 from sm_cg_cgzb_tb where rklb = 0 and zt in (0,1) and djbh = t.djbh and id <> t.id) then 1 else 0 end ) as SFTJ " + $" from SM_CG_CGZB_TB t where t.id in ({CGZBIDList_NOTJ.TrimStart(',')})"; DataTable dt = SlnDataAccess.GetDataTable(sql); if (dt != null && dt.Rows.Count > 0) { if (dt.Select("ZT<>2").Length > 0) { ShowMsg("存在没有入库的情况无法全部提交"); _page.btnQuery_Click(null, null); return; } if (dt.Select("SFTJ=0").Length > 0) { ShowMsg("存在没有入满且没有未入库的分拆单也不能提交"); _page.btnQuery_Click(null, null); return; } } } string msg = ""; try { msg = SlnDataAccess.ExecuteSQL($"update SM_CG_CGZB_TB set CZRID={_page.GetValueByName("sys_userid")}" + $",CZRQ=sysdate,DJZT={(int)Action.DJZ} where DJZT=30 and id in ({CGZBIDList_NOTJ.TrimStart(',')})"); if (msg == "") { msg += "提交成功,单子由待入库变成了待结账状态"; } else { msg += "提交失败"; } } catch (Exception ex) { _page.ShowMessage(ex.Message); } finally { ShowMsg(msg); } _page.btnQuery_Click(null, null); return; } #endregion #region 显示消息提示对话框 public void ShowMsg(string msg) { System.Text.StringBuilder Builder = new System.Text.StringBuilder(); Builder.Append("<script language='javascript' defer>"); Builder.AppendFormat("Alert('{0}');", msg); Builder.Append("</script>"); _page.Page.ClientScript.RegisterStartupScript(typeof(System.Web.UI.Page), "message", Builder.ToString()); } #endregion } }