基线 SVN r240

SVN-Revision: r240
This commit is contained in:
cyf
2025-02-06 06:46:06 +00:00
commit ab56a9bcf7
5317 changed files with 902274 additions and 0 deletions
@@ -0,0 +1,120 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace Lskj_SynchronizeData
{
/// <summary>
/// AES对称加密
/// </summary>
public class AESUtil
{
private static string key = "lserpasebygyc222";
#region AES加解密
/// <summary>
///AES加密(加密步骤)
///1,加密字符串得到2进制数组;
///2,将2进制数组转为16进制;
///3,进行base64编码
/// </summary>
/// <param name="toEncrypt">要加密的字符串</param>
/// <param name="key">密钥</param>
public static string Encrypt(string toEncrypt)
{
if (string.IsNullOrEmpty(toEncrypt)) return "";
byte[] _key = Encoding.ASCII.GetBytes(key);
byte[] _source = Encoding.UTF8.GetBytes(toEncrypt);
Aes aes = Aes.Create("AES");
aes.Mode = CipherMode.ECB;
aes.Padding = PaddingMode.PKCS7;
aes.Key = _key;
ICryptoTransform cTransform = aes.CreateEncryptor();
byte[] cryptData = cTransform.TransformFinalBlock(_source, 0, _source.Length);
string hexCryptString = Hex_2To16(cryptData);
byte[] hexCryptData = Encoding.UTF8.GetBytes(hexCryptString);
return Convert.ToBase64String(hexCryptData);
}
/// <summary>
/// AES解密(解密步骤)
/// 1,将BASE64字符串转为16进制数组
/// 2,将16进制数组转为字符串
/// 3,将字符串转为2进制数据
/// 4,用AES解密数据
/// </summary>
/// <param name="encryptedSource">已加密的内容</param>
/// <param name="key">密钥</param>
public static string Decrypt(string toDecrypt)
{
if (string.IsNullOrEmpty(toDecrypt)) return "";
try
{
byte[] _key = Encoding.ASCII.GetBytes(key);
Aes aes = Aes.Create("AES");
aes.Mode = CipherMode.ECB;
aes.Padding = PaddingMode.PKCS7;
aes.Key = _key;
ICryptoTransform cTransform = aes.CreateDecryptor();
byte[] encryptedData = Convert.FromBase64String(toDecrypt);
string encryptedString = Encoding.UTF8.GetString(encryptedData);
byte[] _source = Hex_16To2(encryptedString);
byte[] originalSrouceData = cTransform.TransformFinalBlock(_source, 0, _source.Length);
return Encoding.UTF8.GetString(originalSrouceData);
}
catch (Exception)
{
return "";
}
}
/// <summary>
/// 2进制转16进制
/// </summary>
static string Hex_2To16(byte[] bytes)
{
string hexString = string.Empty;
Int32 iLength = 65535;
if (bytes != null)
{
StringBuilder strB = new StringBuilder();
if (bytes.Length < iLength)
{
iLength = bytes.Length;
}
for (int i = 0; i < iLength; i++)
{
strB.Append(bytes[i].ToString("X2"));
}
hexString = strB.ToString();
}
return hexString;
}
/// <summary>
/// 16进制转2进制
/// </summary>
static byte[] Hex_16To2(string hexString)
{
if ((hexString.Length % 2) != 0)
{
hexString += " ";
}
byte[] returnBytes = new Byte[hexString.Length / 2];
for (Int32 i = 0; i < returnBytes.Length; i++)
{
returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
}
return returnBytes;
}
#endregion
}
}
@@ -0,0 +1,144 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
using System.Data.SqlClient;
using System.Data;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Diagnostics;
using System.Windows.Forms;
namespace Lskj_SynchronizeData
{
/// <summary>
/// 数据库连接参数配置类
/// </summary>
public sealed class DBConfig
{
private static string _regKey = "AA_LS_Erp V2.0";
private static DBConfig _instance = null;
/// <summary>
/// DBConfig静态单例对象
/// </summary>
/// <value>The instance.</value>
public static DBConfig Instance
{
get
{
if (_instance == null)
{
_instance = new DBConfig();
_instance.ReadConfig();
}
return _instance;
}
}
/// <summary>
/// 数据库名
/// </summary>
public string DataBase;
/// <summary>
/// 服务器名
/// </summary>
public string ServerName;
/// <summary>
/// 登录名
/// </summary>
public string LoginName;
public string Connection1 = "QkYyNjE3QTcxQjc4RDFFMDlERjlFMDc1QkIyMDVGRjdDRUIyMEVEOUM5NjBCQjc5NTA5NzdEQTk0MkNEQTE1RTFGMEIwMThFNUJDQTE0RjE1NjQwM0U5QTYxMThCMDY2MTA4NkE2OTIxNTNBQjQ0MjRDMDIwM0Q5OEVDQjkwQTVCN0RENjJBODkxNUNGOUM5OEI5RTEzN0E3ODBERjg2OURCNEQ5QTlCMzhCQUZGQ0FBNUREMjY4M0FCODg2RTkxMDRERTQ3MjRGQTE1MERDOTJGRDFDRjY2REQ1ODYyREUzN0RGM0ZBQzc4NzJENjIwNDg4RUUyNkI3ODE1RjlDM0I0MjNCQzcyOENDN0VDMTg0QUU0MjgwMDVDMENBOUZF";
/// <summary>
/// <para>说明:读取注册表配置</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-08-07 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
public void ReadConfig()
{
RegistryKey regKey = Registry.CurrentUser;
try
{
RegistryKey erpKey = regKey.CreateSubKey("AA_LS_Erp V2.0");
erpKey.CreateSubKey("File");
}
catch (Exception)
{
}
RegistryKey subKey = regKey.OpenSubKey(_regKey);
subKey = subKey.OpenSubKey("File", true);
DataBase = subKey.GetValue("datastr", "") + "";
ServerName = subKey.GetValue("ServerName", "") + "";
LoginName = subKey.GetValue("LoginName", "") + "";
if (subKey.GetValue("IsCmpCapture") == null)
{
subKey.SetValue("IsCmpCapture", 0);
}
}
/// <summary>
/// <para>说明:获取C#连接字符串</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-08-07 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <returns>System.String.</returns>
public string GetConnection()
{
return string.Format(AESUtil.Decrypt(Connection1), ServerName, DataBase);
}
/// <summary>
/// <para>说明:创建数据库连接</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-08-07 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
public bool CreateConnection()
{
string connStr = GetConnection();
if (SqlHelper._connection != null)
{
try
{
SqlHelper._connection.Close();
SqlHelper._connection.Dispose();
}
catch (Exception)
{
}
SqlHelper._connection = null;
}
try
{
SqlHelper._connection = new SqlConnection(connStr);
SqlHelper._connection.Open();
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return false;
}
}
}
+121
View File
@@ -0,0 +1,121 @@
namespace Lskj_SynchronizeData
{
partial class FrMain
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.txt_log = new System.Windows.Forms.TextBox();
this.pal_top = new System.Windows.Forms.Panel();
this.btnSuspend = new System.Windows.Forms.Button();
this.btnStart = new System.Windows.Forms.Button();
this.panel1.SuspendLayout();
this.pal_top.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.Controls.Add(this.txt_log);
this.panel1.Controls.Add(this.pal_top);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(674, 479);
this.panel1.TabIndex = 0;
//
// txt_log
//
this.txt_log.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txt_log.Dock = System.Windows.Forms.DockStyle.Fill;
this.txt_log.Font = new System.Drawing.Font("微软雅黑", 10F);
this.txt_log.Location = new System.Drawing.Point(0, 50);
this.txt_log.Multiline = true;
this.txt_log.Name = "txt_log";
this.txt_log.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.txt_log.Size = new System.Drawing.Size(674, 429);
this.txt_log.TabIndex = 2;
//
// pal_top
//
this.pal_top.Controls.Add(this.btnSuspend);
this.pal_top.Controls.Add(this.btnStart);
this.pal_top.Dock = System.Windows.Forms.DockStyle.Top;
this.pal_top.Location = new System.Drawing.Point(0, 0);
this.pal_top.Name = "pal_top";
this.pal_top.Size = new System.Drawing.Size(674, 50);
this.pal_top.TabIndex = 0;
//
// btnSuspend
//
this.btnSuspend.Font = new System.Drawing.Font("微软雅黑", 10F);
this.btnSuspend.Location = new System.Drawing.Point(122, 10);
this.btnSuspend.Name = "btnSuspend";
this.btnSuspend.Size = new System.Drawing.Size(75, 31);
this.btnSuspend.TabIndex = 1;
this.btnSuspend.Text = "暂停";
this.btnSuspend.UseVisualStyleBackColor = true;
this.btnSuspend.Click += new System.EventHandler(this.OnSuspendClick);
//
// btnStart
//
this.btnStart.Font = new System.Drawing.Font("微软雅黑", 10F);
this.btnStart.Location = new System.Drawing.Point(32, 10);
this.btnStart.Name = "btnStart";
this.btnStart.Size = new System.Drawing.Size(75, 31);
this.btnStart.TabIndex = 0;
this.btnStart.Text = "开始";
this.btnStart.UseVisualStyleBackColor = true;
this.btnStart.Click += new System.EventHandler(this.OnStartClick);
//
// FrMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(674, 479);
this.Controls.Add(this.panel1);
this.Font = new System.Drawing.Font("宋体", 10F);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Name = "FrMain";
this.Text = "同步数据";
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.pal_top.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Panel pal_top;
private System.Windows.Forms.Button btnSuspend;
private System.Windows.Forms.Button btnStart;
private System.Windows.Forms.TextBox txt_log;
}
}
+418
View File
@@ -0,0 +1,418 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Lskj_SynchronizeData
{
public partial class FrMain : Form
{
public string Connection1 = "QkYyNjE3QTcxQjc4RDFFMDlERjlFMDc1QkIyMDVGRjdDRUIyMEVEOUM5NjBCQjc5NTA5NzdEQTk0MkNEQTE1RTFGMEIwMThFNUJDQTE0RjE1NjQwM0U5QTYxMThCMDY2MTA4NkE2OTIxNTNBQjQ0MjRDMDIwM0Q5OEVDQjkwQTVCN0RENjJBODkxNUNGOUM5OEI5RTEzN0E3ODBERjg2OURCNEQ5QTlCMzhCQUZGQ0FBNUREMjY4M0FCODg2RTkxMDRERTQ3MjRGQTE1MERDOTJGRDFDRjY2REQ1ODYyREUzN0RGM0ZBQzc4NzJENjIwNDg4RUUyNkI3ODE1RjlDM0I0MjNCQzcyOENDN0VDMTg0QUU0MjgwMDVDMENBOUZF";
/// <summary>
/// 远程数据库名
/// </summary>
public string DataBase = "lskj_weixin";
/// <summary>
/// 远程服务器名
/// </summary>
private string serverName = "114.116.152.217,14331";
/// <summary>
/// 本地数据库名
/// </summary>
private string localDBName;
/// <summary>
/// 本地服务器名
/// </summary>
private string localServer;
/// <summary>
/// 数据库远程连接字符串
/// </summary>
string connStr;
/// <summary>
/// 数据库本地连接字符串
/// </summary>
string localconnStr;
private System.Timers.Timer timer = new System.Timers.Timer();
private DataTable localDt;
public FrMain()
{
InitializeComponent();
}
/// <summary>
/// <para>说明:初始化</para>
/// <para>创建人:钱雄</para>
/// <para>创建日期:2020-11-07 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="item">The item.</param>
protected override void OnLoad(EventArgs e) {
//设置timer
timer.Interval = 1000*60;
//设置是否重复计时,如果该属性设为False,则只执行timer_Elapsed方法一次。
timer.AutoReset = true;
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
bool localConn = DBConfig.Instance.CreateConnection();
bool romoteConn = CreateConnection();
}
#region
/// <summary>
/// <para>说明:开始按钮点击</para>
/// <para>创建人:钱雄</para>
/// <para>创建日期:2020-11-27 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
private void OnStartClick(object sender, EventArgs e)
{
timer.Enabled = true;
this.txt_log.Text = "";
RefreshLog(DateTime.Now + ":定时器启动中,请稍后\r\n");
}
/// <summary>
/// 显示信息设置
/// </summary>
/// <param name="msg"></param>
public void RefreshLog(string msg)
{
Invoke((EventHandler)delegate
{
this.txt_log.Text += msg;
this.txt_log.Focus();//获取焦点
this.txt_log.Select(this.txt_log.TextLength, 0);//光标定位到文本最后
this.txt_log.ScrollToCaret();//滚动到光标处
});
}
/// <summary>
/// <para>说明:暂停按钮点击</para>
/// <para>创建人:钱雄</para>
/// <para>创建日期:2020-11-27 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
private void OnSuspendClick(object sender, EventArgs e)
{
timer.Enabled = false;
}
/// <summary>
/// <para>说明:初始化表按钮点击</para>
/// <para>创建人:钱雄</para>
/// <para>创建日期:2020-11-27 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
private void OnInitTable(object sender, EventArgs e)
{
string createSql;
if (DBConfig.Instance.CreateConnection()) {
localconnStr = DBConfig.Instance.GetConnection();
string sqlValue = string.Format("select count(1) as result from sys.objects where name = 'P_SystemMSGSendTab'");
string sqlValue1 = string.Format("select count(1) as result from sys.objects where name = 'P_SystemMSGSendListTab'");
try {
if (SqlHelper.ExecuteDataTable(sqlValue).Rows[0]["result"] + "" != "1")
{
createSql = "CREATE TABLE P_SystemMSGSendTab(id int IDENTITY(1,1) NOT NULL,msgID bigint NULL,ClientCode varchar(50) NULL,OpenID varchar(50) NULL,MsgInfo varchar(500) NULL,MsgLink varchar(max) NULL,CreateTime datetime NULL,SendTime datetime NULL,SendStatus int NULL,StatusMsg varchar(150) NULL,msgType varchar(50) NULL,msg_first varchar(500) NULL,msg_keyword1 [varchar](300) NULL,msg_keyword2 varchar(300) NULL,msg_keyword3 varchar(300) NULL,msg_keyword4 varchar(300) NULL, msg_keyword5 varchar(300) NULL,msg_remark varchar(500) NULL,isSync int NULL, PRIMARY KEY CLUSTERED (id ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]";
if (SqlHelper.ExecuteNonQuery(createSql) > 0)
{
MessageBox.Show("表P_SystemMSGSendTab创建成功");
}
}
if (SqlHelper.ExecuteDataTable(sqlValue1).Rows[0]["result"] + "" != "1")
{
createSql = "CREATE TABLE P_SystemMSGSendListTab(id int IDENTITY(1,1) NOT NULL,msgID bigint NULL,ClientCode varchar(50) NULL,OpenID varchar(50) NULL,MsgInfo varchar(500) NULL,MsgLink varchar(max) NULL,CreateTime datetime NULL,SendTime datetime NULL,SendStatus int NULL,StatusMsg varchar(150) NULL,msgType varchar(50) NULL,msg_first varchar(500) NULL,msg_keyword1 [varchar](300) NULL,msg_keyword2 varchar(300) NULL,msg_keyword3 varchar(300) NULL,msg_keyword4 varchar(300) NULL, msg_keyword5 varchar(300) NULL,msg_remark varchar(500) NULL,isSync int NULL, PRIMARY KEY CLUSTERED (id ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]";
if (SqlHelper.ExecuteNonQuery(createSql) > 0)
{
MessageBox.Show("表P_SystemMSGSendListTab创建成功");
}
}
}
catch(Exception ex) {
MessageBox.Show(ex.Message);
}
}
}
/// <summary>
/// <para>说明:定时器事件</para>
/// <para>创建人:钱雄</para>
/// <para>创建日期:2020-11-27 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (this.txt_log.Lines.Count() > 1000)
{
this.txt_log.Text = "";
}
SynchronizeData();
timer.Enabled = true;
}
#endregion
/// <summary>
/// <para>说明:同步数据</para>
/// <para>创建人:钱雄</para>
/// <para>创建日期:2020-11-27 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
private void SynchronizeData() {
timer.Enabled = false;
string sqlValue = string.Empty;
string result = string.Empty;
RefreshLog(DateTime.Now + ":准备插入数据\r\n");
//本地数据库连接
try
{
if (DBConfig.Instance.CreateConnection())
{
//MessageBox.Show("本地数据库连接成功");
localDBName = DBConfig.Instance.DataBase;
localServer = DBConfig.Instance.ServerName;
localconnStr = DBConfig.Instance.GetConnection();
sqlValue = string.Format("select count(1) as result from sys.objects where name = 'P_SystemMSGSendTab'");
result = SqlHelper.ExecuteDataTable(sqlValue).Rows[0]["result"] + "";
if (result == "1")
{
//判断字段是否存在
string existSql = "select count(1) as result from syscolumns where id=object_id('P_SystemMSGSendTab') and name='isSync'";
result = SqlHelper.ExecuteDataTable(existSql).Rows[0]["result"] + "";
if (result != "1")
{
string alterSql = "alter table P_SystemMSGSendTab add isSync bit not null default 0";
SqlHelper.ExecuteNonQuery(alterSql);
}
localDt = SqlHelper.ExecuteDataTable("select * from P_SystemMSGSendTab where isSync=0");
}
else
{
RefreshLog(DateTime.Now + ":当前数据库没有对应表\r\n");
timer.Enabled = false;
}
}
}
catch(Exception e) {
MessageBox.Show(e.Message);
}
try
{
//远程数据库连接
if (CreateConnection())
{
sqlValue = string.Format("select count(1) as result from sys.objects where name = 'P_SystemMSGSendTab'");
result = SqlHelper.ExecuteDataTable(sqlValue).Rows[0]["result"] + "";
if (result == "1" && localDt.Rows.Count > 0)
{
//RefreshLog(DateTime.Now + ":数据插入中\r\n");
WriteDataToDB(localDt, "P_SystemMSGSendTab");
}
else
{
RefreshLog(DateTime.Now + ":没有要插入的数据\r\n");
}
}
else {
RefreshLog(DateTime.Now + ":远程数据库连接失败\r\n");
}
//timer.Enabled = true;
}
catch(Exception ex) {
MessageBox.Show(ex.Message);
}
}
/// <summary>
/// <para>说明:创建数据库连接</para>
/// <para>创建人:钱雄</para>
/// <para>创建日期:2020-11-27 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
public bool CreateConnection()
{
connStr = GetConnection();
if (SqlHelper._connection != null)
{
try
{
SqlHelper._connection.Close();
SqlHelper._connection.Dispose();
}
catch (Exception)
{
}
SqlHelper._connection = null;
}
try
{
SqlHelper._connection = new SqlConnection(connStr);
SqlHelper._connection.Open();
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return false;
}
/// <summary>
/// <para>说明:获取C#连接字符串</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-08-07 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <returns>System.String.</returns>
public string GetConnection()
{
return string.Format(AESUtil.Decrypt(Connection1), serverName, DataBase);
}
/// <summary>
/// 将DataTable中数据写入数据库中
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
public bool WriteDataToDB(DataTable dt, string tableName)
{
if (dt == null || dt.Rows.Count == 0)
{
return true;
}
string colNames = "";
for (int i = 0; i < dt.Columns.Count; i++)
{
if ((i == 0) || (i == dt.Columns.Count - 1)) continue;
colNames += dt.Columns[i].ColumnName + ",";
}
colNames = colNames.TrimEnd(',');
string cmd = "";
string colValues;
int count = 0;
string ids = string.Empty;
//string cmdmode = string.Format("insert into {0}({1}) values({{0}});", tableName, colNames);
string cmdmode = string.Format("insert into OPENDATASOURCE('SQLOLEDB','{0}').{1}.dbo.{2} ({3}) values({{0}});", connStr, DataBase, tableName, colNames);
for (int i = 0; i < dt.Rows.Count; i++)
{
ids += dt.Rows[i][0] + ",";
//bool isSync;
colValues = "";
//isSync = string.IsNullOrEmpty(dt.Rows[i][dt.Columns.Count - 1] + "") ? false : Convert.ToBoolean(dt.Rows[i][dt.Columns.Count - 1]);
//if (!isSync) {
for (int j = 0; j < dt.Columns.Count; j++)
{
count++;
if (j == 0 || j == dt.Columns.Count - 1) continue;
if (dt.Rows[i][j].GetType() == typeof(DBNull))
{
colValues += "NULL,";
continue;
}
if (dt.Columns[j].DataType == typeof(string))
colValues += string.Format("'{0}',", dt.Rows[i][j]);
else if (dt.Columns[j].DataType == typeof(int) || dt.Columns[j].DataType == typeof(float) || dt.Columns[j].DataType == typeof(double))
{
colValues += string.Format("{0},", dt.Rows[i][j]);
}
else if (dt.Columns[j].DataType == typeof(DateTime))
{
colValues += string.Format("cast('{0}' as datetime),", dt.Rows[i][j]);
}
else if (dt.Columns[j].DataType == typeof(bool))
{
colValues += string.Format("{0},", dt.Rows[i][j].ToString());
}
else
colValues += string.Format("'{0}',", dt.Rows[i][j]);
}
cmd += string.Format(cmdmode, colValues.TrimEnd(','));
//count++;
//}
}
int ret = 0;
try
{
if (count > 0)
{
RefreshLog(DateTime.Now + ":数据插入中\r\n");
ret = SqlHelper.ExecuteNonQuery(cmd);
RefreshLog(DateTime.Now + ":成功插入" + ret + "条数据\r\n");
}
}
catch (Exception e)
{
//写错误日志...
string strOuput = string.Format("向数据库中写数据失败,错误信息:{0},异常{1}\n", e.Message, e.InnerException);
RefreshLog(DateTime.Now + strOuput + "\r\n");
}
if (ret == -1)
{
return false;
}
ids = ids.TrimEnd(',');
if (count == 0)
{
RefreshLog(DateTime.Now + "没有要插入的数据\r\n");
}
try
{
string updateValue = string.Format("Update OPENDATASOURCE('SQLOLEDB','{0}').{1}.dbo.P_SystemMSGSendTab set isSync=1 where id in ({2})", localconnStr, localDBName, ids);
if (DBConfig.Instance.CreateConnection()&&SqlHelper.ExecuteNonQuery(updateValue) > 0) {
RefreshLog(DateTime.Now + ":本地表字段isSync修改成功\r\n");
}
}
catch(Exception e) {
RefreshLog(DateTime.Now + ":" + e.Message+"\r\n");
}
return true;
}
}
}
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{536A3290-9E2A-4F42-AF9A-DEDE1917A852}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Lskj_SynchronizeData</RootNamespace>
<AssemblyName>Lskj_SynchronizeData</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Data" />
<Reference Include="System.Data.Linq" />
<Reference Include="System.Runtime.Remoting" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="UIAutomationClient" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="AESUtil.cs" />
<Compile Include="DBConfig.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SqlHelper.cs" />
<Compile Include="FrMain.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="FrMain.Designer.cs">
<DependentUpon>FrMain.cs</DependentUpon>
</Compile>
<EmbeddedResource Include="Properties\licenses.licx" />
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<EmbeddedResource Include="FrMain.resx">
<DependentUpon>FrMain.cs</DependentUpon>
</EmbeddedResource>
<None Include="app.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
@@ -0,0 +1,20 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lskj_SynchronizeData", "Lskj_SynchronizeData.csproj", "{536A3290-9E2A-4F42-AF9A-DEDE1917A852}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{536A3290-9E2A-4F42-AF9A-DEDE1917A852}.Debug|x86.ActiveCfg = Debug|x86
{536A3290-9E2A-4F42-AF9A-DEDE1917A852}.Debug|x86.Build.0 = Debug|x86
{536A3290-9E2A-4F42-AF9A-DEDE1917A852}.Release|x86.ActiveCfg = Release|x86
{536A3290-9E2A-4F42-AF9A-DEDE1917A852}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace Lskj_SynchronizeData
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FrMain());
}
}
}
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的常规信息通过以下
// 特性集控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Lskj_SynchronizeData")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Lskj_SynchronizeData")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 使此程序集中的类型
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
// 则将该类型上的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("b555f417-60fd-4408-ad38-78e83f255650")]
// 程序集的版本信息由下面四个值组成:
//
// 主版本
// 次版本
// 内部版本号
// 修订号
//
// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,63 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace Lskj_SynchronizeData.Properties {
using System;
/// <summary>
/// 一个强类型的资源类,用于查找本地化的字符串等。
/// </summary>
// 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// 返回此类使用的缓存的 ResourceManager 实例。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Lskj_SynchronizeData.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// 使用此强类型资源类,为所有资源查找
/// 重写当前线程的 CurrentUICulture 属性。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}
@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
@@ -0,0 +1,26 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace Lskj_SynchronizeData.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
}
}
@@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
@@ -0,0 +1,605 @@
/******************************
* 说明:数据库操作类
* 创建人:龚宇超
* 创建日期:2017-07-24
* 修改人:
* 修改日期:
* 修改备注:
* 版本:1.0.0.0
******************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace Lskj_SynchronizeData
{
/// <summary>
/// 数据库操作类
/// </summary>
public static class SqlHelper
{
/// <summary>
/// 数据连接
/// </summary>
public static SqlConnection _connection;
/// <summary>
/// 请求超时时间
/// </summary>
public static int CommandTimeout;
#region ExecuteAdapter
/// <summary>
/// <para>说明:获取适配器</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdType">Type of the command.</param>
/// <param name="cmdText">The command text.</param>
/// <param name="commandParameters">The command parameters.</param>
/// <returns>SqlDataAdapter.</returns>
public static SqlDataAdapter ExecuteAdapter(CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlDataAdapter adapter;
SqlCommand cmd = new SqlCommand();
try
{
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
adapter = new SqlDataAdapter(cmd);
}
catch
{
throw;
}
return adapter;
}
/// <summary>
/// <para>说明:获取适配器</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdType">Type of the command.</param>
/// <param name="cmdText">The command text.</param>
/// <returns>SqlDataAdapter.</returns>
public static SqlDataAdapter ExecuteAdapter(CommandType cmdType, string cmdText)
{
SqlDataAdapter adapter;
SqlCommand cmd = new SqlCommand();
try
{
PrepareCommand(cmd, _connection, null, cmdType, cmdText, null);
adapter = new SqlDataAdapter(cmd);
}
catch
{
throw;
}
return adapter;
}
#endregion
#region ExecuteDataTable
/// <summary>
/// <para>说明:执行sql返回DataTable</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdText">The command text.</param>
/// <returns>DataTable.</returns>
public static DataTable ExecuteDataTable(string cmdText)
{
return ExecuteDataSet(cmdText).Tables[0];
}
/// <summary>
/// <para>说明:执行sql返回DataTable</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdText">The command text.</param>
/// <returns>DataTable.</returns>
public static DataTable ExecuteDataTable(string cmdText, params SqlParameter[] commandParameters)
{
return ExecuteDataSet(CommandType.Text, cmdText, "temp", commandParameters).Tables[0];
}
/// <summary>
/// <para>说明:执行sql返回指定字段值</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-08-15 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="fieldName">Name of the field.</param>
/// <param name="cmdText">The command text.</param>
/// <returns>System.Object.</returns>
public static object ExecuteObject(string fieldName, string cmdText)
{
object result = null;
try
{
result = ExecuteDataSet(cmdText).Tables[0].Rows[0][fieldName];
}
catch (Exception)
{
}
return result;
}
/// <summary>
/// <para>说明:执行sql返回指定字段值</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-11-27 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="fieldName">Name of the field.</param>
/// <param name="cmdText">The command text.</param>
/// <param name="commandParameters">The command parameters.</param>
/// <returns>System.Object.</returns>
public static object ExecuteObject(string fieldName, string cmdText, params SqlParameter[] commandParameters)
{
object result = null;
try
{
result = ExecuteDataSet(CommandType.Text, cmdText, "temp", commandParameters).Tables[0].Rows[0][fieldName];
}
catch (Exception)
{
}
return result;
}
/// <summary>
/// <para>说明:执行sql返回指定字段值</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-08-15 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="fieldName">Name of the field.</param>
/// <param name="cmdText">The command text.</param>
/// <returns>System.Object.</returns>
public static string ExecuteString(string fieldName, string cmdText)
{
object obj = ExecuteObject(fieldName, cmdText);
return obj == null ? "" : obj.ToString();
}
/// <summary>
/// <para>说明:执行sql返回指定字段值</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-11-27 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="fieldName">Name of the field.</param>
/// <param name="cmdText">The command text.</param>
/// <param name="commandParameters">The command parameters.</param>
/// <returns>System.String.</returns>
public static string ExecuteString(string fieldName, string cmdText, params SqlParameter[] commandParameters)
{
object obj = ExecuteObject(fieldName, cmdText, commandParameters);
return obj == null ? "" : obj.ToString();
}
#endregion
#region ExecuteDataSet
/// <summary>
/// <para>说明:查询结果集</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdType">Type of the command.</param>
/// <param name="cmdText">The command text.</param>
/// <param name="tabName">Name of the tab.</param>
/// <param name="commandParameters">The command parameters.</param>
/// <returns>DataSet.</returns>
public static DataSet ExecuteDataSet(int cmdType, string cmdText, string tabName, params SqlParameter[] commandParameters)
{
CommandType _cmdType = CommandType.Text;
switch (cmdType)
{
case 4:
_cmdType = CommandType.StoredProcedure;
break;
case 512:
_cmdType = CommandType.TableDirect;
break;
}
return ExecuteDataSet(_cmdType, cmdText, tabName, commandParameters);
}
/// <summary>
/// <para>说明:查询结果集</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdType">语句类型存储过程或者sql语句</param>
/// <param name="cmdText">执行内容</param>
/// <param name="tabName">表名</param>
/// <param name="commandParameters">参数</param>
/// <returns>DataSet.</returns>
public static DataSet ExecuteDataSet(CommandType cmdType, string cmdText, string tabName, params SqlParameter[] commandParameters)
{
DataSet set2;
SqlCommand cmd = new SqlCommand();
try
{
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet dataSet = new DataSet();
adapter.Fill(dataSet, tabName);
//adapter.FillSchema(dataSet, SchemaType.Mapped, tabName);
set2 = dataSet;
}
catch (Exception e)
{
if (e.Message.StartsWith("在从服务器接收结果时发生传输级错误") ||
e.Message.StartsWith("在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误") ||
e.Message.StartsWith("在向服务器发送请求时发生传输级错误"))
{
throw new Exception("无法连接服务器,请检查网络连接.");
}
else
{
throw;
}
}
finally
{
cmd.Dispose();
}
return set2;
}
/// <summary>
/// <para>说明:查询结果集</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdType">语句类型存储过程或者sql语句</param>
/// <param name="cmdText">执行内容</param>
/// <param name="tabName">表名</param>
/// <returns>DataSet.</returns>
public static DataSet ExecuteDataSet(CommandType cmdType, string cmdText, string tabName)
{
return ExecuteDataSet(cmdType, cmdText, tabName, null);
}
/// <summary>
/// <para>说明:查询结果集</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdText">执行内容</param>
/// <returns>DataSet.</returns>
public static DataSet ExecuteDataSet(string cmdText)
{
return ExecuteDataSet(CommandType.Text, cmdText, "temp");
}
/// <summary>
/// <para>说明:查询结果集</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="procedureName">Name of the procedure.</param>
/// <param name="tabName">表名</param>
/// <param name="parameterNames">The parameter names.</param>
/// <param name="parameterValues">The parameter values.</param>
/// <returns>DataSet.</returns>
public static DataSet ExecuteDataSet(string procedureName, string tabName, string[] parameterNames, object[] parameterValues)
{
DataSet set2;
try
{
SqlCommand cmd = new SqlCommand(procedureName, _connection);
cmd.CommandType = CommandType.StoredProcedure;
if (parameterNames != null && parameterValues != null)
{
for (int i = 0; i < parameterNames.Length && i < parameterValues.Length; i++)
{
cmd.Parameters.AddWithValue(parameterNames[i], parameterValues[i]);
}
}
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet dataSet = new DataSet();
adapter.Fill(dataSet, tabName);
set2 = dataSet;
}
catch
{
throw;
}
return set2;
}
#endregion
#region ExecuteNonQuery
/// <summary>
/// <para>说明:执行sql语句或者存储过程</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdType">Type of the command.</param>
/// <param name="cmdText">The command text.</param>
/// <param name="commandParameters">The command parameters.</param>
/// <returns>System.Int32.</returns>
public static int ExecuteNonQuery(CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlCommand cmd = new SqlCommand();
int num = 0;
try
{
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
num = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
}
catch (Exception e)
{
if (e.Message.StartsWith("在从服务器接收结果时发生传输级错误") ||
e.Message.StartsWith("在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误") ||
e.Message.StartsWith("在向服务器发送请求时发生传输级错误"))
{
throw new Exception("无法连接服务器,请检查网络连接.");
}
else
{
throw;
}
}
finally
{
cmd.Dispose();
}
return num;
}
/// <summary>
/// <para>说明:执行sql语句或者存储过程</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdType">Type of the command.</param>
/// <param name="cmdText">The command text.</param>
/// <returns>System.Int32.</returns>
public static int ExecuteNonQuery(CommandType cmdType, string cmdText)
{
return ExecuteNonQuery(CommandType.Text, cmdText, null);
}
/// <summary>
/// <para>说明:执行sql语句或者存储过程</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdText">The command text.</param>
/// <returns>System.Int32.</returns>
public static int ExecuteNonQuery(string cmdText)
{
return ExecuteNonQuery(CommandType.Text, cmdText);
}
#endregion
#region ExecuteReader
/// <summary>
/// <para>说明:执行sql语句或者存储过程并返回结果集(只读、只进)</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdType">Type of the command.</param>
/// <param name="cmdText">The command text.</param>
/// <param name="commandParameters">The command parameters.</param>
/// <returns>SqlDataReader.</returns>
public static SqlDataReader ExecuteReader(CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlDataReader reader2;
SqlCommand cmd = new SqlCommand();
try
{
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
SqlDataReader reader = cmd.ExecuteReader();
cmd.Parameters.Clear();
reader2 = reader;
}
catch
{
throw;
}
return reader2;
}
#endregion
#region ExecuteScalar
/// <summary>
/// <para>说明:执行sql语句或者存储过程并返回结果集第一行第一列</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="Connectionection">The connectionection.</param>
/// <param name="cmdType">Type of the command.</param>
/// <param name="cmdText">The command text.</param>
/// <param name="commandParameters">The command parameters.</param>
/// <returns>System.Object.</returns>
public static object ExecuteScalar(SqlConnection Connectionection, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, Connectionection, null, cmdType, cmdText, commandParameters);
object obj2 = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return obj2;
}
/// <summary>
/// <para>说明:执行sql语句或者存储过程并返回结果集第一行第一列</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdType">Type of the command.</param>
/// <param name="cmdText">The command text.</param>
/// <param name="commandParameters">The command parameters.</param>
/// <returns>System.Object.</returns>
public static object ExecuteScalar(CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlCommand cmd = new SqlCommand();
{
PrepareCommand(cmd, _connection, null, cmdType, cmdText, commandParameters);
object obj2 = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return obj2;
}
}
/// <summary>
/// <para>说明:执行sql语句或者存储过程并返回结果集第一行第一列</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdType">Type of the command.</param>
/// <param name="cmdText">The command text.</param>
/// <returns>System.Object.</returns>
public static object ExecuteScalar(CommandType cmdType, string cmdText)
{
SqlCommand cmd = new SqlCommand();
{
PrepareCommand(cmd, _connection, null, cmdType, cmdText, null);
object obj2 = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return obj2;
}
}
/// <summary>
/// <para>说明:执行sql语句或者存储过程并返回结果集第一行第一列</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-08-21 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmdText">The command text.</param>
/// <returns>System.Object.</returns>
public static object ExecuteScalar(string cmdText)
{
SqlCommand cmd = new SqlCommand();
{
PrepareCommand(cmd, _connection, null, CommandType.Text, cmdText, null);
object obj2 = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return obj2;
}
}
#endregion
#region PrepareCommand
/// <summary>
/// <para>说明: sql参数处理</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-07-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="cmd">The command.</param>
/// <param name="Connection">The connection.</param>
/// <param name="trans">The trans.</param>
/// <param name="cmdType">Type of the command.</param>
/// <param name="cmdText">The command text.</param>
/// <param name="cmdParms">The command parms.</param>
private static void PrepareCommand(SqlCommand cmd, SqlConnection Connection, SqlTransaction trans, CommandType cmdType, string cmdText, SqlParameter[] cmdParms)
{
if (Connection.State != ConnectionState.Open)
{
Connection.Open();
}
cmd.Connection = Connection;
cmd.CommandTimeout = CommandTimeout;
cmd.CommandText = cmdText;
if (trans != null)
{
cmd.Transaction = trans;
}
cmd.CommandType = cmdType;
if (cmdParms != null)
{
foreach (SqlParameter parameter in cmdParms)
{
cmd.Parameters.Add(parameter);
}
}
}
#endregion
}
}
@@ -0,0 +1,3 @@
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>