ivr流程编辑器

CtlIVRSql.cs 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using HySoft.IVRFlowEditor.IVRControlUtility;
  10. using HySoft.IVRFlowEditor.Utility;
  11. namespace HySoft.IVRFlowEditor.IVRControl
  12. {
  13. public partial class CtlIVRSql : UserControl
  14. {
  15. IVRSql _IVRSql;
  16. public CtlIVRSql(IVRSql obj)
  17. {
  18. InitializeComponent();
  19. _IVRSql = obj;
  20. this.Load += new EventHandler(CtlIVRSql_Load);
  21. }
  22. void CtlIVRSql_Load(object sender, EventArgs e)
  23. {
  24. this.tb_NodeID.Text = _IVRSql.Pos;
  25. this.tb_NodeName.Text = _IVRSql.Name;
  26. this.rtb_Note.Text = _IVRSql.Note;
  27. this.cmb_FailPos.DataSource = GlobalController.GetComBoBoxofIVR();
  28. this.cmb_FailPos.DisplayMember = "Note";//2017-5-8将Name改为Note
  29. this.cmb_FailPos.ValueMember = "ID";
  30. if (_IVRSql.FailPos != null)
  31. cmb_FailPos.SelectedItem = _IVRSql.FailPos;
  32. this.cmb_SuccessPos.DataSource = GlobalController.GetComBoBoxofIVR();
  33. this.cmb_SuccessPos.DisplayMember = "Note";//2017-5-8将Name改为Note
  34. this.cmb_SuccessPos.ValueMember = "ID";
  35. if (_IVRSql.SuccessPos != null)
  36. cmb_SuccessPos.SelectedItem = _IVRSql.SuccessPos;
  37. if(!string.IsNullOrEmpty(_IVRSql.ConnStr))
  38. this.rtb_ConnStr.Text = _IVRSql.ConnStr;
  39. this.rtb_SqlStr.Text = _IVRSql.SqlStr;
  40. //this.ckb_IsSaved.Checked = _IVRSql.IsSaved;
  41. //2017-5-6
  42. bool issave = false;
  43. if(_IVRSql.IsSaved=="yes")
  44. { issave = true; }
  45. else if (_IVRSql.IsSaved == "no")
  46. { issave = false ; }
  47. this.ckb_IsSaved.Checked = issave;
  48. }
  49. private void btn_enter_Click(object sender, EventArgs e)
  50. {
  51. if (string.IsNullOrEmpty(this.rtb_ConnStr.Text) || string.IsNullOrEmpty(this.rtb_SqlStr.Text))
  52. {
  53. MessageBox.Show("连接字符串和SQL语句都不能为空!");
  54. return;
  55. }
  56. _IVRSql.SuccessPos = this.cmb_SuccessPos.SelectedItem as IVRControlBase;
  57. _IVRSql.FailPos = this.cmb_FailPos.SelectedItem as IVRControlBase;
  58. _IVRSql.ConnStr = this.rtb_ConnStr.Text;
  59. //2017-5-8将<用&lt;替换掉以防解析错误
  60. string strrep=StringReplace(this.rtb_SqlStr.Text, "<", "&lt;");
  61. _IVRSql.SqlStr = strrep;// this.rtb_SqlStr.Text;
  62. //_IVRSql.IsSaved=this.ckb_IsSaved.Checked;
  63. //2017-5-6
  64. if (this.ckb_IsSaved.Checked == true)
  65. { _IVRSql.IsSaved = "yes"; }
  66. else if (this.ckb_IsSaved.Checked == false )
  67. { _IVRSql.IsSaved = "no"; }
  68. _IVRSql.Pos = this.tb_NodeID.Text;
  69. _IVRSql.Name = this.tb_NodeName.Text;
  70. _IVRSql.Note = this.rtb_Note.Text;
  71. this.FindForm().DialogResult = DialogResult.OK;
  72. this.FindForm().Close();
  73. }
  74. #region 替换指定字符串
  75. /// <summary>
  76. /// 替换指定字符串
  77. /// </summary>
  78. /// <param name="str">待处理的字符串</param>
  79. /// <param name="toRep">要替换的字符串中的子串</param>
  80. /// <param name="strRep">用来替换toRep字符串的字符串</param>
  81. /// <returns>返回一个结果字符串</returns>
  82. public static string StringReplace(string str, string toRep, string strRep)
  83. {
  84. StringBuilder sb = new StringBuilder();
  85. int np = 0, n_ptmp = 0;
  86. for (;;)
  87. {
  88. string str_tmp = str.Substring(np);
  89. n_ptmp = str_tmp.IndexOf(toRep);
  90. if (n_ptmp == -1)
  91. {
  92. sb.Append(str_tmp);
  93. break;
  94. }
  95. else
  96. {
  97. sb.Append(str_tmp.Substring(0, n_ptmp)).Append(strRep);
  98. np += n_ptmp + toRep.Length;
  99. }
  100. }
  101. return sb.ToString();
  102. }
  103. #endregion
  104. private void btn_cancel_Click(object sender, EventArgs e)
  105. {
  106. this.FindForm().DialogResult = DialogResult.No;
  107. this.FindForm().Close();
  108. }
  109. private void rtb_SqlStr_MouseDoubleClick(object sender, MouseEventArgs e)
  110. {
  111. FrmIVREdit frm = new FrmIVREdit(_IVRSql.SqlStr);
  112. frm.Text = "sql语句内容定义";
  113. if (frm.ShowDialog() == DialogResult.OK)
  114. {
  115. this.rtb_SqlStr.Text = frm.GetText();
  116. }
  117. }
  118. }
  119. }