using AttachmentDemo.Helper; using AttachmentDemo.Model; using KAttachmentDemo.Helper; using KGIS.Framework.DBOperator; using Refit; using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Data.SQLite; using System.IO; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace AttachmentDemo { /// /// MainWindow.xaml 的交互逻辑 /// public partial class MainWindow : Window { //string baseUrl = @"http://dp.kingoit.com:90/";// @"https://localhost:44382/"; string baseUrl = ConfigurationManager.AppSettings["BaseUrl"].ToString(); List oldCertificateInfo = new List(); List oldAttachmentInfo = new List(); DataView DtFjxx = new DataView(); DataView DtJmxx = new DataView(); public MainWindow() { InitializeComponent(); dataGridFJ.ItemsSource = DtFjxx; dataGridJMXX.ItemsSource = DtJmxx; } private void btChange_Click(object sender, RoutedEventArgs e) { stateLabel.Content = ""; GetJMXXMessage(out oldCertificateInfo); GetFJMessage(out oldAttachmentInfo); Change(); } private async void Change() { try { await Login(); var taskwebpi = RestService.For(AuthHttpClient.Instance); string path = string.Format(tbFilePath.Text); KGIS.Framework.DBOperator.IRDBHelper rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + path, DatabaseType.SQLite); //附件信息表更新 var aulistFj = await taskwebpi.GetAttachmentInfo(oldAttachmentInfo); if (oldAttachmentInfo != null&& oldAttachmentInfo.Count > 0) { if (aulistFj.Code == 200) { //说明 1、如果返回数据中的某一条 ZSDM = "" 并且JYM = "" 说明该条数据 临时校验失败 //说明 2、如果返回数据中的某一条 ZSDM = "" 并且JYM = "提交原始校验码" 说明该条数据 正式签名失败 for (int i = 0; i < aulistFj.Data.Count; i++) { if (aulistFj.Data[i].ZSDM == "" && (aulistFj.Data[i].JYM == "" || aulistFj.Data[i].JYM == "提交原始校验码")) { DtFjxx.Table.Rows[i]["ZT"] = "失败"; continue; } else if (aulistFj.Data[i].ZSDM == oldAttachmentInfo[i].ZSDM && aulistFj.Data[i].JYM == oldAttachmentInfo[i].JYM) { DtFjxx.Table.Rows[i]["ZT"] = "转换值与原始值相同"; continue; } string sql = string.Format("update FJ set JYM='{0}', ZSDM='{1}' where BSM = '{2}' ", aulistFj.Data[i].JYM, aulistFj.Data[i].ZSDM, aulistFj.Data[i].BSM); rdbHelper.ExecuteSQL(sql); DtFjxx.Table.Rows[i]["JYM"] = aulistFj.Data[i].JYM; DtFjxx.Table.Rows[i]["ZSDM"] = aulistFj.Data[i].ZSDM; DtFjxx.Table.Rows[i]["ZT"] = "成功"; } } } //加密信息表更新 for (int i = 0; i < DtJmxx.Table.Rows.Count; i++) { var aulistJmxx = await taskwebpi.GetCertificateInfo(oldCertificateInfo[i].ZSDM); if (aulistJmxx.Code == 200) { if (aulistJmxx.Data.ZSDM == "" || aulistJmxx.Data.ZSDM == null) { DtJmxx.Table.Rows[i]["ZT"] = "失败"; continue; } else if (aulistJmxx.Data.ZSDM == oldCertificateInfo[i].ZSDM && aulistJmxx.Data.SZZS == oldCertificateInfo[i].SZZS && aulistJmxx.Data.ZSBFJGDM == oldCertificateInfo[i].ZSBFJGDM && aulistJmxx.Data.ZSBFJGGY == oldCertificateInfo[i].ZSBFJGGY && aulistJmxx.Data.QKLFWDZ == oldCertificateInfo[i].QKLFWDZ) { DtJmxx.Table.Rows[i]["ZT"] = "转换值与原始值相同"; continue; } string sql = string.Format("update JMXX set ZSDM='{0}', SZZS='{1}', ZSBFJGDM='{2}', ZSBFJGGY='{3}', QKLFWDZ='{4}' where ZSDM = '{5}' ", aulistJmxx.Data.ZSDM, aulistJmxx.Data.SZZS, aulistJmxx.Data.ZSBFJGDM, aulistJmxx.Data.ZSBFJGGY, aulistJmxx.Data.QKLFWDZ, oldCertificateInfo[i].ZSDM); rdbHelper.ExecuteSQL(sql); DtJmxx.Table.Rows[i]["ZSDM"] = aulistJmxx.Data.ZSDM; DtJmxx.Table.Rows[i]["SZZS"] = aulistJmxx.Data.SZZS; DtJmxx.Table.Rows[i]["ZSBFJGDM"] = aulistJmxx.Data.ZSBFJGDM; DtJmxx.Table.Rows[i]["ZSBFJGGY"] = aulistJmxx.Data.ZSBFJGGY; DtJmxx.Table.Rows[i]["QKLFWDZ"] = aulistJmxx.Data.QKLFWDZ; DtJmxx.Table.Rows[i]["ZT"] = "成功"; } else DtJmxx.Table.Rows[i]["ZT"] = "失败"; } rdbHelper.DisConnect(); stateLabel.Content = "状态:执行完成"; } catch (Exception e) { stateLabel.Content = "状态:执行失败!" + e.Message; return; } } private void btSelectFile_Click(object sender, RoutedEventArgs e) { IRDBHelper dbHelper = null; try { System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog(); if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)//注意,此处一定要手动引入System.Window.Forms空间,否则你如果使用默认的DialogResult会发现没有OK属性 { tbFilePath.Text = openFileDialog.FileName; dbHelper = RDBFactory.CreateDbHelper("Data Source=" + openFileDialog.FileName, DatabaseType.SQLite); DtFjxx.Table = dbHelper.ExecuteDatatable("FJXX", "select * from FJ", true); DtFjxx.Table.Columns.Add("ZT"); DtJmxx.Table = dbHelper.ExecuteDatatable("JMXX", "select * from JMXX", true); DtJmxx.Table.Columns.Add("ZT"); dbHelper.DisConnect(); } } catch (Exception ex) { } } private void GetFJMessage(out List oldAttachmentInfo) { oldAttachmentInfo = new List(); try { foreach (System.Data.DataRow dr in DtFjxx.Table.Rows) { var attachmentInfo = new AttachmentInfo() { BSM = dr["BSM"].ToString().Trim(), FJHXZ = dr["FJHXZ"].ToString().Trim(), FJMC = dr["FJMC"].ToString().Trim(), Latitude = dr["Latitude"].ToString().Trim(), Longitude = dr["Longitude"].ToString().Trim(), PSFYJ = dr["PSFYJ"].ToString().Trim(), PSHGJ = dr["PSHGJ"].ToString().Trim(), PSJD = dr["PSJD"].ToString().Trim(), PSRY = dr["PSRY"].ToString().Trim(), PSSJ = dr["PSSJ"].ToString().Trim(), TBBSM = dr["TBBSM"].ToString().Trim(), TBLX = dr["TBLX"].ToString().Trim(), XZQDM = dr["XZQDM"].ToString().Trim(), ZSDM = dr["ZSDM"].ToString().Trim(), JYM = dr["JYM"].ToString().Trim() }; oldAttachmentInfo.Add(attachmentInfo); } } catch (Exception ex) { return; } } private void GetJMXXMessage(out List oldCertificateInfo) { oldCertificateInfo = new List(); try { foreach (System.Data.DataRow dr in DtJmxx.Table.Rows) { var certificateInfo = new Certificate() { ZSDM = dr["ZSDM"].ToString().Trim(), SZZS = dr["SZZS"].ToString().Trim(), ZSBFJGDM = dr["ZSBFJGDM"].ToString().Trim(), ZSBFJGGY = dr["ZSBFJGGY"].ToString().Trim(), QKLFWDZ = dr["QKLFWDZ"].ToString().Trim() }; oldCertificateInfo.Add(certificateInfo); } } catch (Exception ex) { return; } } private async Task Login() { //验证用户名密码 var gitHubApi = RestService.For(baseUrl); var userdata = await gitHubApi.Login(new UserContext() { LoginName = "licAdmin", Password = Md5Helper.Md5("Kingo_It#7739@93")//这个密码是固定的 最后由其他字符串解密后得到 //Base64Helper.EncodeBase64("Kingo_It#7739@93")//采用MD5加密 }); if (userdata.Code == 200) { AuthHttpClient.SetHttpClient(baseUrl, userdata.Data.TokenStr);//data 为token } } } }