protected override void WfActionClick(string pActionName) { vw_admi600 masterModel; StringBuilder sbSql; YR.ERP.Base.Forms.FrmBase frmActive = null; try { switch (pActionName.ToLower()) { case "admi601": if (FormEditMode != YREditType.NA) { return; } if (DrMaster == null) { return; } masterModel = DrMaster.ToItem <vw_admi600>(); sbSql = new StringBuilder(); sbSql.AppendLine(string.Format(" AND ado01='{0}'", masterModel.ado01)); WfShowForm("admi601", false, new object[] { "admi600", this.LoginInfo, sbSql.ToString() }); break; case "admi602": if (FormEditMode != YREditType.NA) { return; } if (DrMaster == null) { return; } masterModel = DrMaster.ToItem <vw_admi600>(); sbSql = new StringBuilder(); sbSql.AppendLine(string.Format(" AND ado01='{0}'", masterModel.ado01)); WfShowForm("admi602", false, new object[] { "admi600", this.LoginInfo, sbSql.ToString() }); break; #region genaction case "genaction": if (DrMaster == null) { return; } if (FormEditMode != YREditType.NA) { return; } masterModel = DrMaster.ToItem <vw_admi600>(); var adoModle = BoAdm.OfGetAdoModel(masterModel.ado01); if (AdoModel == null) { WfShowErrorMsg("無此程式代號"); return; } //先檢查是否有transction if (BoMaster.TRAN != null) { WfCommit(); } if (TabMaster.CanUseRowLock == true) { WfLockMasterRow(); //Lock row 並且產生transaction } else { WfBeginTran(); } try { var assembly = System.Reflection.Assembly.LoadFile(Path.Combine(Application.StartupPath, adoModle.ado03)); var type = assembly.GetType(adoModle.ado04); frmActive = Activator.CreateInstance(type) as YR.ERP.Base.Forms.FrmBase; frmActive.LoginInfo = this.LoginInfo; frmActive.WindowState = FormWindowState.Minimized; frmActive.Show(); Dictionary <string, string> dic = new Dictionary <string, string>(); var actionDic = frmActive.ActionDic; var reportDic = frmActive.ReportDic; if (actionDic != null) { foreach (KeyValuePair <string, string> keyValue in actionDic) { dic.Add(keyValue.Key, keyValue.Value); } } if (reportDic != null) { foreach (KeyValuePair <string, string> keyValue in reportDic) { dic.Add(keyValue.Key, keyValue.Value); } } StringBuilder sb = new StringBuilder(); if (dic != null) { var i = 0; foreach (KeyValuePair <string, string> keyValue in dic) { i++; sb.Append(keyValue.Key); if (i < dic.Count) { sb.Append(","); } } DrMaster["ado15"] = sb.ToString(); //WfShowMsg(sb.ToString()); } frmActive.Close(); BoMaster.OfUpdate(DrMaster.Table); WfCommit(); DrMaster.Table.AcceptChanges(); } catch (Exception ex) { WfRollback(); DrMaster.Table.RejectChanges(); throw ex; } finally { if (frmActive != null) { frmActive.Close(); } } break; #endregion } } catch (Exception ex) { throw ex; } }
/********************************ovveride*************************/ #region WfToolbarModify() : 主表修改 function protected override Boolean WfToolbarModify() { vw_admi602 masterModel; StringBuilder sbSql; YR.ERP.Base.Forms.FrmBase frmActive = null; int chkCnts = 0; DataTable dtAdq = null; try { if (base.WfToolbarModify() == true) { masterModel = DrMaster.ToItem <vw_admi602>(); var adoModle = BoAdm.OfGetAdoModel(masterModel.ado01); if (AdoModel == null) { WfShowErrorMsg("無此程式代號"); return(false); } var result = WfShowConfirmMsg("是否需要重新擷取功能選單 ?"); //if (WfShowConfirmMsg("是否需要重新擷取功能選單") != 1) if (result != DialogResult.Yes) { return(true); } //先檢查是否有transction if (BoMaster.TRAN != null) { WfCommit(); } if (TabMaster.CanUseRowLock == true) { if (WfLockMasterRow() == false)//Lock row 並且產生transaction { return(false); } } else { if (WfBeginTran() == false) { return(false); } } try { var assembly = System.Reflection.Assembly.LoadFile(Path.Combine(Application.StartupPath, adoModle.ado03)); var type = assembly.GetType(adoModle.ado04); frmActive = Activator.CreateInstance(type) as YR.ERP.Base.Forms.FrmBase; frmActive.LoginInfo = this.LoginInfo; frmActive.WindowState = FormWindowState.Minimized; frmActive.Show(); Dictionary <string, string> dic = new Dictionary <string, string>(); var actionDic = frmActive.ActionDic; var reportDic = frmActive.ReportDic; if (actionDic != null) { foreach (KeyValuePair <string, string> keyValue in actionDic) { dic.Add(keyValue.Key, keyValue.Value); } } if (reportDic != null) { foreach (KeyValuePair <string, string> keyValue in reportDic) { dic.Add(keyValue.Key, keyValue.Value); } } frmActive.Close(); //以目前的action與擷取的資料來比對,只處理新增與刪除 dtAdq = TabDetailList[0].DtSource; //先處理刪除 for (int i = dtAdq.Rows.Count - 1; i >= 0; i--) { var adqModel = dtAdq.Rows[i].ToItem <adq_tb>(); //先刪掉不在程式中的 if (!dic.ContainsKey(adqModel.adq02)) { dtAdq.Rows[i].Delete(); if (TabDetailList[0].BoBasic.OfUpdate(BoMaster.TRAN, dtAdq.GetChanges()) < 0) { { throw new Exception("儲存明細時失敗,請檢核 !"); } } dtAdq.AcceptChanges(); } } //foreach (DataRow drAdq in dtAdq.Rows) //{ // var adqModel = drAdq.ToItem<adq_tb>(); // //先刪掉不在程式中的 // if (!dic.ContainsKey(adqModel.adq02)) // { // drAdq.Delete(); // if (TabDetailList[0].BoBasic.OfUpdate(BoMaster.TRAN, dtAdq.GetChanges()) < 0) // { // { throw new Exception("儲存明細時失敗,請檢核 !"); } // } // dtAdq.AcceptChanges(); // } //} //再處理新增 var adqList = dtAdq.ToList <adq_tb>(); foreach (KeyValuePair <string, string> keyValue in dic) { chkCnts = adqList.Where(p => p.adq02 == keyValue.Key).Count(); if (chkCnts == 0) { var drNew = dtAdq.NewRow(); drNew["adq01"] = masterModel.ado01; drNew["adq02"] = keyValue.Key; drNew["adq03"] = keyValue.Value; drNew["adq04"] = "1"; //預設為action dtAdq.Rows.Add(drNew); } } if (dtAdq.GetChanges() != null) { if (TabDetailList[0].BoBasic.OfUpdate(BoMaster.TRAN, dtAdq.GetChanges()) < 0) { { throw new Exception("儲存明細時失敗,請檢核 !"); } } } WfCommit(); //dtAdq.AcceptChanges(); } catch (Exception ex) { WfRollback(); //dtAdq.RejectChanges(); throw ex; } finally { if (frmActive != null) { frmActive.Close(); } WfRetrieveDetail(); } } } catch (Exception ex) { throw ex; } return(true); }