基线 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
+229
View File
@@ -0,0 +1,229 @@
namespace SynchronousOven
{
partial class Form1
{
/// <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.label6 = new System.Windows.Forms.Label();
this.txtTimeInterval = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.txtName = new System.Windows.Forms.TextBox();
this.txtDataBase = new System.Windows.Forms.TextBox();
this.txtPassword = new System.Windows.Forms.TextBox();
this.txtSeverId = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.btnBegin = new System.Windows.Forms.Button();
this.txtLog = new System.Windows.Forms.TextBox();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.Controls.Add(this.label6);
this.panel1.Controls.Add(this.txtTimeInterval);
this.panel1.Controls.Add(this.label5);
this.panel1.Controls.Add(this.txtName);
this.panel1.Controls.Add(this.txtDataBase);
this.panel1.Controls.Add(this.txtPassword);
this.panel1.Controls.Add(this.txtSeverId);
this.panel1.Controls.Add(this.label4);
this.panel1.Controls.Add(this.label3);
this.panel1.Controls.Add(this.label2);
this.panel1.Controls.Add(this.label1);
this.panel1.Controls.Add(this.btnBegin);
this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Margin = new System.Windows.Forms.Padding(4);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(800, 90);
this.panel1.TabIndex = 2;
//
// label6
//
this.label6.Location = new System.Drawing.Point(687, 11);
this.label6.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(104, 29);
this.label6.TabIndex = 11;
this.label6.Text = "秒(最短30秒)";
this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// txtTimeInterval
//
this.txtTimeInterval.Location = new System.Drawing.Point(560, 11);
this.txtTimeInterval.Margin = new System.Windows.Forms.Padding(4);
this.txtTimeInterval.Name = "txtTimeInterval";
this.txtTimeInterval.Size = new System.Drawing.Size(117, 25);
this.txtTimeInterval.TabIndex = 10;
//
// label5
//
this.label5.Location = new System.Drawing.Point(448, 11);
this.label5.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(117, 29);
this.label5.TabIndex = 9;
this.label5.Text = "间隔时间设置";
this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// txtName
//
this.txtName.Location = new System.Drawing.Point(108, 50);
this.txtName.Margin = new System.Windows.Forms.Padding(4);
this.txtName.Name = "txtName";
this.txtName.Size = new System.Drawing.Size(129, 25);
this.txtName.TabIndex = 8;
//
// txtDataBase
//
this.txtDataBase.Location = new System.Drawing.Point(323, 11);
this.txtDataBase.Margin = new System.Windows.Forms.Padding(4);
this.txtDataBase.Name = "txtDataBase";
this.txtDataBase.Size = new System.Drawing.Size(116, 25);
this.txtDataBase.TabIndex = 7;
//
// txtPassword
//
this.txtPassword.Location = new System.Drawing.Point(323, 50);
this.txtPassword.Margin = new System.Windows.Forms.Padding(4);
this.txtPassword.Name = "txtPassword";
this.txtPassword.PasswordChar = '*';
this.txtPassword.Size = new System.Drawing.Size(116, 25);
this.txtPassword.TabIndex = 6;
//
// txtSeverId
//
this.txtSeverId.Location = new System.Drawing.Point(108, 11);
this.txtSeverId.Margin = new System.Windows.Forms.Padding(4);
this.txtSeverId.Name = "txtSeverId";
this.txtSeverId.Size = new System.Drawing.Size(129, 25);
this.txtSeverId.TabIndex = 5;
//
// label4
//
this.label4.Location = new System.Drawing.Point(232, 11);
this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(95, 29);
this.label4.TabIndex = 4;
this.label4.Text = "数据库";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label3
//
this.label3.Location = new System.Drawing.Point(16, 50);
this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(95, 29);
this.label3.TabIndex = 3;
this.label3.Text = "登录名称";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label2
//
this.label2.Location = new System.Drawing.Point(232, 50);
this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(95, 29);
this.label2.TabIndex = 2;
this.label2.Text = "登录密码";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 11);
this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(95, 29);
this.label1.TabIndex = 1;
this.label1.Text = "服务器地址";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// btnBegin
//
this.btnBegin.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnBegin.Location = new System.Drawing.Point(679, 48);
this.btnBegin.Margin = new System.Windows.Forms.Padding(4);
this.btnBegin.Name = "btnBegin";
this.btnBegin.Size = new System.Drawing.Size(105, 29);
this.btnBegin.TabIndex = 0;
this.btnBegin.Text = "开始同步";
this.btnBegin.UseVisualStyleBackColor = true;
this.btnBegin.Click += new System.EventHandler(this.btnBegin_Click);
//
// txtLog
//
this.txtLog.Dock = System.Windows.Forms.DockStyle.Fill;
this.txtLog.Location = new System.Drawing.Point(0, 90);
this.txtLog.Margin = new System.Windows.Forms.Padding(4);
this.txtLog.Multiline = true;
this.txtLog.Name = "txtLog";
this.txtLog.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtLog.Size = new System.Drawing.Size(800, 360);
this.txtLog.TabIndex = 4;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.txtLog);
this.Controls.Add(this.panel1);
this.Name = "Form1";
this.Text = "同步工具";
this.Load += new System.EventHandler(this.Form1_Load);
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.TextBox txtTimeInterval;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox txtName;
private System.Windows.Forms.TextBox txtDataBase;
private System.Windows.Forms.TextBox txtPassword;
private System.Windows.Forms.TextBox txtSeverId;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button btnBegin;
private System.Windows.Forms.TextBox txtLog;
}
}
+919
View File
@@ -0,0 +1,919 @@
using Lskj.Control;
using Lskj.Core;
using Lskj.Data;
//using Lskj.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using static SynchronousOven.NewEmp;
namespace SynchronousOven
{
public partial class Form1 : Form
{
/// <summary>
/// ini文件内段落名
/// </summary>
public bool RunAutomatically = false;
/// <summary>
/// ini文件内段落名
/// </summary>
public string company = "烤箱同步工具";
/// <summary>
/// 初始时间间隔
/// </summary>
int second = 30;
/// <summary>
/// IP,端口,请求路径
/// </summary>
public string IP = "110.185.210.70";
public string port = "8881";
public System.Threading.Thread thread = null;
public System.Timers.Timer timer1 = new System.Timers.Timer();
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 初始化
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_Load(object sender, EventArgs e)
{
txtSeverId.Text = Lskj.Util.IniHelper.Read("Setting.ini", company, "serverName");
txtDataBase.Text = Lskj.Util.IniHelper.Read("Setting.ini", company, "dbName");
txtName.Text = Lskj.Util.IniHelper.Read("Setting.ini", company, "user");
txtPassword.Text = Lskj.Util.IniHelper.Read("Setting.ini", company, "password");
txtTimeInterval.Text = Lskj.Util.IniHelper.Read("Setting.ini", company, "interval");
//txtSeverId.Text = IniUtil.IniReadValue(company, "serverName");
//txtDataBase.Text = IniUtil.IniReadValue(company, "dbName");
//txtName.Text = IniUtil.IniReadValue(company, "user");
//txtPassword.Text = IniUtil.IniReadValue(company, "password");
//txtTimeInterval.Text = IniUtil.IniReadValue(company, "interval");
if (string.IsNullOrEmpty(txtTimeInterval.Text)) txtTimeInterval.Text = "30";
txtTimeInterval.LostFocus += new EventHandler(txtTimeInterval_LostFocus);
this.FormClosed += new FormClosedEventHandler(Form1_FormClosed);
this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(timer1_Tick);
//数据都有的话就自动启动
if (!string.IsNullOrWhiteSpace(txtSeverId.Text) && !string.IsNullOrWhiteSpace(txtDataBase.Text) && !string.IsNullOrWhiteSpace(txtName.Text) && !string.IsNullOrWhiteSpace(txtPassword.Text) && !string.IsNullOrWhiteSpace(txtTimeInterval.Text))
{
RunAutomatically = Lskj.Util.IniHelper.Read("Setting.ini", company, "RunAutomatically").Equals("1");
if (RunAutomatically)
{
this.btnBegin_Click(null, null);
}
}
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
if (thread != null)
{
thread.Abort();
}
this.Dispose();
this.Close();
}
/// <summary>
/// 时间间隔TextBox失去焦点事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtTimeInterval_LostFocus(object sender, EventArgs e)
{
string checkStr = txtTimeInterval.Text.ToString();
if (string.IsNullOrEmpty(checkStr)) txtTimeInterval.Text = "30";
int check = Convert.ToInt32(txtTimeInterval.Text.ToString());
if (check < 30)
{
txtTimeInterval.Text = "30";
}
second = Convert.ToInt32(txtTimeInterval.Text.ToString());
IniUtil.IniWriteValue(company, "interval", txtTimeInterval.Text.ToString());
}
//开始同步
private void btnBegin_Click(object sender, EventArgs e)
{
if (thread == null)
{
thread = new System.Threading.Thread(StartMethod);
thread.Start();
}
}
//同步事件
private void StartMethod()
{
try
{
if (ConnectServer())
{
//判断数据库是否有该配置列
DataTable DT = SqlHelper.ExecuteDataTable("select name from syscolumns where id=object_id('mrp_WorkTaskListTab') and name='SyncFlag'");
bool flag = DT.Rows.Count > 0;
if (!flag)
{
MessageBox.Show("同步失败,原因:数据库内无同步标识列!");
return;
}
timer1.Interval = second * 1000;
RefreshLogUIThread("开始同步");
SynchronizeWorkOrder();
SynchronizeStatus();
SynchronousMachiningParameter();
SynchronizePersonnelInformation();
RefreshLogUIThread("同步完成");
timer1.Enabled = true;
this.timer1.Start();
}
else
{
thread = null;
}
}
catch (Exception ex)
{
RefreshLogUIThread(DateTime.Now + string.Format("失败.原因:{0}.\r\n", ex.Message));
}
}
//private void RefreshTemperature()
//{
// Thread thread = new Thread(DatabaseMonitoring);
// thread.IsBackground = true;
// thread.Start();
//}
///// <summary>
///// timer2事件
///// </summary>
///// <param name="sender"></param>
///// <param name="e"></param>
//private void timer2_Tick(object sender, EventArgs e)
//{
// RefreshTemperature();
//}
/// <summary>
/// timer事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Enabled = false;
ReClearLogUIThread();//清除内容
SynchronizeWorkOrder();
SynchronizeStatus();
SynchronousMachiningParameter();
SynchronizePersonnelInformation();
timer1.Enabled = true;
}
/// <summary>
///温度同步
/// </summary>
//public void DatabaseMonitoring()
//{
// string sqlValue = "select * from p_sbhottab";
// DataTable dt = SqlHelper.ExecuteDataTable(sqlValue);
// string url = "http://110.185.210.70:8881/business/receive/findEquipmentSetData?jtBillNo=";
// foreach (DataRow row in dt.Rows)
// {
// if (string.IsNullOrEmpty(row["sbhot"].ToString()) || row["sbhot"].ToString().Equals("0.00"))
// {
// url = "http://110.185.210.70:8881/business/receive/findEquipmentSetData?jtBillNo=";
// url += row["sbno"];
// ResponseMode mode = NewEmp.GetUrl(url);
// if (mode!=null&&0 == mode.ret)
// {
// string temp = mode.data.temp;
// sqlValue = string.Format("update p_sbhottab set sbhot='{0}' where sbno='{1}'", temp, row["sbno"].ToString());
// SqlHelper.ExecuteNonQuery(sqlValue);
// }
// else
// {
// string errorMsg = mode != null ? mode.msg : "未知原因.";
// RefreshLogUIThread(DateTime.Now + string.Format(" 维修状态,信息读取失败,错误原因:{0}.\r\n", errorMsg));
// }
// }
// }
//}
/// <summary>
/// 同步事件 人员账号信息
/// </summary>
private void SynchronizePersonnelInformation()
{
//现在用户信息表里的信息
string sqlValue = "select isnull(LoginAccount,'') as LoginAccount,isnull(Password,'') as Password,isnull(p_emp_status,'') as p_emp_status,isnull(EmployeeName,'') as EmployeeName,isnull(p_emp_linkphone,'') as p_emp_linkphone,isnull(p_emp_email,'') as p_emp_email from P_EmployeeTab";
DataTable dt = SqlHelper.ExecuteDataTable(sqlValue);
sqlValue = "select isnull(LoginAccount,'') as LoginAccount,isnull(UseFlag,0) as UseFlag from P_EmployeeTab";
DataTable useFlagTab = SqlHelper.ExecuteDataTable(sqlValue);
//人员信息对照表
sqlValue = "select * from P_EmployeeTab_temp";
DataTable lastimportDt = SqlHelper.ExecuteDataTable(sqlValue);
//有差别的数据 差集
DataTable changeContent = dt.Clone();
IEnumerable<DataRow> QCJ = dt.Select().AsEnumerable().Except(lastimportDt.Select().AsEnumerable(), DataRowComparer.Default);
try
{
DataTable jg = QCJ.CopyToDataTable();
changeContent = jg;
//sqlValue = "select LoginAccount,Password,p_emp_status,EmployeeName,p_emp_linkphone,p_emp_email from P_EmployeeTab where LoginAccount='09998'";
//changeContent = SqlHelper.ExecuteDataTable(sqlValue);
}
catch (System.InvalidOperationException ex) //如果差集为null,就回进当前报错
{
changeContent = dt.Clone();
}
finally
{
//更改表格列名
changeContent.Columns["LoginAccount"].ColumnName = "userName";
changeContent.Columns["Password"].ColumnName = "password";
changeContent.Columns["p_emp_status"].ColumnName = "status";
changeContent.Columns["EmployeeName"].ColumnName = "trueName";
changeContent.Columns["p_emp_linkphone"].ColumnName = "phone";
changeContent.Columns["p_emp_email"].ColumnName = "email";
}
string tokenName = "09998";
string token = GetToken();
try
{
foreach (DataRow item in changeContent.Rows)
{
string statusStr = item["status"] + "";
//判断更改状态
string loginAccount = item["userName"] + "";
DataTable selectTab = SqlHelper.ExecuteDataTable(string.Format("select * from P_EmployeeTab_temp where LoginAccount='{0}'", loginAccount));
if (selectTab.Rows.Count == 0)
{
item["status"] = "1";
}
else
{
string useFlag = useFlagTab.Select(string.Format("LoginAccount='{0}'", loginAccount))[0]["UseFlag"] + "";
DataRow selectRow = selectTab.Rows[0];
if ((item["status"] + "").Equals("离职") || useFlag.Equals("0") || useFlag.Equals(""))
{
item["status"] = "3";
}
else
{
item["status"] = "2";
}
}
if (!string.IsNullOrWhiteSpace(token))
{
string jsonObj = JsonUtil.ToJsonObject(item);
newResponseMode newmode = ExecutePost(tokenName, token, jsonObj);
//修改对比表数据
sqlValue = string.Format(@"if(select 1 from P_EmployeeTab_temp where LoginAccount='{0}')=1
begin
update P_EmployeeTab_temp set Password = '{1}', p_emp_status = '{2}',EmployeeName='{3}',p_emp_linkphone='{4}',p_emp_email='{5}' where LoginAccount='{0}';
end else
begin
insert into P_EmployeeTab_temp(LoginAccount,Password,p_emp_status,EmployeeName,p_emp_linkphone,p_emp_email) values('{0}', '{1}', '{2}','{3}','{4}','{5}')
end
", item["userName"], item["password"], statusStr, item["trueName"], item["phone"], item["email"]);
SqlHelper.ExecuteNonQuery(sqlValue);
}
}
}
catch (Exception ex)
{
RefreshLogUIThread(DateTime.Now + string.Format(" 人员账号信息,信息读取失败.\r\n" + " 原因:" + ex.Message + Environment.NewLine));
}
RefreshLogUIThread(DateTime.Now + "人员账号信息 同步完成.\r\n");
RefreshLogUIThread("--------------------分割线------------------------\r\n");
}
private newResponseMode ExecutePost(string tokenName, string token, string jsonStr, int num = 0)
{
string url = "http://110.185.210.70:8881/auth/sys/users/thirdPlatformData?userDb=ditoo&username={0}&token={1}";
url = string.Format(url, tokenName, token);
string jsonObj = jsonStr;
string newDeljson = jsonObj.Substring(1, jsonObj.Length - 2);
newResponseMode newmode = NewEmp.newPostMethodToObj(url, newDeljson);
if (newmode.msg.Equals("token验证失败,请重新登录!"))
{
if (num < 10)
{
num += 1;
token = GetToken();
newmode = ExecutePost(tokenName, token, jsonStr, num);
}
else
{
return newmode;
}
}
return newmode;
}
private string GetToken()
{
string token = string.Empty;
string tokenUrl = "http://110.185.210.70:8881/auth/sys/users/thirdPlatformData/login?userDb=ditoo";//获得令牌
string tokenSqlStr = "select isnull(LoginAccount,'') as LoginAccount,isnull(Password,'') as Password,isnull(p_emp_status,'') as p_emp_status,isnull(EmployeeName,'') as EmployeeName,isnull(p_emp_linkphone,'') as p_emp_linkphone,isnull(p_emp_email,'') as p_emp_email from P_EmployeeTab where LoginAccount='09998'";
DataTable tokenTab = SqlHelper.ExecuteDataTable(tokenSqlStr);
DataRow tokenRow = null;
if (tokenTab.Rows.Count > 0)
{
tokenRow = tokenTab.Rows[0];
}
if (tokenRow != null)
{
string tokenName = tokenRow["LoginAccount"] + "";
string tokenPassWord = tokenRow["Password"] + "";
string tokenJson = string.Format("\"userName\":\"{0}\",\"password\":\"{1}\"", tokenName, tokenPassWord);//sbs@4433 item["password"] + ""
tokenJson = "{" + tokenJson + "}";
newResponseMode mode = NewEmp.newPostMethodToObj(tokenUrl, tokenJson);
if (mode.data != null)
{
token = mode.data.token;
}
}
return token;
}
/// <summary>
/// 同步事件 维修状态
/// </summary>
private void SynchronizeStatus()
{
//当前最新的维修状态信息
string sqlValue = @"
select sbnumber as 'jtBillNo',isrepair,COALESCE((
select top 1 Ema_wx_wxman
from EMA_WxMaintab a left
join p_departmenttab b on a.Ema_wx_departmentid = b.Departmentid
where 1 = 1
and isnull(Ema_wx_Affirmer, 0) <> 0
and ISNULL(Ema_wx_stepcode, '') > 100 and Ema_wx_sbnumber = sbnumber order by Ema_wx_operatedate desc
) ,'')as 'ema_wx_wxman',
COALESCE((
select top 1 case when Ema_wx_receiveflag=1 then '维修中'
when Ema_wx_receiveflag=2 then '完工'
when Ema_wx_receiveflag=3 then '暂停'
else '未开工' end
from EMA_WxMaintab a left
join p_departmenttab b on a.Ema_wx_departmentid = b.Departmentid
where 1 = 1
and isnull(Ema_wx_Affirmer, 0) <> 0
and ISNULL(Ema_wx_stepcode, '') > 100 and Ema_wx_sbnumber = sbnumber order by Ema_wx_operatedate desc
) ,'')as 'stateOfRepair'
from(select a.*
,case when sbnumber in (select Ema_wx_sbnumber from EMA_WxMaintab where Ema_wx_receiveflag = 1) then '是'
else '' end as isrepair
,case when sbnumber in (select ema_sbnumber from EMA_stopTab where ema_type = '停用' ) then '停用'
when sbnumber in (select ema_pst_number from EMA_ScrapTab ) then '报废'
when sbnumber in (select Ema_wx_sbnumber from EMA_WxMaintab where isnull(Ema_wx_receiveflag,0) = 0) then '待修'
else '启用' end as Usage
from Wms_toolsTab a where 1 = 1
) a where 1 = 1 ";
//2022-1-20 zj让把Ema_wx_receiveflag 改为isnull(Ema_wx_receiveflag,0) 改前是按照设备档案sql查询
DataTable dt = SqlHelper.ExecuteDataTable(sqlValue);
//上一次同步时的维修信息
sqlValue = "select * from lastimport_repair";
DataTable lastimportDt = SqlHelper.ExecuteDataTable(sqlValue);
//有差别的数据 差集
DataTable changeContent = dt.Clone();
IEnumerable<DataRow> QCJ = dt.Select().AsEnumerable().Except(lastimportDt.Select().AsEnumerable(), DataRowComparer.Default);
try
{
DataTable jg = QCJ.CopyToDataTable();
changeContent = jg;
}
catch (System.InvalidOperationException ex) //如果差集为null,就回进当前报错
{
changeContent = dt.Clone();
}
string url = "http://110.185.210.70:8881/business/receive/maintainRecord";
try
{
foreach (DataRow item in changeContent.Rows)
{
string ema_wx_wxman = item["ema_wx_wxman"].ToString();
string name = (ema_wx_wxman.Split(','))[0];//维修人只传第一个
item["ema_wx_wxman"] = name;
string jtBillNo = item["jtBillNo"].ToString();
string newjtBillNo = jtBillNo.Trim();
item["jtBillNo"] = newjtBillNo;
string jsonObj = JsonUtil.ToJsonObject(item);
string deljson = jsonObj.Substring(1, jsonObj.Length - 2);
ResponseMode mode = NewEmp.PostMethodToObj(url, deljson);
item["ema_wx_wxman"] = ema_wx_wxman;
item["jtBillNo"] = jtBillNo;
if (mode != null && 0 == mode.ret)
{
//修改上一次查询表的数据,根据是否存在编号去修改或新增
sqlValue = string.Format(@"if(select 1 from lastimport_repair where jtBillNo='{0}')=1
begin
update lastimport_repair set isrepair = '{1}', ema_wx_wxman = '{2}',stateOfRepair='{3}' where jtBillNo='{0}';
end else
begin
insert into lastimport_repair(jtBillNo, isrepair, ema_wx_wxman,stateOfRepair) values('{0}', '{1}', '{2}','{3}')
end",
item["jtBillNo"], item["isrepair"], item["ema_wx_wxman"], item["stateOfRepair"]);
SqlHelper.ExecuteNonQuery(sqlValue);
string updareabak = DateTime.Now + string.Format(" 维修状态{0} 信息同步成功.\r\n", item["jtBillNo"]);
RefreshLogUIThread(updareabak);
}
else
{
string errorMsg = mode != null ? mode.msg : "未知原因.";
RefreshLogUIThread(DateTime.Now + string.Format(" 维修状态,信息读取失败,错误原因:{0}.\r\n", errorMsg));
}
}
}
catch (Exception ex)
{
RefreshLogUIThread(DateTime.Now + string.Format(" 维修状态,信息读取失败.\r\n" + " 原因:" + ex.Message + Environment.NewLine));
}
RefreshLogUIThread(DateTime.Now + "维修状态 同步完成.\r\n");
RefreshLogUIThread("--------------------分割线------------------------\r\n");
}
/// <summary>
/// 同步事件 加工参数
/// </summary>
private void SynchronousMachiningParameter()
{
//当前最新的加工参数数据
string sqlValue = @"select wms_ep_ProductId,wms_ep_mojuid,isnull(wms_ep_bzlhwd,0)as wms_ep_bzlhwd ,isnull(wms_ep_lhwdgc,0)as wms_ep_lhwdgc,
isnull(wms_ep_lhtime,0)as wms_ep_lhtime,isnull(wms_ep_sjgc,0)as wms_ep_sjgc,isnull(wms_ep_lhyl,0)as wms_ep_lhyl,
isnull(wms_ep_ylgc,0)as wms_ep_ylgc,isnull(wms_ep_bzedwd,0)as wms_ep_bzedwd,isnull(wms_ep_edwdgc,0)as wms_ep_edwdgc,
isnull(wms_ep_bzedtime,0)as wms_ep_bzedtime,isnull(wms_ep_edsjgc,0)as wms_ep_edsjgc,isnull(wms_ep_bzedwd2,0)as wms_ep_bzedwd2,
isnull(wms_ep_edwdgc2,0)as wms_ep_edwdgc2,isnull(wms_ep_bzedtime2,0)as wms_ep_bzedtime2,isnull(wms_ep_edsjgc2,0)as wms_ep_edsjgc2,
isnull(wms_ep_bzedwd3,0)as wms_ep_bzedwd3,isnull(wms_ep_edwdgc3,0)as wms_ep_edwdgc3,isnull(wms_ep_bzedtime3,0)as wms_ep_bzedtime3,
isnull(wms_ep_edsjgc3,0)as wms_ep_edsjgc3,isnull(wms_ep_bzedwd4,0)as wms_ep_bzedwd4,isnull(wms_ep_edwdgc4,0)as wms_ep_edwdgc4,
isnull(wms_ep_bzedtime4,0)as wms_ep_bzedtime4,isnull(wms_ep_edsjgc4,0)as wms_ep_edsjgc4,isnull(wms_ep_jfdy,0)as wms_ep_jfdy,
isnull(wms_ep_nyz,0)as wms_ep_nyz,isnull(wms_ep_nytime,0)as wms_ep_nytime,isnull(wms_ep_yl1,0)as wms_ep_yl1,isnull(wms_ep_yl2,0)as wms_ep_yl2,
isnull(wms_ep_yl3,0)as wms_ep_yl3,isnull(wms_ep_yl4,0)as wms_ep_yl4,isnull(wms_ep_yl5,0)as wms_ep_yl5,isnull(wms_ep_yl6,0)as wms_ep_yl6,
isnull(wms_ep_yl7,0)as wms_ep_yl7,isnull(wms_ep_yl8,0)as wms_ep_yl8,isnull(wms_ep_yl9,0)as wms_ep_yl9,isnull(wms_ep_yl10,0)as wms_ep_yl10
from wms_Equipmentparameterstab";
DataTable dt = SqlHelper.ExecuteDataTable(sqlValue);
// 上一次同步时物料加工标准参数
sqlValue = @"select wms_ep_ProductId,wms_ep_mojuid,wms_ep_bzlhwd,wms_ep_lhwdgc,wms_ep_lhtime,wms_ep_sjgc,wms_ep_lhyl,wms_ep_ylgc,
wms_ep_bzedwd,wms_ep_edwdgc,wms_ep_bzedtime,wms_ep_edsjgc,wms_ep_bzedwd2,wms_ep_edwdgc2,wms_ep_bzedtime2,wms_ep_edsjgc2,
wms_ep_bzedwd3,wms_ep_edwdgc3,wms_ep_bzedtime3,wms_ep_edsjgc3,wms_ep_bzedwd4,wms_ep_edwdgc4,wms_ep_bzedtime4,wms_ep_edsjgc4,
wms_ep_jfdy,wms_ep_nyz,wms_ep_nytime,wms_ep_yl1,wms_ep_yl2,wms_ep_yl3,wms_ep_yl4,wms_ep_yl5,wms_ep_yl6,wms_ep_yl7,wms_ep_yl8,
wms_ep_yl9,wms_ep_yl10
from lastimport_machining";
DataTable LastTimeDt = SqlHelper.ExecuteDataTable(sqlValue);
//需要同步的数据
DataTable changeContent = dt.Clone();
//差集
IEnumerable<DataRow> QCJ = dt.Select().AsEnumerable().Except(LastTimeDt.Select().AsEnumerable(), DataRowComparer.Default);
string url = "http://110.185.210.70:8881/business/receive/productionStandard";
try
{
DataTable jg = QCJ.CopyToDataTable();
changeContent = jg;
}
catch (System.InvalidOperationException ex) //如果差集为null,就回进当前报错
{
changeContent = dt.Clone();
}
try
{
foreach (DataRow item in changeContent.Rows)
{
string updateSql = "update {0} set {1} where {2}='{3}';";
string insertSql = "insert into {0}({1}) values({2});";
string updateFields = string.Empty;
string insertFields = string.Empty;
string insertValues = string.Empty;
string jsonObj = JsonUtil.ToJsonObject(item);
string deljson = jsonObj.Substring(1, jsonObj.Length - 2);
ResponseMode mode = NewEmp.PostMethodToObj(url, deljson);
if (mode != null && 0 == mode.ret)
{
//判断对照表中是否存在相同编码
DataRow[] dr = LastTimeDt.Select("wms_ep_ProductId" + "='" + item["wms_ep_ProductId"] + "'");
bool isupdate = dr.Length == 1 ? true : false;
//同步数据到对照表中
foreach (DataColumn column in changeContent.Columns)
{
if (isupdate)
{
//修改语句
if (!column.ColumnName.Equals("wms_ep_ProductId"))
{
if (column.DataType == typeof(Decimal) || column.DataType == typeof(Int32))
{
updateFields += string.Format("[{0}]='{1}',", column.ColumnName, 0);
}
else
{
updateFields += string.Format("[{0}]='{1}',", column.ColumnName, (item[column.ColumnName] + "").Replace("'", "''"));
}
}
}
else
{
//新增语句
string fieldValue = string.Empty;
fieldValue = (item[column.ColumnName] + "").Replace("'", "''");
insertFields += "[" + column.ColumnName + "],";
if (!string.IsNullOrWhiteSpace(fieldValue))
{
insertValues += column.DataType == typeof(DateTime) ? "'" + Convert.ToDateTime(fieldValue).ToString("yyyy-MM-dd HH:mm:ss") + "'," : "'" + fieldValue + "',";
}
else
{
if (column.DataType == typeof(Decimal) || column.DataType == typeof(Int32))
insertValues += "0,";
else if (column.DataType == typeof(DateTime))
insertValues += "NULL,";
else
insertValues += "'',";
}
}
}
updateFields = updateFields.TrimEnd(',');
insertFields = insertFields.TrimEnd(',');
insertValues = insertValues.TrimEnd(',');
if (!string.IsNullOrEmpty(updateFields))
{
sqlValue = string.Format(updateSql, "lastimport_machining", updateFields, "wms_ep_ProductId", item["wms_ep_ProductId"]);
}
if (!string.IsNullOrEmpty(insertFields))
{
sqlValue = string.Format(insertSql, "lastimport_machining", insertFields, insertValues);
}
SqlHelper.ExecuteNonQuery(sqlValue);
string updareabak = DateTime.Now + string.Format(" 加工参数{0} 信息同步成功.\r\n", item["wms_ep_ProductId"]);
RefreshLogUIThread(updareabak);
}
else
{
string errorMsg = mode != null ? mode.msg : "未知原因.";
RefreshLogUIThread(DateTime.Now + string.Format(" 加工参数 信息读取失败,错误原因:{0}.\r\n", errorMsg));
}
}
}
catch (Exception ex)
{
RefreshLogUIThread(DateTime.Now + string.Format("加工参数 信息读取失败.\r\n" + " 原因:" + ex.Message + Environment.NewLine));
}
RefreshLogUIThread(DateTime.Now + "加工参数 同步完成.\r\n");
RefreshLogUIThread("--------------------分割线------------------------\r\n");
}
/// <summary>
/// 同步事件 工单明细信息
/// </summary>
private void SynchronizeWorkOrder()
{
// string sqlValue = @"select mrp_lwt_id,mrp_lwt_workno ,mrp_lwt_workordername ,stdt,
//(select (CASE mrp_lwt_workordername WHEN '硫化' THEN (select mrp_lwt_beforeAmount) ELSE( select (mrp_lwt_kxamount1+mrp_lwt_kxamount2 +mrp_lwt_kxamount3) as 'mrp_lwt_kxamount' from mrp_WorkTaskListTab where mrp_lwt_workno = a.mrp_lwt_workno and mrp_lwt_workordername=a.mrp_lwt_workordername and mrp_lwt_ProductId=a.mrp_lwt_ProductId and mrp_lwt_id=a.mrp_lwt_id )END )) as'mrp_lwt_beforeAmount',
//--mrp_lwt_beforeAmount,
// enddt,mrp_lwt_AfterAmount,mrp_lwt_badamount,
// (select EmployeeName from p_employeetab where employeeid = mrp_lwt_publishOper) as mrp_lwt_publishOper,
// mrp_lwt_ProductId,
// (select mrp_mwt_appellation from mrp_worktaskmaintab where mrp_mwt_workno = mrp_lwt_workno)as 'mrp_mwt_appellation',
//(select (CASE mrp_lwt_workordername WHEN '硫化' THEN (select jtBillNo from Mps_MachineSetTab where id =(select mrp_mwt_machine from mrp_worktaskmaintab where mrp_mwt_workno = a.mrp_lwt_workno)) ELSE( select mrp_lwt_kaoxiang1 from mrp_WorkTaskListTab where mrp_lwt_workno = a.mrp_lwt_workno and mrp_lwt_workordername=a.mrp_lwt_workordername and mrp_lwt_ProductId=a.mrp_lwt_ProductId and mrp_lwt_id=a.mrp_lwt_id )END )) as'jtBillNo',
//(select (CASE mrp_lwt_workordername WHEN '硫化' THEN (select jtname from Mps_MachineSetTab where id =(select mrp_mwt_machine from mrp_worktaskmaintab where mrp_mwt_workno = a.mrp_lwt_workno)) ELSE( select jtname from Mps_MachineSetTab where jtBillNo =(select mrp_lwt_kaoxiang1 from mrp_WorkTaskListTab where mrp_lwt_workno = a.mrp_lwt_workno and mrp_lwt_workordername=a.mrp_lwt_workordername and mrp_lwt_ProductId=a.mrp_lwt_ProductId and mrp_lwt_id=a.mrp_lwt_id ))END )) as'jtname',
// --(select jtBillNo from Mps_MachineSetTab where id =(select CASE mrp_lwt_workordername WHEN '硫化' THEN mrp_mwt_machine ELSE mrp_mwt_str3 END from mrp_worktaskmaintab where mrp_mwt_workno = mrp_lwt_workno)) as 'jtBillNo',
// --(select jtname from Mps_MachineSetTab where id =(select CASE mrp_lwt_workordername WHEN '硫化' THEN mrp_mwt_machine ELSE mrp_mwt_str3 END from mrp_worktaskmaintab where mrp_mwt_workno = mrp_lwt_workno)) as 'jtname',
//SyncFlag,
// (select mrp_mwt_comid from mrp_worktaskmaintab where mrp_mwt_workno = mrp_lwt_workno)as 'comid',
// (select mrp_mwt_finish from mrp_worktaskmaintab where mrp_mwt_workno = mrp_lwt_workno)as 'finish'
// from(
// select
// *, DATEDIFF(minute, a.mrp_lwt_starttime, a.mrp_lwt_endtime) / 60 as betweenTime
// ,case when isnull(mrp_lwt_glgx, '') = '' then b.mes_list_glgx else mrp_lwt_glgx end as glgx
// from mrp_WorkTaskListTab a with(nolock)
// left join(
// select mes_list_no, mes_List_Name , mes_list_glgx from mes_fl_list with(nolock)
// where isnull(sign,0)= 0
// ) b on b.mes_list_no = a.mrp_lwt_prolistno
// left join(
// select a.workno, a.taskid, MIN(optime) stdt, max(opendtime) enddt
// from mrp_worktaskoptimetab a
// group by a.workno, a.taskid
// ) aa on a.mrp_lwt_workno = aa.workno and a.mrp_lwt_id = aa.taskid
// where 1 = 1
// ) a where 1 = 1 and (mrp_lwt_workordername = '硫化' or mrp_lwt_workordername = '二段硫化') and ISNULL(SyncFlag,0)<>1 ";
//and stdt > '2021-11-19' and mrp_lwt_workno='CCP202201170056' and ISNULL(SyncFlag,0)<>1
string sqlValue = @"select mrp_lwt_id,mrp_lwt_workno ,mrp_lwt_workordername ,stdt,
(select (CASE mrp_lwt_workordername WHEN '硫化' THEN (select mrp_lwt_beforeAmount) ELSE( select (mrp_lwt_kxamount1+mrp_lwt_kxamount2 +mrp_lwt_kxamount3) as 'mrp_lwt_kxamount' from mrp_WorkTaskListTab where mrp_lwt_workno = a.mrp_lwt_workno and mrp_lwt_workordername=a.mrp_lwt_workordername and mrp_lwt_ProductId=a.mrp_lwt_ProductId and mrp_lwt_id=a.mrp_lwt_id )END )) as'mrp_lwt_beforeAmount',
enddt,mrp_lwt_AfterAmount,mrp_lwt_badamount,
(select EmployeeName from p_employeetab where employeeid = mrp_lwt_publishOper) as mrp_lwt_publishOper,
mrp_lwt_ProductId,
(select mrp_mwt_appellation from mrp_worktaskmaintab where mrp_mwt_workno = mrp_lwt_workno)as 'mrp_mwt_appellation',
(select (CASE mrp_lwt_workordername WHEN '硫化' THEN (select jtBillNo from Mps_MachineSetTab where id =(select mrp_mwt_machine from mrp_worktaskmaintab where mrp_mwt_workno = a.mrp_lwt_workno)) ELSE( select mrp_lwt_kaoxiang1 from mrp_WorkTaskListTab where mrp_lwt_workno = a.mrp_lwt_workno and mrp_lwt_workordername=a.mrp_lwt_workordername and mrp_lwt_ProductId=a.mrp_lwt_ProductId and mrp_lwt_id=a.mrp_lwt_id )END )) as'jtBillNo',
(select (CASE mrp_lwt_workordername WHEN '硫化' THEN (select jtname from Mps_MachineSetTab where id =(select mrp_mwt_machine from mrp_worktaskmaintab where mrp_mwt_workno = a.mrp_lwt_workno)) ELSE( select jtname from Mps_MachineSetTab where jtBillNo =(select mrp_lwt_kaoxiang1 from mrp_WorkTaskListTab where mrp_lwt_workno = a.mrp_lwt_workno and mrp_lwt_workordername=a.mrp_lwt_workordername and mrp_lwt_ProductId=a.mrp_lwt_ProductId and mrp_lwt_id=a.mrp_lwt_id ))END )) as'jtname',
SyncFlag,
(select mrp_mwt_comid from mrp_worktaskmaintab where mrp_mwt_workno = mrp_lwt_workno)as 'comid',
(select mrp_mwt_finish from mrp_worktaskmaintab where mrp_mwt_workno = mrp_lwt_workno)as 'finish'
--,mrp_mwt_Start
from(
select
*, DATEDIFF(minute, a.mrp_lwt_starttime, a.mrp_lwt_endtime) / 60 as betweenTime
,case when isnull(mrp_lwt_glgx, '') = '' then b.mes_list_glgx else mrp_lwt_glgx end as glgx
from mrp_WorkTaskListTab a with(nolock)
left join ( select mrp_mwt_Start,mrp_mwt_workno from mrp_worktaskmaintab ) ttt on ttt.mrp_mwt_workno=a.mrp_lwt_workno
left join(
select mes_list_no, mes_List_Name , mes_list_glgx from mes_fl_list with(nolock)
where isnull(sign,0)= 0
) b on b.mes_list_no = a.mrp_lwt_prolistno
left join(
select a.workno, a.taskid, MIN(optime) stdt, max(opendtime) enddt
from mrp_worktaskoptimetab a
group by a.workno, a.taskid
) aa on a.mrp_lwt_workno = aa.workno and a.mrp_lwt_id = aa.taskid
where 1 = 1 and mrp_mwt_Start=1
) a where 1 = 1 and (mrp_lwt_workordername = '硫化' or mrp_lwt_workordername = '二段硫化') and ISNULL(SyncFlag,0)<>1";
try
{
DataTable dt = SqlHelper.ExecuteDataTable(sqlValue);
dt.Columns.Remove("SyncFlag");
string url = "http://110.185.210.70:8881/business/receive/followWorkOrder";
for (int i = 0; i < dt.Rows.Count; i++)
{
if (string.IsNullOrWhiteSpace(dt.Rows[i]["jtBillNo"]+"")) continue;
string jsonObj = JsonUtil.ToJsonObject(dt.Rows[i]);
string deljson = jsonObj.Substring(1, jsonObj.Length - 2);
ResponseMode mode = NewEmp.PostMethodToObj(url, deljson);
if (mode!=null&&0 == mode.ret)
{
//有完工时间的行才会改变同步状态
if ("1".Equals(dt.Rows[i]["comid"] + "") || "1".Equals(dt.Rows[i]["finish"] + "") || !string.IsNullOrWhiteSpace(dt.Rows[i]["enddt"] + ""))
{
sqlValue = string.Format("update mrp_WorkTaskListTab set SyncFlag = 1 where mrp_lwt_workno='{0}' and mrp_lwt_workordername='{1}' and mrp_lwt_id='{2}'", dt.Rows[i]["mrp_lwt_workno"], dt.Rows[i]["mrp_lwt_workordername"], dt.Rows[i]["mrp_lwt_id"]);
SqlHelper.ExecuteNonQuery(sqlValue);
}
string updareabak = DateTime.Now + string.Format(" 工单号{0},工序{1} 信息同步成功.\r\n", dt.Rows[i]["mrp_lwt_workno"], dt.Rows[i]["mrp_lwt_workordername"]);
RefreshLogUIThread(updareabak);
}
else
{
string errorMsg = mode != null ? mode.msg : "未知原因.";
RefreshLogUIThread(DateTime.Now + string.Format("工单明细信息 信息读取失败,错误原因:{0}.\r\n", errorMsg));
}
}
////删除或者取消下发的工单信息。 SyncFlag标识 0还未同步 1正在同步 2同步成功
//RefreshLogUIThread("正在同步已删除和取消下发工单信息\r\n");
//string sqlValue2 = "update DeleteWorkOrderTable set SyncFlag='1' where ISNULL(SyncFlag,0)=0";//
//SqlHelper.ExecuteNonQuery(sqlValue2);
//sqlValue2 = "select * from DeleteWorkOrderTable where SyncFlag='1'";
//DataTable deleteDt = SqlHelper.ExecuteDataTable(sqlValue2);
//deleteDt.Columns.Remove("SyncFlag");
////推送程序中删除或取消下发的工单数据
//for (int i = 0; i < deleteDt.Rows.Count; i++)
//{
// string jsonObj = JsonUtil.ToJsonObject(deleteDt.Rows[i]);
// string deljson = jsonObj.Substring(1, jsonObj.Length - 2);
// deljson = deljson.Replace("\"true\"", "true");
// //url = "http://110.185.210.70:8881/business/receive/followWorkOrder";
// ResponseMode mode = NewEmp.PostMethodToObj(url, deljson);
// if (mode != null && mode.msg.Equals("success"))
// {
// //修改标识
// //sqlValue2 = string.Format("update DeleteWorkOrderTable set SyncFlag='2' where SyncFlag='1' and mrp_lwt_workno='{0}' and mrp_lwt_workordername='{1}'", deleteDt.Rows[i]["mrp_lwt_workno"], deleteDt.Rows[i]["mrp_lwt_workordername"]);
// sqlValue2 = string.Format("update DeleteWorkOrderTable set SyncFlag='2' where SyncFlag='1' and mrp_lwt_workno='{0}' and mrp_lwt_workordername='{1}' and mrp_lwt_id='{2}'", deleteDt.Rows[i]["mrp_lwt_workno"], deleteDt.Rows[i]["mrp_lwt_workordername"], deleteDt.Rows[i]["mrp_lwt_id"]);
// SqlHelper.ExecuteNonQuery(sqlValue2);
// }
// else if(string.IsNullOrWhiteSpace(deleteDt.Rows[i]["jtBillNo"] +"")&& !string.IsNullOrWhiteSpace(deleteDt.Rows[i]["mrp_lwt_id"] + ""))
// {
// //如果机器编号未空,则直接算同步成功,不会再次同步
// sqlValue2 = string.Format("update DeleteWorkOrderTable set SyncFlag='2' where mrp_lwt_id='{0}'", deleteDt.Rows[i]["mrp_lwt_id"]);
// SqlHelper.ExecuteNonQuery(sqlValue2);
// }
//}
//清空删除信息表
//sqlValue2 = "delete DeleteWorkOrderTable where SyncFlag='1'";
}
catch (Exception ex)
{
RefreshLogUIThread(DateTime.Now + string.Format("工单明细信息 信息读取失败.\r\n" + " 原因:" + ex.Message + Environment.NewLine));
}
RefreshLogUIThread(DateTime.Now + "工单明细信息 同步完成.\r\n");
RefreshLogUIThread("--------------------分割线------------------------\r\n");
}
/// <summary>
/// 后台线程刷新数据
/// </summary>
/// <param name="msg"></param>
public void RefreshLogUIThread(string msg)
{
if (this.IsHandleCreated)
{
Invoke((EventHandler)delegate
{
txtLog.Text += msg;
txtLog.Select(txtLog.TextLength, 0);
txtLog.ScrollToCaret();
});
}
}
/// <summary>
/// 后台线程清理数据
/// </summary>
/// <param name="msg"></param>
public void ReClearLogUIThread()
{
if (this.IsHandleCreated)
{
Invoke((EventHandler)delegate
{
txtLog.Clear();
});
}
}
/// <summary>
/// 主线程刷新数据
/// </summary>
/// <param name="msg"></param>
public void RefreshLog(string msg)
{
txtLog.Text += msg;
txtLog.Select(txtLog.TextLength, 0);
txtLog.ScrollToCaret();
}
#region
/// <summary>
/// <para>说明:连接服务器</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-08-09 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="isSave">if set to <c>true</c> [is save].</param>
public bool ConnectServer(bool isSave = false)
{
string serverName = this.txtSeverId.Text.Trim();//地址
string dbName = this.txtDataBase.Text.Trim();//数据库名
string user = this.txtName.Text.Trim();//用户名
string password = this.txtPassword.Text.Trim();//密码
if (string.IsNullOrWhiteSpace(serverName))
{
MessageUtil.Show(ResourceKeys.ServerNameIsNull);
return false;
}
if (string.IsNullOrWhiteSpace(dbName))
{
MessageUtil.Show(ResourceKeys.ServerDBIsNull);
return false;
}
if (string.IsNullOrWhiteSpace(user))
{
MessageUtil.Show("请重新输入用户名");
return false;
}
// 测试数据库连接
try
{
if (ConnectingToDatabase())
{
if (isSave)
{
}
else
{
IniUtil.IniWriteValue(company, "serverName", serverName);
IniUtil.IniWriteValue(company, "dbName", dbName);
IniUtil.IniWriteValue(company, "user", user);
IniUtil.IniWriteValue(company, "password", password);
return true;
}
}
else
{
MessageUtil.Show(ResourceKeys.ConnectFault);
return false;
}
}
catch (Exception ex)
{
MessageUtil.Show(ResourceKeys.ConnectFault);
}
return true;
}
/// <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 ConnectingToDatabase()
{
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)
{
// LogHelper.Instance.WriteLog(ex.Message);
}
return false;
}
/// <summary>
/// 获取连接服务器的字符串
/// </summary>
/// <returns></returns>
public string GetConnection()
{
return string.Format("Server={0};Database={1};Persist Security Info=True;User ID={2};Password={3};Connection Timeout=5;MultipleActiveResultSets=true", txtSeverId.Text.ToString(), txtDataBase.Text.ToString(), txtName.Text.ToString(), txtPassword.Text.ToString());
}
#endregion
}
}
+120
View File
@@ -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,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Web.Script.Serialization;
namespace SynchronousOven.HttpUtil
{
public static class GetUtil
{
/// <summary>
/// <para>说明:获取Response Html</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-08-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="url">The URL.</param>
/// <returns>System.String.</returns>
public static string Get(string url)
{
return RequestUtil.HttpGet(url);
}
/// <summary>
/// <para>说明:获取JSON数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="url">The URL.</param>
/// <returns>T.</returns>
public static T GetJson<T>(string url)
{
string returnText = RequestUtil.HttpGet(url);
JavaScriptSerializer js = new JavaScriptSerializer();
T result = js.Deserialize<T>(returnText);
return result;
}
/// <summary>
/// <para>说明:获取JSON数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="url">The URL.</param>
/// <param name="header">The header.</param>
/// <returns>T.</returns>
public static T GetJson<T>(string url, WebHeaderCollection header)
{
string returnText = RequestUtil.HttpGet(url, header);
JavaScriptSerializer js = new JavaScriptSerializer();
T result = js.Deserialize<T>(returnText);
return result;
}
}
}
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SynchronousOven.HttpUtil
{
/// <summary>
/// Request请求枚举
/// </summary>
public enum MethodEnum
{
POST,
GET,
PUT,
DELETE
}
}
@@ -0,0 +1,135 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web.Script.Serialization;
namespace SynchronousOven.HttpUtil
{
/// <summary>
/// Post帮助类
/// </summary>
public static class PostUtil
{
/// <summary>
/// <para>说明:获取Post结果</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="returnText">The return text.</param>
/// <returns>T.</returns>
public static T GetResult<T>(string returnText)
{
JavaScriptSerializer js = new JavaScriptSerializer();
T result = js.Deserialize<T>(returnText);
return result;
}
/// <summary>
/// <para>说明:发起Post请求</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <typeparam name="T">返回数据类型(Json对应的实体)</typeparam>
/// <param name="url">请求Url</param>
/// <param name="content">The content.</param>
/// <returns>T.</returns>
public static T PostUrl<T>(string url, string content)
{
string returnText = RequestUtil.HttpPost(url, content);
var result = GetResult<T>(returnText);
return result;
}
/// <summary>
/// <para>说明:发起Post请求</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="url">The URL.</param>
/// <param name="content">The content.</param>
/// <param name="header">The header.</param>
/// <returns>T.</returns>
public static T PostUrl<T>(string url, string content, WebHeaderCollection header)
{
string returnText = RequestUtil.HttpPost(url, content, header);
var result = GetResult<T>(returnText);
return result;
}
/// <summary>
/// <para>说明:发起Post请求</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="url">The URL.</param>
/// <param name="content">The content.</param>
/// <param name="header">The header.</param>
/// <param name="method">The method.</param>
/// <returns>T.</returns>
public static T PostUrl<T>(string url, string content, WebHeaderCollection header, MethodEnum method)
{
string returnText = RequestUtil.HttpPost(url, content, header, method);
var result = GetResult<T>(returnText);
return result;
}
/// <summary>
/// <para>说明:发起Post请求</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <typeparam name="T">返回数据类型(Json对应的实体)</typeparam>
/// <param name="url">请求Url</param>
/// <param name="cookieContainer">CookieContainer,如果不需要则设为null</param>
/// <param name="fileName">要发送的文件名,如果不需要上传则设为null</param>
/// <returns>T.</returns>
public static T PostGetJson<T>(string url, CookieContainer cookieContainer, string fileName)
{
string returnText = RequestUtil.HttpPost(url, cookieContainer, fileName);
var result = GetResult<T>(returnText);
return result;
}
/// <summary>
/// <para>说明:发起Post请求</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <typeparam name="T">返回数据类型(Json对应的实体)</typeparam>
/// <param name="url">请求Url</param>
/// <param name="cookieContainer">CookieContainer,如果不需要则设为null</param>
/// <param name="fileStream">文件流</param>
/// <returns>T.</returns>
public static T PostGetJson<T>(string url, CookieContainer cookieContainer, Stream fileStream)
{
string returnText = RequestUtil.HttpPost(url, cookieContainer, fileStream);
var result = GetResult<T>(returnText);
return result;
}
}
}
@@ -0,0 +1,284 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
namespace SynchronousOven.HttpUtil
{
/// <summary>
/// Request请求帮助类
/// </summary>
public static class RequestUtil
{
/// <summary>
/// <para>说明:使用Get方法获取字符串结果(暂时没有加入Cookie</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="url">The URL.</param>
/// <returns>System.String.</returns>
public static string HttpGet(string url)
{
WebClient wc = new WebClient();
wc.Encoding = Encoding.UTF8;
return wc.DownloadString(url);
}
/// <summary>
/// <para>说明:使用Get方法获取字符串结果(暂时没有加入Cookie</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="header">The header.</param>
/// <returns>System.String.</returns>
public static string HttpGet(string url, WebHeaderCollection header)
{
WebClient wc = new WebClient();
if (header != null)
{
wc.Headers = header;
}
wc.Encoding = Encoding.UTF8;
return wc.DownloadString(url);
}
/// <summary>
/// <para>说明:使用Post方法获取字符串结果</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="cookieContainer">The cookie container.</param>
/// <param name="fileName">Name of the file.</param>
/// <returns>System.String.</returns>
public static string HttpPost(string url, CookieContainer cookieContainer, string fileName)
{
FileStream fileStream = null;
if (!string.IsNullOrEmpty(fileName) && File.Exists(fileName))
{
//读取文件
fileStream = new FileStream(fileName, FileMode.Open);
}
return HttpPost(url, cookieContainer, fileStream);
}
/// <summary>
/// <para>说明:使用Post方法获取字符串结果</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="content">The content.</param>
/// <param name="timeout">The timeout.</param>
/// <returns>System.String.</returns>
public static string HttpPost(string url, string content, int timeout = 5000)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ServicePoint.Expect100Continue = false;
request.ContentType = "application/json;charset=utf8";
request.Timeout = timeout;
byte[] buffer = Encoding.UTF8.GetBytes(content);
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
HttpWebResponse response = null;
try
{
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException ex)
{
response = (HttpWebResponse)ex.Response;
Console.WriteLine(ex.Message);
return "";
}
using (Stream responseStream = response.GetResponseStream())
{
using (StreamReader myStreamReader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8")))
{
string retString = myStreamReader.ReadToEnd();
return retString;
}
}
}
/// <summary>
/// <para>说明:使用Post方法获取字符串结果</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="content">The content.</param>
/// <param name="header">The header.</param>
/// <returns>System.String.</returns>
public static string HttpPost(string url, string content, WebHeaderCollection header)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
if (header != null)
{
request.Headers = header;
}
request.ServicePoint.Expect100Continue = false;
request.ContentType = "application/json;charset=utf8";
byte[] buffer = Encoding.UTF8.GetBytes(content);
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
HttpWebResponse response = null;
try
{
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException ex)
{
response = (HttpWebResponse)ex.Response;
Console.WriteLine(ex.Message);
return "";
}
using (Stream responseStream = response.GetResponseStream())
{
using (StreamReader myStreamReader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8")))
{
string retString = myStreamReader.ReadToEnd();
return retString;
}
}
}
/// <summary>
/// <para>说明:使用Post方法获取字符串结果</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="content">The content.</param>
/// <param name="header">The header.</param>
/// <param name="method">The method.</param>
/// <returns>System.String.</returns>
public static string HttpPost(string url, string content, WebHeaderCollection header, MethodEnum method)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = method.ToString();
if (header != null)
{
request.Headers = header;
}
request.ServicePoint.Expect100Continue = false;
request.ContentType = "application/json;charset=utf8";
byte[] buffer = Encoding.UTF8.GetBytes(content);
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
HttpWebResponse response = null;
try
{
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException ex)
{
response = (HttpWebResponse)ex.Response;
Console.WriteLine(ex.Message);
return "";
}
using (Stream responseStream = response.GetResponseStream())
{
using (StreamReader myStreamReader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8")))
{
string retString = myStreamReader.ReadToEnd();
return retString;
}
}
}
/// <summary>
/// <para>说明:使用Post方法获取字符串结果</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="cookieContainer">The cookie container.</param>
/// <param name="fileStream">The file stream.</param>
/// <returns>System.String.</returns>
public static string HttpPost(string url, CookieContainer cookieContainer, Stream fileStream)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
//request.ContentType = "application/x-www-form-urlencoded";
request.ContentType = "application/json;charset=utf8";
request.ContentLength = fileStream != null ? fileStream.Length : 0;
if (cookieContainer != null)
{
request.CookieContainer = cookieContainer;
}
if (fileStream != null)
{
Stream requestStream = request.GetRequestStream();
byte[] buffer = new byte[1024];
int bytesRead = 0;
while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
{
requestStream.Write(buffer, 0, bytesRead);
}
fileStream.Close();//关闭文件访问
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (cookieContainer != null)
{
response.Cookies = cookieContainer.GetCookies(response.ResponseUri);
}
using (Stream responseStream = response.GetResponseStream())
{
using (StreamReader myStreamReader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8")))
{
string retString = myStreamReader.ReadToEnd();
return retString;
}
}
}
/// <summary>
/// <para>说明:请求是否发起自客户端的浏览器</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-07-30 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="httpContext">The HTTP context.</param>
/// <returns><c>true</c> if [is sogou client request] [the specified HTTP context]; otherwise, <c>false</c>.</returns>
public static bool IsSogouClientRequest(HttpContext httpContext)
{
return !string.IsNullOrEmpty(httpContext.Request.UserAgent) &&
httpContext.Request.UserAgent.Contains("MicroMessenger");
}
}
}
+91
View File
@@ -0,0 +1,91 @@
using Lskj.Util;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace SynchronousOven
{
public static class IniUtil
{
/// <summary>
/// ini文件目录
/// </summary>
static string location = Environment.CurrentDirectory + "\\" + "Setting.ini";
/// <summary>
/// ini文件获取数据
/// </summary>
/// <param name="section"></param>
/// <param name="key"></param>
/// <param name="defVal"></param>
/// <param name="retVal"></param>
/// <param name="size"></param>
/// <param name="filePath"></param>
/// <returns></returns>
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string defVal, StringBuilder retVal, int size, string filePath);
/// <summary>
/// ini文件写入数据
/// </summary>
/// <param name="section"></param>
/// <param name="key"></param>
/// <param name="val"></param>
/// <param name="filePath"></param>
/// <returns></returns>
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
/// <summary>
/// 写INI文件
/// </summary>
/// <param name="section">段落</param>
/// <param name="key">键</param>
/// <param name="iValue">值</param>
public static void IniWriteValue(string section, string key, string iValue)
{
WritePrivateProfileString(section, key, iValue, location);
}
/// <summary>
/// 读取INI文件
/// </summary>
/// <param name="section">段落</param>
/// <param name="key">键</param>
/// <returns>返回的键值</returns>
public static string IniReadValue(string section, string key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(section, key, "", temp, 255, location);
return temp.ToString();
}
//public static string Read(string iniName, string mainKey, string listKey)
//{
// string value = string.Empty;
// try
// {
// 判读INI文件是否存在
// string filePath = Path.Combine(new string[] { PubUtil.AbsolutelyPath + iniName });
// if (File.Exists(filePath))
// {
// StringBuilder temp = new StringBuilder(1024);
// string fileName = Path.GetFileNameWithoutExtension(filePath);
// GetPrivateProfileString(mainKey, listKey, "", temp, 1024, filePath);
// return temp + "";
// }
// }
// catch (Exception)
// {
// }
// return value;
//}
}
}
+170
View File
@@ -0,0 +1,170 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web.Script.Serialization;
namespace SynchronousOven
{
public static class JsonUtil
{
/// <summary>
/// <para>说明:json 字符串转换为DataTable</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-10-23 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="json">The json.</param>
/// <returns>DataTable.</returns>
public static DataTable ToDataTable(this string json)
{
DataTable dataTable = new DataTable(); //实例化
DataTable result;
try
{
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
javaScriptSerializer.MaxJsonLength = Int32.MaxValue; //取得最大数值
ArrayList arrayList = javaScriptSerializer.Deserialize<ArrayList>(json);
if (arrayList.Count > 0)
{
foreach (Dictionary<string, object> dictionary in arrayList)
{
if (dictionary.Keys.Count<string>() == 0)
{
result = dataTable;
return result;
}
if (dataTable.Columns.Count == 0)
{
foreach (string current in dictionary.Keys)
{
dataTable.Columns.Add(current, dictionary[current].GetType());
}
}
DataRow dataRow = dataTable.NewRow();
foreach (string current in dictionary.Keys)
{
dataRow[current] = dictionary[current];
}
dataTable.Rows.Add(dataRow); //循环添加行到DataTable中
}
}
}
catch
{
}
result = dataTable;
return result;
}
/// <summary>
/// <para>说明:</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-10-23 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="json">The json.</param>
/// <returns>DataRow.</returns>
public static DataRow ToDataRow(this string json)
{
if (string.IsNullOrWhiteSpace(json)) return null;
return ToDataTable(json).Rows[0];
}
/// <summary>
/// <para>说明:DataTable To JsonArray</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-10-23 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="dtTable">The dt table.</param>
/// <returns>System.String.</returns>
public static string ToJsonArray(this DataTable dtTable)
{
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
javaScriptSerializer.MaxJsonLength = Int32.MaxValue; //取得最大数值
ArrayList arrayList = new ArrayList();
foreach (DataRow dataRow in dtTable.Rows)
{
Dictionary<string, object> dictionary = new Dictionary<string, object>(); //实例化一个参数集合
foreach (DataColumn dataColumn in dtTable.Columns)
{
dictionary.Add(dataColumn.ColumnName, dataRow[dataColumn.ColumnName].ToStr());
}
arrayList.Add(dictionary); //ArrayList集合中添加键值
}
return javaScriptSerializer.Serialize(arrayList); //返回一个json字符串
}
/// <summary>
/// <para>说明:DataRow To Json</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-10-23 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="row">The row.</param>
/// <returns>System.String.</returns>
public static string ToJsonObject(this DataRow row)
{
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
javaScriptSerializer.MaxJsonLength = Int32.MaxValue; //取得最大数值
ArrayList arrayList = new ArrayList();
Dictionary<string, object> dictionary = new Dictionary<string, object>(); //实例化一个参数集合
foreach (DataColumn dataColumn in row.Table.Columns)
{
dictionary.Add(dataColumn.ColumnName, row[dataColumn.ColumnName].ToStr());
}
arrayList.Add(dictionary); //ArrayList集合中添加键值
return javaScriptSerializer.Serialize(arrayList);
}
/// <summary>
/// <para>说明:</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-10-23 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="s">The s.</param>
/// <param name="format">The format.</param>
/// <returns>A <see cref="System.String" /> that represents this instance.</returns>
public static string ToStr(this object s, string format = "")
{
string result = string.Empty;
try
{
if (string.IsNullOrWhiteSpace(format))
{
result = s.ToString();
}
else
{
result = string.Format("{0:" + format + "}", s);
}
}
catch
{
}
return result;
}
}
}
+74
View File
@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace SynchronousOven
{
public static class LogUtil
{
/// <summary>
/// Log文件夹目录
/// </summary>
static string folderPath;
/// <summary>
/// 日志文件目录
/// </summary>
static string filePath;
/// <summary>
/// 写入日志
/// </summary>
public static void WriteLocalLog(string log)
{
try
{
//获取程序目录,并完整日志文件夹目录
folderPath = System.IO.Directory.GetCurrentDirectory() + "\\Log";
//TXT日志目录
filePath = folderPath + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
//判断是否存在文件夹
if (!System.IO.Directory.Exists(folderPath))
{
//创建文件夹
Directory.CreateDirectory(folderPath);
}
inPut(log);
}
catch (Exception ex)
{
}
}
/// <summary>
/// 写入日志事件
/// </summary>
/// <param name="log"></param>
private static void inPut(string log)
{
//判断是否存在此TXT文件
if (!System.IO.File.Exists(filePath))
{
FileStream fs1 = new FileStream(filePath, FileMode.Create, FileAccess.Write);//创建写入文件
StreamWriter sw = new StreamWriter(fs1);
sw.WriteLine(log);//开始写入值
sw.Close();
fs1.Close();
}
else
{
FileStream fs1 = new FileStream(filePath, FileMode.Append, FileAccess.Write);//获取文件尾行
StreamWriter sw = new StreamWriter(fs1);
sw.WriteLine(log);//开始写入值
sw.Close();
fs1.Close();
}
}
}
}
+92
View File
@@ -0,0 +1,92 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SynchronousOven
{
public sealed class NewEmp
{
/// <summary>
/// 同步数据
/// </summary>
/// <param name="
/// ">没有特殊说明,传入</param>
public static ResponseMode PostMethodToObj(string url, string jsonObj)
{
try
{
return HttpUtil.PostUtil.PostUrl<ResponseMode>(url, jsonObj);
}
catch (Exception)
{
throw;
//return JsonConvert.SerializeObject(new ResponseMode{ code = "-1", errorMsg = "非法操作." });
}
}
/// <summary>
/// 同步数据
/// </summary>
public static ResponseMode GetUrl(string url)
{
try
{
return HttpUtil.GetUtil.GetJson<ResponseMode>(url);
}
catch (Exception)
{
throw;
//return JsonConvert.SerializeObject(new ResponseMode{ code = "-1", errorMsg = "非法操作." });
}
}
/// <summary>
/// 新的响应对象
/// </summary>
public class ResponseMode
{
public int ret;
public string msg;
// public data data;
}
/// <summary>
/// 同步数据
/// </summary>
/// <param name="
/// ">没有特殊说明,传入</param>
public static newResponseMode newPostMethodToObj(string url, string jsonObj)
{
try
{
return HttpUtil.PostUtil.PostUrl<newResponseMode>(url, jsonObj);
}
catch (Exception)
{
throw;
//return JsonConvert.SerializeObject(new ResponseMode{ code = "-1", errorMsg = "非法操作." });
}
}
/// <summary>
/// 新的响应对象
/// </summary>
public class newResponseMode
{
//public int ret;
public string msg;
public string code;
public data data;
}
}
}
+21
View File
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace SynchronousOven
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("SynchronousOven")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SynchronousOven")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("75123069-f5e5-4516-8afb-e156a517941d")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,70 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本: 4.0.30319.42000
//
// 对此文件的更改可能导致不正确的行为,如果
// 重新生成代码,则所做更改将丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace SynchronousOven.Properties
{
/// <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 ((resourceMan == null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SynchronousOven.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,29 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace SynchronousOven.Properties
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.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>
+605
View File
@@ -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.SqlClient;
using System.Data;
namespace SynchronousOven
{
/// <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,106 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{75123069-F5E5-4516-8AFB-E156A517941D}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>SynchronousOven</RootNamespace>
<AssemblyName>SynchronousOven</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<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|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Lskj.Business">
<HintPath>..\..\Debug\Lskj.Business.dll</HintPath>
</Reference>
<Reference Include="Lskj.Control">
<HintPath>..\..\Debug\Lskj.Control.dll</HintPath>
</Reference>
<Reference Include="Lskj.Core">
<HintPath>..\..\Debug\Lskj.Core.dll</HintPath>
</Reference>
<Reference Include="Lskj.Data">
<HintPath>..\..\Debug\Lskj.Data.dll</HintPath>
</Reference>
<Reference Include="Lskj.Util">
<HintPath>..\..\Debug\Lskj.Util.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="data.cs" />
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="HttpUtil\GetUtil.cs" />
<Compile Include="HttpUtil\MethodEnum.cs" />
<Compile Include="HttpUtil\PostUtil.cs" />
<Compile Include="HttpUtil\RequestUtil.cs" />
<Compile Include="IniUtil.cs" />
<Compile Include="JsonUtil.cs" />
<Compile Include="LogUtil.cs" />
<Compile Include="NewEmp.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SqlHelper.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<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>
</Compile>
<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>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
@@ -0,0 +1,25 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31613.86
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SynchronousOven", "SynchronousOven.csproj", "{75123069-F5E5-4516-8AFB-E156A517941D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{75123069-F5E5-4516-8AFB-E156A517941D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{75123069-F5E5-4516-8AFB-E156A517941D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{75123069-F5E5-4516-8AFB-E156A517941D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{75123069-F5E5-4516-8AFB-E156A517941D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {41E9245C-1026-4D31-B324-F8523458A462}
EndGlobalSection
EndGlobal
+16
View File
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SynchronousOven
{
public class data
{
//public string temp;
//public object _id;
//public string jtBillNo;
public string token;//token
public string userName; //用户名
}
}
Binary file not shown.