Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

161 řádky
6.0 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Configuration;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. using Learun.Util;
  14. namespace Quanjiang.DigitalScholl.DataSync
  15. {
  16. public partial class Form1 : Form
  17. {
  18. public Form1()
  19. {
  20. InitializeComponent();
  21. }
  22. private void btcheck_Click(object sender, EventArgs e)
  23. {
  24. if (tbsource.Text.Trim() != "" && tbtarget.Text.Trim() != "")
  25. {
  26. //写
  27. var opencon = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  28. opencon.ConnectionStrings.ConnectionStrings["source"].ConnectionString = tbsource.Text.Trim();
  29. opencon.ConnectionStrings.ConnectionStrings["target"].ConnectionString = tbtarget.Text.Trim();
  30. opencon.ConnectionStrings.ConnectionStrings["missource"].ConnectionString = tbmissource.Text.Trim();
  31. opencon.ConnectionStrings.ConnectionStrings["mistarget"].ConnectionString = tbmistarget.Text.Trim();
  32. opencon.Save(ConfigurationSaveMode.Full);
  33. //连
  34. if (Check().Result)
  35. {
  36. rtblog.AppendText("数据库连接成功!\r\n");
  37. btsync.Enabled = true;
  38. }
  39. else
  40. {
  41. btcheck.Enabled = true;
  42. }
  43. }
  44. else
  45. {
  46. MessageBox.Show("请输入连接字符串");
  47. }
  48. }
  49. public async Task<bool> Check()
  50. {
  51. btcheck.Enabled = false;
  52. bool result = false;
  53. result = await CheckConnection(tbsource.Text.Trim(), "源");
  54. if (result)
  55. {
  56. rtblog.AppendText("源数据库连接成功...\r\n");
  57. }
  58. result = result && await CheckConnection(tbtarget.Text.Trim(), "目标");
  59. if (result)
  60. {
  61. rtblog.AppendText("目标数据库连接成功...\r\n");
  62. }
  63. result = result && await CheckConnection(tbmissource.Text.Trim(), "源mis");
  64. if (result)
  65. {
  66. rtblog.AppendText("源mis数据库连接成功...\r\n");
  67. }
  68. result = result && await CheckConnection(tbmistarget.Text.Trim(), "目标mis");
  69. if (result)
  70. {
  71. rtblog.AppendText("目标mis数据库连接成功...\r\n");
  72. }
  73. return result;
  74. }
  75. public async Task<bool> CheckConnection(string conn, string target)
  76. {
  77. MainService main = new MainService();
  78. rtblog.AppendText("开始检测" + target + "数据库连接...\r\n");
  79. var result = await main.CheckConnection(conn);
  80. if (!result.result)
  81. {
  82. rtblog.AppendText(target + "数据库连接失败,请检查网络和连接字符串!\r\n");
  83. rtblog.AppendText(result.errormessage + "\r\n");
  84. }
  85. return result.result;
  86. }
  87. private void btsync_Click(object sender, EventArgs e)
  88. {
  89. if (clbmodule.CheckedItems.Count == 0)
  90. {
  91. MessageBox.Show("请选择要同步的模块");
  92. return;
  93. }
  94. MainService main = new MainService();
  95. bool result = Task.Run(() => main.BeginSync(clbmodule.CheckedItems)).Result;
  96. if (result)
  97. {
  98. MessageBox.Show("同步完成");
  99. btsync.Enabled = true;
  100. }
  101. }
  102. private void Form1_Load(object sender, EventArgs e)
  103. {
  104. tbsource.Text = ConfigurationManager.ConnectionStrings["source"].ConnectionString;
  105. tbtarget.Text = ConfigurationManager.ConnectionStrings["target"].ConnectionString;
  106. tbmissource.Text = ConfigurationManager.ConnectionStrings["missource"].ConnectionString;
  107. tbmistarget.Text = ConfigurationManager.ConnectionStrings["mistarget"].ConnectionString;
  108. }
  109. Thread mainthread = null;
  110. private void btsynccore_Click(object sender, EventArgs e)
  111. {
  112. Program.beginTable = txtBeginTable.Text;
  113. ThreadStart threadstart = new ThreadStart(TransferCoreData);
  114. mainthread = new Thread(threadstart);
  115. mainthread.Name = "main";
  116. mainthread.Start();
  117. }
  118. private void btsyncmis_Click(object sender, EventArgs e)
  119. {
  120. Program.beginTable = txtBeginTable.Text;
  121. ThreadStart threadstart = new ThreadStart(TransferMisData);
  122. mainthread = new Thread(threadstart);
  123. mainthread.Name = "main";
  124. mainthread.Start();
  125. }
  126. public void TransferCoreData()
  127. {
  128. SyncWindow progress = new SyncWindow("core");
  129. progress.ShowDialog();
  130. }
  131. public void TransferMisData()
  132. {
  133. SyncWindow progress = new SyncWindow("mis");
  134. progress.ShowDialog();
  135. }
  136. private void 查找密码为123456的ToolStripMenuItem_Click(object sender, EventArgs e)
  137. {
  138. MainService mainService = new MainService();
  139. DataTable dtuserlist = mainService.GetDataTableResult("source", "select * from LR_Base_User where F_EnabledMark=1 and F_DeleteMark=0");
  140. for (int i = 0; i < dtuserlist.Rows.Count; i++)
  141. {
  142. string md5pwd=Md5Helper.Hash("123456");
  143. string dbPassword = Md5Helper.Encrypt(DESEncrypt.Encrypt(md5pwd, dtuserlist.Rows[i]["F_Secretkey"].ToString()).ToLower(), 32).ToLower();
  144. if (dbPassword == dtuserlist.Rows[i]["F_Password"].ToString())
  145. {
  146. rtblog.AppendText("帐户"+dtuserlist.Rows[i]["F_Account"]+" 姓名:"+ dtuserlist.Rows[i]["F_RealName"] + "\r\n");
  147. }
  148. }
  149. }
  150. }
  151. }