JLHHJSvrConfig.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using LJLib.Tools.DEncrypt;
  2. using LJLib.Tools.File;
  3. using System;
  4. using System.Data.SqlClient;
  5. using System.IO;
  6. using System.Reflection;
  7. using System.Windows.Forms;
  8. using LJLib.InstallHelper;
  9. using JLHHJSvr;
  10. namespace JLHHJSvr
  11. {
  12. public partial class Form1 : Form
  13. {
  14. private string servername = "JLHHJSvr";
  15. private string displayname = "金龙恒核价后台服务";
  16. private string dscrp = "金龙恒核价后台服务";
  17. public Form1()
  18. {
  19. #if DEBUG
  20. servername += "_DEBUG";
  21. displayname += "(DEBUG)";
  22. dscrp += "(DEBUG)";
  23. #endif
  24. InitializeComponent();
  25. button4.Text = LJInstallHelper.Exitst(servername) ? "卸载服务" : "安装服务";
  26. var xmlconfig = new XmlConfig();
  27. var constr = xmlconfig.GetXmlFileValue(configFile, string.Empty, "ConnectionString", string.Empty);
  28. if (!string.IsNullOrEmpty(constr))
  29. {
  30. constr = DESEncrypt.Decrypt(constr, "4A61A8B51C3E42BCAE991F6C913A6A33");
  31. var builder = new SqlConnectionStringBuilder(constr);
  32. textBox1.Text = builder.DataSource;
  33. textBox2.Text = builder.InitialCatalog;
  34. textBox3.Text = builder.UserID;
  35. textBox4.Text = builder.Password;
  36. }
  37. textBox5.Text = xmlconfig.GetXmlFileValue(configFile, string.Empty, "port", "9075");
  38. }
  39. private void button1_Click(object sender, EventArgs e)
  40. {
  41. try
  42. {
  43. var builder = new SqlConnectionStringBuilder();
  44. builder.DataSource = textBox1.Text;
  45. builder.InitialCatalog = textBox2.Text;
  46. builder.UserID = textBox3.Text;
  47. builder.Password = textBox4.Text;
  48. using (var con = new SqlConnection(builder.ConnectionString))
  49. {
  50. con.Open();
  51. }
  52. MessageBox.Show("连接成功");
  53. }
  54. catch (Exception ex)
  55. {
  56. MessageBox.Show(ex.ToString());
  57. }
  58. }
  59. private static string configFile
  60. {
  61. get { return GlobalVar.XmlFile; }
  62. }
  63. private void button2_Click(object sender, EventArgs e)
  64. {
  65. try
  66. {
  67. var builder = new SqlConnectionStringBuilder();
  68. builder.DataSource = textBox1.Text;
  69. builder.InitialCatalog = textBox2.Text;
  70. builder.UserID = textBox3.Text;
  71. builder.Password = textBox4.Text;
  72. var xmlconfig = new XmlConfig();
  73. xmlconfig.SetXmlFileValue(configFile, string.Empty, "ConnectionString", DESEncrypt.Encrypt(builder.ConnectionString, "4A61A8B51C3E42BCAE991F6C913A6A33"));
  74. xmlconfig.SetXmlFileValue(configFile, string.Empty, "port", textBox5.Text);
  75. xmlconfig.SetXmlFileValue(configFile, string.Empty, "httpport", textBox6.Text);
  76. MessageBox.Show("保存成功");
  77. }
  78. catch (Exception ex)
  79. {
  80. MessageBox.Show(ex.ToString());
  81. }
  82. }
  83. private void button3_Click(object sender, EventArgs e)
  84. {
  85. Close();
  86. }
  87. private void button4_Click(object sender, EventArgs e)
  88. {
  89. if (button4.Text == "安装服务")
  90. {
  91. MessageBox.Show(LJInstallHelper.Install(servername, displayname, dscrp, string.Empty));
  92. }
  93. else
  94. {
  95. MessageBox.Show(LJInstallHelper.Uninstall(servername));
  96. }
  97. button4.Text = LJInstallHelper.Exitst(servername) ? "卸载服务" : "安装服务";
  98. }
  99. }
  100. }