using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HySoft.IVRFlowEditor.IVRControlUtility;
using HySoft.IVRFlowEditor.Utility;
namespace HySoft.IVRFlowEditor.IVRControl
{
public partial class CtlIVRSql : UserControl
{
IVRSql _IVRSql;
public CtlIVRSql(IVRSql obj)
{
InitializeComponent();
_IVRSql = obj;
this.Load += new EventHandler(CtlIVRSql_Load);
}
void CtlIVRSql_Load(object sender, EventArgs e)
{
this.tb_NodeID.Text = _IVRSql.Pos;
this.tb_NodeName.Text = _IVRSql.Name;
this.rtb_Note.Text = _IVRSql.Note;
this.cmb_FailPos.DataSource = GlobalController.GetComBoBoxofIVR();
this.cmb_FailPos.DisplayMember = "Note";//2017-5-8将Name改为Note
this.cmb_FailPos.ValueMember = "ID";
if (_IVRSql.FailPos != null)
cmb_FailPos.SelectedItem = _IVRSql.FailPos;
this.cmb_SuccessPos.DataSource = GlobalController.GetComBoBoxofIVR();
this.cmb_SuccessPos.DisplayMember = "Note";//2017-5-8将Name改为Note
this.cmb_SuccessPos.ValueMember = "ID";
if (_IVRSql.SuccessPos != null)
cmb_SuccessPos.SelectedItem = _IVRSql.SuccessPos;
if(!string.IsNullOrEmpty(_IVRSql.ConnStr))
this.rtb_ConnStr.Text = _IVRSql.ConnStr;
this.rtb_SqlStr.Text = _IVRSql.SqlStr;
//this.ckb_IsSaved.Checked = _IVRSql.IsSaved;
//2017-5-6
bool issave = false;
if(_IVRSql.IsSaved=="yes")
{ issave = true; }
else if (_IVRSql.IsSaved == "no")
{ issave = false ; }
this.ckb_IsSaved.Checked = issave;
}
private void btn_enter_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.rtb_ConnStr.Text) || string.IsNullOrEmpty(this.rtb_SqlStr.Text))
{
MessageBox.Show("连接字符串和SQL语句都不能为空!");
return;
}
_IVRSql.SuccessPos = this.cmb_SuccessPos.SelectedItem as IVRControlBase;
_IVRSql.FailPos = this.cmb_FailPos.SelectedItem as IVRControlBase;
_IVRSql.ConnStr = this.rtb_ConnStr.Text;
//2017-5-8将<用<替换掉以防解析错误
string strrep=StringReplace(this.rtb_SqlStr.Text, "<", "<");
_IVRSql.SqlStr = strrep;// this.rtb_SqlStr.Text;
//_IVRSql.IsSaved=this.ckb_IsSaved.Checked;
//2017-5-6
if (this.ckb_IsSaved.Checked == true)
{ _IVRSql.IsSaved = "yes"; }
else if (this.ckb_IsSaved.Checked == false )
{ _IVRSql.IsSaved = "no"; }
_IVRSql.Pos = this.tb_NodeID.Text;
_IVRSql.Name = this.tb_NodeName.Text;
_IVRSql.Note = this.rtb_Note.Text;
this.FindForm().DialogResult = DialogResult.OK;
this.FindForm().Close();
}
#region 替换指定字符串
///
/// 替换指定字符串
///
/// 待处理的字符串
/// 要替换的字符串中的子串
/// 用来替换toRep字符串的字符串
/// 返回一个结果字符串
public static string StringReplace(string str, string toRep, string strRep)
{
StringBuilder sb = new StringBuilder();
int np = 0, n_ptmp = 0;
for (;;)
{
string str_tmp = str.Substring(np);
n_ptmp = str_tmp.IndexOf(toRep);
if (n_ptmp == -1)
{
sb.Append(str_tmp);
break;
}
else
{
sb.Append(str_tmp.Substring(0, n_ptmp)).Append(strRep);
np += n_ptmp + toRep.Length;
}
}
return sb.ToString();
}
#endregion
private void btn_cancel_Click(object sender, EventArgs e)
{
this.FindForm().DialogResult = DialogResult.No;
this.FindForm().Close();
}
private void rtb_SqlStr_MouseDoubleClick(object sender, MouseEventArgs e)
{
FrmIVREdit frm = new FrmIVREdit(_IVRSql.SqlStr);
frm.Text = "sql语句内容定义";
if (frm.ShowDialog() == DialogResult.OK)
{
this.rtb_SqlStr.Text = frm.GetText();
}
}
}
}