選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

159 行
5.9 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. ThreadStart threadstart = new ThreadStart(TransferCoreData);
  113. mainthread = new Thread(threadstart);
  114. mainthread.Name = "main";
  115. mainthread.Start();
  116. }
  117. private void btsyncmis_Click(object sender, EventArgs e)
  118. {
  119. ThreadStart threadstart = new ThreadStart(TransferMisData);
  120. mainthread = new Thread(threadstart);
  121. mainthread.Name = "main";
  122. mainthread.Start();
  123. }
  124. public void TransferCoreData()
  125. {
  126. SyncWindow progress = new SyncWindow("core");
  127. progress.ShowDialog();
  128. }
  129. public void TransferMisData()
  130. {
  131. SyncWindow progress = new SyncWindow("mis");
  132. progress.ShowDialog();
  133. }
  134. private void 查找密码为123456的ToolStripMenuItem_Click(object sender, EventArgs e)
  135. {
  136. MainService mainService = new MainService();
  137. DataTable dtuserlist = mainService.GetDataTableResult("source", "select * from LR_Base_User where F_EnabledMark=1 and F_DeleteMark=0");
  138. for (int i = 0; i < dtuserlist.Rows.Count; i++)
  139. {
  140. string md5pwd=Md5Helper.Hash("123456");
  141. string dbPassword = Md5Helper.Encrypt(DESEncrypt.Encrypt(md5pwd, dtuserlist.Rows[i]["F_Secretkey"].ToString()).ToLower(), 32).ToLower();
  142. if (dbPassword == dtuserlist.Rows[i]["F_Password"].ToString())
  143. {
  144. rtblog.AppendText("帐户"+dtuserlist.Rows[i]["F_Account"]+" 姓名:"+ dtuserlist.Rows[i]["F_RealName"] + "\r\n");
  145. }
  146. }
  147. }
  148. }
  149. }