|
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Configuration;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using Learun.Util;
-
- namespace Quanjiang.DigitalScholl.DataSync
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
-
- private void btcheck_Click(object sender, EventArgs e)
- {
- if (tbsource.Text.Trim() != "" && tbtarget.Text.Trim() != "")
- {
- //写
- var opencon = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
- opencon.ConnectionStrings.ConnectionStrings["source"].ConnectionString = tbsource.Text.Trim();
- opencon.ConnectionStrings.ConnectionStrings["target"].ConnectionString = tbtarget.Text.Trim();
- opencon.ConnectionStrings.ConnectionStrings["missource"].ConnectionString = tbmissource.Text.Trim();
- opencon.ConnectionStrings.ConnectionStrings["mistarget"].ConnectionString = tbmistarget.Text.Trim();
- opencon.Save(ConfigurationSaveMode.Full);
- //连
- if (Check().Result)
- {
- rtblog.AppendText("数据库连接成功!\r\n");
- btsync.Enabled = true;
- }
- else
- {
- btcheck.Enabled = true;
- }
- }
- else
- {
- MessageBox.Show("请输入连接字符串");
- }
- }
-
- public async Task<bool> Check()
- {
- btcheck.Enabled = false;
- bool result = false;
- result = await CheckConnection(tbsource.Text.Trim(), "源");
- if (result)
- {
- rtblog.AppendText("源数据库连接成功...\r\n");
- }
- result = result && await CheckConnection(tbtarget.Text.Trim(), "目标");
- if (result)
- {
- rtblog.AppendText("目标数据库连接成功...\r\n");
- }
- result = result && await CheckConnection(tbmissource.Text.Trim(), "源mis");
- if (result)
- {
- rtblog.AppendText("源mis数据库连接成功...\r\n");
- }
- result = result && await CheckConnection(tbmistarget.Text.Trim(), "目标mis");
- if (result)
- {
- rtblog.AppendText("目标mis数据库连接成功...\r\n");
- }
- return result;
- }
-
- public async Task<bool> CheckConnection(string conn, string target)
- {
- MainService main = new MainService();
- rtblog.AppendText("开始检测" + target + "数据库连接...\r\n");
- var result = await main.CheckConnection(conn);
- if (!result.result)
- {
- rtblog.AppendText(target + "数据库连接失败,请检查网络和连接字符串!\r\n");
- rtblog.AppendText(result.errormessage + "\r\n");
- }
- return result.result;
- }
-
- private void btsync_Click(object sender, EventArgs e)
- {
- if (clbmodule.CheckedItems.Count == 0)
- {
- MessageBox.Show("请选择要同步的模块");
- return;
- }
- MainService main = new MainService();
- bool result = Task.Run(() => main.BeginSync(clbmodule.CheckedItems)).Result;
- if (result)
- {
- MessageBox.Show("同步完成");
- btsync.Enabled = true;
- }
- }
-
- private void Form1_Load(object sender, EventArgs e)
- {
- tbsource.Text = ConfigurationManager.ConnectionStrings["source"].ConnectionString;
- tbtarget.Text = ConfigurationManager.ConnectionStrings["target"].ConnectionString;
- tbmissource.Text = ConfigurationManager.ConnectionStrings["missource"].ConnectionString;
- tbmistarget.Text = ConfigurationManager.ConnectionStrings["mistarget"].ConnectionString;
- }
-
- Thread mainthread = null;
- private void btsynccore_Click(object sender, EventArgs e)
- {
- Program.beginTable = txtBeginTable.Text;
- ThreadStart threadstart = new ThreadStart(TransferCoreData);
- mainthread = new Thread(threadstart);
- mainthread.Name = "main";
- mainthread.Start();
- }
-
- private void btsyncmis_Click(object sender, EventArgs e)
- {
- Program.beginTable = txtBeginTable.Text;
- ThreadStart threadstart = new ThreadStart(TransferMisData);
- mainthread = new Thread(threadstart);
- mainthread.Name = "main";
- mainthread.Start();
- }
- public void TransferCoreData()
- {
- SyncWindow progress = new SyncWindow("core");
- progress.ShowDialog();
- }
- public void TransferMisData()
- {
- SyncWindow progress = new SyncWindow("mis");
- progress.ShowDialog();
- }
-
- private void 查找密码为123456的ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- MainService mainService = new MainService();
- DataTable dtuserlist = mainService.GetDataTableResult("source", "select * from LR_Base_User where F_EnabledMark=1 and F_DeleteMark=0");
- for (int i = 0; i < dtuserlist.Rows.Count; i++)
- {
- string md5pwd=Md5Helper.Hash("123456");
- string dbPassword = Md5Helper.Encrypt(DESEncrypt.Encrypt(md5pwd, dtuserlist.Rows[i]["F_Secretkey"].ToString()).ToLower(), 32).ToLower();
- if (dbPassword == dtuserlist.Rows[i]["F_Password"].ToString())
- {
- rtblog.AppendText("帐户"+dtuserlist.Rows[i]["F_Account"]+" 姓名:"+ dtuserlist.Rows[i]["F_RealName"] + "\r\n");
- }
- }
- }
- }
- }
|