JLHHJSvrConfig.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. textBox6.Text = xmlconfig.GetXmlFileValue(configFile, string.Empty, "httpport", "");
  39. textBox7.Text = xmlconfig.GetXmlFileValue(configFile, string.Empty, "L1Server", "");
  40. textBox10.Text = xmlconfig.GetXmlFileValue(configFile, string.Empty, "L1API", "");
  41. textBox8.Text = xmlconfig.GetXmlFileValue(configFile, string.Empty, "L1Usercode", "");
  42. textBox9.Text = DESEncrypt.Decrypt(xmlconfig.GetXmlFileValue(configFile, string.Empty, "L1Password", ""), "4A61A8B51C3E42BCAE991F6C913A6A33");
  43. }
  44. private void button1_Click(object sender, EventArgs e)
  45. {
  46. try
  47. {
  48. var builder = new SqlConnectionStringBuilder();
  49. builder.DataSource = textBox1.Text;
  50. builder.InitialCatalog = textBox2.Text;
  51. builder.UserID = textBox3.Text;
  52. builder.Password = textBox4.Text;
  53. using (var con = new SqlConnection(builder.ConnectionString))
  54. {
  55. con.Open();
  56. }
  57. MessageBox.Show("连接成功");
  58. }
  59. catch (Exception ex)
  60. {
  61. MessageBox.Show(ex.ToString());
  62. }
  63. }
  64. private static string configFile
  65. {
  66. get { return GlobalVar.XmlFile; }
  67. }
  68. private void button2_Click(object sender, EventArgs e)
  69. {
  70. try
  71. {
  72. var builder = new SqlConnectionStringBuilder();
  73. builder.DataSource = textBox1.Text;
  74. builder.InitialCatalog = textBox2.Text;
  75. builder.UserID = textBox3.Text;
  76. builder.Password = textBox4.Text;
  77. var xmlconfig = new XmlConfig();
  78. xmlconfig.SetXmlFileValue(configFile, string.Empty, "ConnectionString", DESEncrypt.Encrypt(builder.ConnectionString, "4A61A8B51C3E42BCAE991F6C913A6A33"));
  79. xmlconfig.SetXmlFileValue(configFile, string.Empty, "port", textBox5.Text);
  80. xmlconfig.SetXmlFileValue(configFile, string.Empty, "httpport", textBox6.Text);
  81. xmlconfig.SetXmlFileValue(configFile, string.Empty, "L1Server", textBox7.Text);
  82. xmlconfig.SetXmlFileValue(configFile, string.Empty, "L1API", textBox10.Text);
  83. xmlconfig.SetXmlFileValue(configFile, string.Empty, "L1Usercode", textBox8.Text);
  84. xmlconfig.SetXmlFileValue(configFile, string.Empty, "L1Password", DESEncrypt.Encrypt(textBox9.Text, "4A61A8B51C3E42BCAE991F6C913A6A33"));
  85. MessageBox.Show("保存成功");
  86. }
  87. catch (Exception ex)
  88. {
  89. MessageBox.Show(ex.ToString());
  90. }
  91. }
  92. private void button3_Click(object sender, EventArgs e)
  93. {
  94. Close();
  95. }
  96. private void button4_Click(object sender, EventArgs e)
  97. {
  98. if (button4.Text == "安装服务")
  99. {
  100. MessageBox.Show(LJInstallHelper.Install(servername, displayname, dscrp, string.Empty));
  101. }
  102. else
  103. {
  104. MessageBox.Show(LJInstallHelper.Uninstall(servername));
  105. }
  106. button4.Text = LJInstallHelper.Exitst(servername) ? "卸载服务" : "安装服务";
  107. }
  108. }
  109. }