/// <summary> /// replace message {1}-->param1,{2}-->param2 /// </summary> /// <param name="originalText">select from db</param> /// <param name="mme">replace text</param> /// <returns></returns> private string ReplaceMessage(string originalText, M_Message_Entity mme) { if (!string.IsNullOrWhiteSpace(originalText)) { if (originalText.Contains("{0}")) { originalText = originalText.Replace("{0}", mme.MessageText1); } if (originalText.Contains("{1}")) { originalText = originalText.Replace("{1}", mme.MessageText2); } if (originalText.Contains("{2}")) { originalText = originalText.Replace("{2}", mme.MessageText3); } if (originalText.Contains("{3}")) { originalText = originalText.Replace("{3}", mme.MessageText4); } if (originalText.Contains("{4}")) { originalText = originalText.Replace("{4}", mme.MessageText5); } //originalText += !string.IsNullOrWhiteSpace(mme.MessageText2) ? originalText.Replace("{2}", mme.MessageText2) : string.Empty; //originalText += !string.IsNullOrWhiteSpace(mme.MessageText3) ? originalText.Replace("{3}", mme.MessageText3) : string.Empty; //originalText += !string.IsNullOrWhiteSpace(mme.MessageText4) ? originalText.Replace("{4}", mme.MessageText4) : string.Empty; //originalText += !string.IsNullOrWhiteSpace(mme.MessageText5) ? originalText.Replace("{5}", mme.MessageText5) : string.Empty; } return(originalText); }
/// <summary> /// select Message Information /// </summary> /// <param name="mme">Message Entity</param> /// <returns>return Datatable select by MessageID</returns> public DataTable M_Message_Select(M_Message_Entity mme) { Dictionary <string, ValuePair> dic = new Dictionary <string, ValuePair>(); dic.Add("@MessageID", new ValuePair { value1 = SqlDbType.VarChar, value2 = mme.MessageID }); return(SelectData(dic, "M_Message_Select")); }
/// <summary> /// select data from single table only /// </summary> /// <param name="fields"></param> /// <param name="tableName"></param> /// <param name="condition"></param> /// <returns></returns> //public DataTable SimpleSelect(string fields, string tableName, string condition) //{ // Base_DL bdl = new Base_DL(); // return bdl.SimpleSelect(fields, tableName, condition); //} /// <summary> /// to show Message /// MessageID is require,other params are nullable /// eg.ShowMessage("I0001"); ---> OK.No need to add all params if not necessary /// </summary> /// <param name="MessageID">Message ID eg.I001</param> /// <param name="text1">to replace {1}</param> /// <param name="text2">to replace {2}</param> /// <param name="text3">to replace {3}</param> /// <param name="text4">to replace {4}</param> /// <param name="text5">to replace {5}</param> /// <returns>return DialogResult(Yes,No,OK,Cancel)</returns> public DialogResult ShowMessage(string MessageID, string text1 = null, string text2 = null, string text3 = null, string text4 = null, string text5 = null) { M_Message_Entity mme = new M_Message_Entity { MessageID = MessageID, MessageText1 = string.IsNullOrWhiteSpace(text1) ? string.Empty : text1, MessageText2 = string.IsNullOrWhiteSpace(text2) ? string.Empty : text2, MessageText3 = string.IsNullOrWhiteSpace(text3) ? string.Empty : text3, MessageText4 = string.IsNullOrWhiteSpace(text4) ? string.Empty : text4, MessageText5 = string.IsNullOrWhiteSpace(text5) ? string.Empty : text5 }; return(GetMessage(mme)); }
/// <summary> /// show message /// </summary> /// <param name="mme"></param> /// <returns>dialogresult(ok,cancel,...)</returns> private DialogResult GetMessage(M_Message_Entity mme) { M_Message_DL mmdl = new M_Message_DL(); DataTable dtMsg = mmdl.M_Message_Select(mme); string message = string.Empty; string MessageID; if (dtMsg.Rows.Count > 0) { message = ReplaceMessage(dtMsg.Rows[0]["MessageText1"].ToString(), mme); message += !string.IsNullOrWhiteSpace(dtMsg.Rows[0]["MessageText2"].ToString()) ? "\n\n" + ReplaceMessage(dtMsg.Rows[0]["MessageText2"].ToString(), mme) : string.Empty; message += !string.IsNullOrWhiteSpace(dtMsg.Rows[0]["MessageText3"].ToString()) ? "\n\n" + ReplaceMessage(dtMsg.Rows[0]["MessageText3"].ToString(), mme) : string.Empty; message += !string.IsNullOrWhiteSpace(dtMsg.Rows[0]["MessageText4"].ToString()) ? "\n\n" + ReplaceMessage(dtMsg.Rows[0]["MessageText4"].ToString(), mme) : string.Empty; MessageID = !string.IsNullOrWhiteSpace(dtMsg.Rows[0]["MessageID"].ToString()) ? "\n\n" + ReplaceMessage(dtMsg.Rows[0]["MessageID"].ToString(), mme) : string.Empty; // MessageID = ReplaceMessage(dtMsg.Rows[0]["MessageID"].ToString(), mme); MessageBoxButtons msgbtn = dtMsg.Rows[0]["MessageButton"].ToString().Equals("1") ? MessageBoxButtons.OK : dtMsg.Rows[0]["MessageButton"].ToString().Equals("2") ? MessageBoxButtons.OKCancel : dtMsg.Rows[0]["MessageButton"].ToString().Equals("3") ? MessageBoxButtons.RetryCancel : dtMsg.Rows[0]["MessageButton"].ToString().Equals("4") ? MessageBoxButtons.YesNo : dtMsg.Rows[0]["MessageButton"].ToString().Equals("5") ? MessageBoxButtons.YesNoCancel : MessageBoxButtons.AbortRetryIgnore; MessageBoxIcon msgicon = dtMsg.Rows[0]["MessageMark"].ToString().Equals("1") ? MessageBoxIcon.Information : dtMsg.Rows[0]["MessageMark"].ToString().Equals("2") ? MessageBoxIcon.Asterisk : dtMsg.Rows[0]["MessageMark"].ToString().Equals("3") ? MessageBoxIcon.Question : dtMsg.Rows[0]["MessageMark"].ToString().Equals("4") ? MessageBoxIcon.Error : dtMsg.Rows[0]["MessageMark"].ToString().Equals("5") ? MessageBoxIcon.Stop : dtMsg.Rows[0]["MessageMark"].ToString().Equals("6") ? MessageBoxIcon.Exclamation : MessageBoxIcon.None; if (mme.MessageID == "Q003") { return(MessageBox.Show(message, mme.MessageID, msgbtn, msgicon, MessageBoxDefaultButton.Button2)); } else { return(MessageBox.Show(message, mme.MessageID, msgbtn, msgicon, MessageBoxDefaultButton.Button1)); } } else { return(MessageBox.Show("システムで予約されたコード(メッセージマスタ未登録)", "エラー(" + mme.MessageID + ")", MessageBoxButtons.OK, MessageBoxIcon.Error)); } }