/// <summary> /// 初始化Eterm窗口后,进入方法尝试链接 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void eterm_base_Load(object sender, EventArgs e) { int ll_1; int ll_2; int ll_3; string ls_temp_str; hWnd = this.Handle; Eterm_host = ""; Eterm_port = 0; Eterm_user = ""; Eterm_pwd = ""; Eterm_code = ""; Eterm_first_comm = ""; //开始启动Eterm窗口 eterm_bga.is_eterm_status = "Start"; #region 获取Eterm账号,并解密 ls_temp_str = ConfigurationManager.AppSettings["Eterm_STR"]; if (string.IsNullOrEmpty(ls_temp_str)) { if (DateTime.Now.Day > 15) ls_temp_str = ConfigurationManager.AppSettings["Eterm_STR1"]; else ls_temp_str = ConfigurationManager.AppSettings["Eterm_STR2"]; } if (!string.IsNullOrEmpty(ls_temp_str) && ls_temp_str.IndexOf(";") > -1) { string eterm_host1 = string.Empty, eterm_host = string.Empty, eterm_port1 = string.Empty, eterm_port = string.Empty; string eterm_user1 = string.Empty, eterm_user = string.Empty, eterm_pwd1 = string.Empty, eterm_pwd = string.Empty; string eterm_first_comm1 = string.Empty, eterm_first_comm = string.Empty; String[] strs = ls_temp_str.Split(';'); eterm_host1 = strs[0].Substring(strs[0].IndexOf("=") + 1); eterm_host = bga.DESDecrypt(eterm_host1, "hna2013_rams");//对数据库名解密 eterm_port1 = strs[1].Substring(strs[1].IndexOf("=") + 1); eterm_port = bga.DESDecrypt(eterm_port1, "hna2013_rams");//对用户名解密 eterm_user1 = strs[2].Substring(strs[2].IndexOf("=") + 1); eterm_user = bga.DESDecrypt(eterm_user1, "hna2013_rams");//对密码解密 eterm_pwd1 = strs[3].Substring(strs[3].IndexOf("=") + 1); eterm_pwd = bga.DESDecrypt(eterm_pwd1, "hna2013_rams");//对密码解密 eterm_first_comm1 = strs[4].Substring(strs[4].IndexOf("=") + 1); eterm_first_comm = bga.DESDecrypt(eterm_first_comm1, "hna2013_rams");//对密码解密 ls_temp_str = ls_temp_str.Replace(eterm_host1, eterm_host); ls_temp_str = ls_temp_str.Replace(eterm_port1, eterm_port); ls_temp_str = ls_temp_str.Replace(eterm_user1, eterm_user); ls_temp_str = ls_temp_str.Replace(eterm_pwd1, eterm_pwd); ls_temp_str = ls_temp_str.Replace(eterm_first_comm1, eterm_first_comm); } ll_1 = ls_temp_str.IndexOf("host", 0); //找HOST if (ll_1 >= 0) { ll_2 = ls_temp_str.IndexOf("=", ll_1 + 1); if (ll_2 > 0) { ll_3 = ls_temp_str.IndexOf(";", ll_2 + 1); if (ll_3 > ll_2) { Eterm_host = ls_temp_str.Substring(ll_2 + 1, ll_3 - ll_2 - 1).Trim(); } else { Eterm_host = ls_temp_str.Substring(ll_2 + 1).Trim(); } } } ll_1 = ls_temp_str.IndexOf("port", 0); //找PORT if (ll_1 >= 0) { ll_2 = ls_temp_str.IndexOf("=", ll_1 + 1); if (ll_2 > 0) { ll_3 = ls_temp_str.IndexOf(";", ll_2 + 1); if (ll_3 > ll_2) { Eterm_port = int.Parse(ls_temp_str.Substring(ll_2 + 1, ll_3 - ll_2 - 1).Trim()); } else { Eterm_port = int.Parse(ls_temp_str.Substring(ll_2 + 1).Trim()); } } } ll_1 = ls_temp_str.IndexOf("user", 0); //找user if (ll_1 >= 0) { ll_2 = ls_temp_str.IndexOf("=", ll_1 + 1); if (ll_2 > 0) { ll_3 = ls_temp_str.IndexOf(";", ll_2 + 1); if (ll_3 > ll_2) { Eterm_user = ls_temp_str.Substring(ll_2 + 1, ll_3 - ll_2 - 1).Trim(); } else { Eterm_user = ls_temp_str.Substring(ll_2 + 1).Trim(); } } } ll_1 = ls_temp_str.IndexOf("pwd", 0); //找pwd if (ll_1 >= 0) { ll_2 = ls_temp_str.IndexOf("=", ll_1 + 1); if (ll_2 > 0) { ll_3 = ls_temp_str.IndexOf(";", ll_2 + 1); if (ll_3 > ll_2) { Eterm_pwd = ls_temp_str.Substring(ll_2 + 1, ll_3 - ll_2 - 1).Trim(); } else { Eterm_pwd = ls_temp_str.Substring(ll_2 + 1).Trim(); } } } ll_1 = ls_temp_str.IndexOf("code", 0); //找code if (ll_1 >= 0) { ll_2 = ls_temp_str.IndexOf("=", ll_1 + 1); if (ll_2 > 0) { ll_3 = ls_temp_str.IndexOf(";", ll_2 + 1); if (ll_3 > ll_2) { Eterm_code = ls_temp_str.Substring(ll_2 + 1, ll_3 - ll_2 - 1).Trim(); } else { Eterm_code = ls_temp_str.Substring(ll_2 + 1).Trim(); } } } ll_1 = ls_temp_str.IndexOf("first_comm", 0); //找first_comm if (ll_1 >= 0) { ll_2 = ls_temp_str.IndexOf("=", ll_1 + 1); if (ll_2 > 0) { ll_3 = ls_temp_str.IndexOf(";", ll_2 + 1); if (ll_3 > ll_2) { Eterm_first_comm = ls_temp_str.Substring(ll_2 + 1, ll_3 - ll_2 - 1).Trim(); } else { Eterm_first_comm = ls_temp_str.Substring(ll_2 + 1).Trim(); } } } #endregion //如果从配置文件中获取的Eterm指令没有完整信息,则打开一个窗口手动输入Eterm账号信息 if ((Eterm_host.Length < 1) || (Eterm_port == 0) || (Eterm_user.Length < 1) || (Eterm_pwd.Length < 1)) { eterm_connect dlg = new eterm_connect(); dlg.Eterm_host = Eterm_host; dlg.Eterm_port = Eterm_port.ToString(); dlg.Eterm_user = Eterm_user; dlg.Eterm_pwd = Eterm_pwd; if (dlg.ShowDialog() != DialogResult.OK) { Close(); return; } Eterm_host = dlg.Eterm_host; Eterm_port = int.Parse(dlg.Eterm_port.Trim()); Eterm_user = dlg.Eterm_user; Eterm_pwd = dlg.Eterm_pwd; dlg.Dispose(); } //创建Eterm接口中的工厂类,用于连接、断开航信的订座系统 eTermFactory = new DrveTerm.MatipFactoryClass(); eTermFactory._IDrvFactoryEvents_Event_OnConnected += new _IDrvFactoryEvents_OnConnectedEventHandler(Factory_OnConnected); eTermFactory._IDrvFactoryEvents_Event_OnConnectParameters += new _IDrvFactoryEvents_OnConnectParametersEventHandler(Factory_OnConnectParameters); eTermFactory._IDrvFactoryEvents_Event_OnCtxCreated += new _IDrvFactoryEvents_OnCtxCreatedEventHandler(Factory_OnCtxCreated); eTermFactory._IDrvFactoryEvents_Event_OnDisconnected += new _IDrvFactoryEvents_OnDisconnectedEventHandler(Factory_OnDisconnected); eTermFactory.Connect(Eterm_host, Eterm_port, ""); }
/// <summary> /// 初始化Eterm窗口后,进入方法尝试链接 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void eterm_base_Load(object sender, EventArgs e) { int ll_1; int ll_2; int ll_3; string ls_temp_str; hWnd = this.Handle; Eterm_host = ""; Eterm_port = 0; Eterm_user = ""; Eterm_pwd = ""; Eterm_code = ""; Eterm_first_comm = ""; //开始启动Eterm窗口 eterm_bga.is_eterm_status = "Start"; #region 获取Eterm账号,并解密 ls_temp_str = ConfigurationManager.AppSettings["Eterm_STR"]; if (string.IsNullOrEmpty(ls_temp_str)) { if (DateTime.Now.Day > 15) { ls_temp_str = ConfigurationManager.AppSettings["Eterm_STR1"]; } else { ls_temp_str = ConfigurationManager.AppSettings["Eterm_STR2"]; } } if (!string.IsNullOrEmpty(ls_temp_str) && ls_temp_str.IndexOf(";") > -1) { string eterm_host1 = string.Empty, eterm_host = string.Empty, eterm_port1 = string.Empty, eterm_port = string.Empty; string eterm_user1 = string.Empty, eterm_user = string.Empty, eterm_pwd1 = string.Empty, eterm_pwd = string.Empty; string eterm_first_comm1 = string.Empty, eterm_first_comm = string.Empty; String[] strs = ls_temp_str.Split(';'); eterm_host1 = strs[0].Substring(strs[0].IndexOf("=") + 1); eterm_host = bga.DESDecrypt(eterm_host1, "hna2013_rams"); //对数据库名解密 eterm_port1 = strs[1].Substring(strs[1].IndexOf("=") + 1); eterm_port = bga.DESDecrypt(eterm_port1, "hna2013_rams"); //对用户名解密 eterm_user1 = strs[2].Substring(strs[2].IndexOf("=") + 1); eterm_user = bga.DESDecrypt(eterm_user1, "hna2013_rams"); //对密码解密 eterm_pwd1 = strs[3].Substring(strs[3].IndexOf("=") + 1); eterm_pwd = bga.DESDecrypt(eterm_pwd1, "hna2013_rams"); //对密码解密 eterm_first_comm1 = strs[4].Substring(strs[4].IndexOf("=") + 1); eterm_first_comm = bga.DESDecrypt(eterm_first_comm1, "hna2013_rams"); //对密码解密 ls_temp_str = ls_temp_str.Replace(eterm_host1, eterm_host); ls_temp_str = ls_temp_str.Replace(eterm_port1, eterm_port); ls_temp_str = ls_temp_str.Replace(eterm_user1, eterm_user); ls_temp_str = ls_temp_str.Replace(eterm_pwd1, eterm_pwd); ls_temp_str = ls_temp_str.Replace(eterm_first_comm1, eterm_first_comm); } ll_1 = ls_temp_str.IndexOf("host", 0); //找HOST if (ll_1 >= 0) { ll_2 = ls_temp_str.IndexOf("=", ll_1 + 1); if (ll_2 > 0) { ll_3 = ls_temp_str.IndexOf(";", ll_2 + 1); if (ll_3 > ll_2) { Eterm_host = ls_temp_str.Substring(ll_2 + 1, ll_3 - ll_2 - 1).Trim(); } else { Eterm_host = ls_temp_str.Substring(ll_2 + 1).Trim(); } } } ll_1 = ls_temp_str.IndexOf("port", 0); //找PORT if (ll_1 >= 0) { ll_2 = ls_temp_str.IndexOf("=", ll_1 + 1); if (ll_2 > 0) { ll_3 = ls_temp_str.IndexOf(";", ll_2 + 1); if (ll_3 > ll_2) { Eterm_port = int.Parse(ls_temp_str.Substring(ll_2 + 1, ll_3 - ll_2 - 1).Trim()); } else { Eterm_port = int.Parse(ls_temp_str.Substring(ll_2 + 1).Trim()); } } } ll_1 = ls_temp_str.IndexOf("user", 0); //找user if (ll_1 >= 0) { ll_2 = ls_temp_str.IndexOf("=", ll_1 + 1); if (ll_2 > 0) { ll_3 = ls_temp_str.IndexOf(";", ll_2 + 1); if (ll_3 > ll_2) { Eterm_user = ls_temp_str.Substring(ll_2 + 1, ll_3 - ll_2 - 1).Trim(); } else { Eterm_user = ls_temp_str.Substring(ll_2 + 1).Trim(); } } } ll_1 = ls_temp_str.IndexOf("pwd", 0); //找pwd if (ll_1 >= 0) { ll_2 = ls_temp_str.IndexOf("=", ll_1 + 1); if (ll_2 > 0) { ll_3 = ls_temp_str.IndexOf(";", ll_2 + 1); if (ll_3 > ll_2) { Eterm_pwd = ls_temp_str.Substring(ll_2 + 1, ll_3 - ll_2 - 1).Trim(); } else { Eterm_pwd = ls_temp_str.Substring(ll_2 + 1).Trim(); } } } ll_1 = ls_temp_str.IndexOf("code", 0); //找code if (ll_1 >= 0) { ll_2 = ls_temp_str.IndexOf("=", ll_1 + 1); if (ll_2 > 0) { ll_3 = ls_temp_str.IndexOf(";", ll_2 + 1); if (ll_3 > ll_2) { Eterm_code = ls_temp_str.Substring(ll_2 + 1, ll_3 - ll_2 - 1).Trim(); } else { Eterm_code = ls_temp_str.Substring(ll_2 + 1).Trim(); } } } ll_1 = ls_temp_str.IndexOf("first_comm", 0); //找first_comm if (ll_1 >= 0) { ll_2 = ls_temp_str.IndexOf("=", ll_1 + 1); if (ll_2 > 0) { ll_3 = ls_temp_str.IndexOf(";", ll_2 + 1); if (ll_3 > ll_2) { Eterm_first_comm = ls_temp_str.Substring(ll_2 + 1, ll_3 - ll_2 - 1).Trim(); } else { Eterm_first_comm = ls_temp_str.Substring(ll_2 + 1).Trim(); } } } #endregion //如果从配置文件中获取的Eterm指令没有完整信息,则打开一个窗口手动输入Eterm账号信息 if ((Eterm_host.Length < 1) || (Eterm_port == 0) || (Eterm_user.Length < 1) || (Eterm_pwd.Length < 1)) { eterm_connect dlg = new eterm_connect(); dlg.Eterm_host = Eterm_host; dlg.Eterm_port = Eterm_port.ToString(); dlg.Eterm_user = Eterm_user; dlg.Eterm_pwd = Eterm_pwd; if (dlg.ShowDialog() != DialogResult.OK) { Close(); return; } Eterm_host = dlg.Eterm_host; Eterm_port = int.Parse(dlg.Eterm_port.Trim()); Eterm_user = dlg.Eterm_user; Eterm_pwd = dlg.Eterm_pwd; dlg.Dispose(); } //创建Eterm接口中的工厂类,用于连接、断开航信的订座系统 eTermFactory = new DrveTerm.MatipFactoryClass(); eTermFactory._IDrvFactoryEvents_Event_OnConnected += new _IDrvFactoryEvents_OnConnectedEventHandler(Factory_OnConnected); eTermFactory._IDrvFactoryEvents_Event_OnConnectParameters += new _IDrvFactoryEvents_OnConnectParametersEventHandler(Factory_OnConnectParameters); eTermFactory._IDrvFactoryEvents_Event_OnCtxCreated += new _IDrvFactoryEvents_OnCtxCreatedEventHandler(Factory_OnCtxCreated); eTermFactory._IDrvFactoryEvents_Event_OnDisconnected += new _IDrvFactoryEvents_OnDisconnectedEventHandler(Factory_OnDisconnected); eTermFactory.Connect(Eterm_host, Eterm_port, ""); }