You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
329 lines
12 KiB
C#
329 lines
12 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using MySql.Data.MySqlClient;
|
|
using System.Data;
|
|
using ADOX;
|
|
using System.IO;
|
|
using demo.ClassHelper.FileOperate;
|
|
|
|
namespace demo
|
|
{
|
|
class OperMySql
|
|
{
|
|
//yf_id yf_OddNumbers yf_applicant_sfzid yf_applicant_name yf_receiver_name yf_phone yf_intime yf_readtime yf_state
|
|
public static string strConn = "server='113.57.198.100';user id='yzyfj';password='bhyzyfj';database='yzyfj';Allow Zero Datetime=True";//表名yfj
|
|
public static string tableName = "yfj";
|
|
public static string jgh = "43001800";
|
|
public static string gh = "YFJ000001";
|
|
public static bool GetPostInfo(string sfzid, ref string oddNumbers, ref string receiveName, ref string address, ref string phoneNumber)
|
|
{
|
|
bool flag = false;
|
|
MySqlConnection conn = null;
|
|
MySqlCommand cmd = null;
|
|
object obj = null;
|
|
string sql_oddNum = string.Format("select yf_OddNumbers from {0} where yf_applicant_sfzid = {1}", tableName, sfzid);
|
|
try
|
|
{
|
|
conn = new MySqlConnection(strConn);
|
|
conn.Open();
|
|
cmd = new MySqlCommand(sql_oddNum, conn);
|
|
obj = cmd.ExecuteScalar();
|
|
oddNumbers = obj.ToString();
|
|
flag = true;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
finally
|
|
{
|
|
cmd.Dispose();
|
|
conn.Close();
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
public static bool SelectPostInfoBySfzID(string sfzid, ref string yf_id, ref string recvAddress, ref string postNo, ref string recvName, ref string recvNo, ref string applicantName)
|
|
{
|
|
bool flag = false;
|
|
MySqlConnection conn = null;
|
|
MySqlCommand cmd = null;
|
|
DataSet ds = new DataSet();
|
|
string sql = null;
|
|
//sql = string.Format("select * from {0} where yf_applicant_sfzid = '{1}'", tableName, sfzid);
|
|
sql = string.Format("select yf_id ,yf_OddNumbers,yf_applicant_name,yf_receiver_name,yf_address,yf_phone_number,yf_intime time,yf_state from {0} where yf_applicant_sfzid = '{1}'", tableName, sfzid);
|
|
try
|
|
{
|
|
conn = new MySqlConnection(strConn);
|
|
conn.Open();
|
|
cmd = new MySqlCommand(sql, conn);
|
|
MySqlDataAdapter sda = new MySqlDataAdapter(cmd);
|
|
sda.Fill(ds);
|
|
|
|
//DataTable dt = new DataTable();
|
|
//sda.Fill(dt);
|
|
//for (int i = 0; i < dt.Rows.Count; i++)
|
|
//{
|
|
// for (int j = 0; j < dt.Columns.Count; j++)
|
|
// {
|
|
// //Console.WriteLine(dt.Rows[i][j].ToString());
|
|
// string str = dt.Rows[i][j].ToString();
|
|
// }
|
|
//}
|
|
//Console.ReadKey();
|
|
|
|
if (ds.Tables[0].Rows.Count == 1)
|
|
{
|
|
yf_id = ds.Tables[0].Rows[0]["yf_id"].ToString();
|
|
|
|
recvAddress = ds.Tables[0].Rows[0]["yf_address"].ToString();
|
|
postNo = ds.Tables[0].Rows[0]["yf_OddNumbers"].ToString();
|
|
recvName = ds.Tables[0].Rows[0]["yf_receiver_name"].ToString();
|
|
recvNo = ds.Tables[0].Rows[0]["yf_phone_number"].ToString();
|
|
applicantName = ds.Tables[0].Rows[0]["yf_applicant_name"].ToString();
|
|
flag = true;
|
|
}
|
|
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
finally
|
|
{
|
|
cmd.Dispose();
|
|
conn.Close();
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
public static bool SelectSingleInfo(int _field, string sfzid, ref string info)
|
|
{
|
|
bool flag = false;
|
|
MySqlConnection conn = null;
|
|
MySqlCommand cmd = null;
|
|
object obj = null;
|
|
string sql = null;
|
|
switch (_field)
|
|
{
|
|
case 1: sql = string.Format("select yf_OddNumbers from {0} where yf_applicant_sfzid = {1}", tableName, sfzid);
|
|
break;
|
|
case 2: sql = string.Format("select yf_receiver_name from {0} where yf_applicant_sfzid = {1}", tableName, sfzid);
|
|
break;
|
|
case 3: sql = string.Format("select yf_address from {0} where yf_applicant_sfzid = {1}", tableName, sfzid);
|
|
break;
|
|
case 4: sql = string.Format("select yf_phone_number from {0} where yf_applicant_sfzid = {1}", tableName, sfzid);
|
|
break;
|
|
case 5: sql = string.Format("select yf_address from {0} where yf_applicant_sfzid = {1}", tableName, sfzid);
|
|
break;
|
|
//case 6: sql = string.Format("select yf_ems_department from {0} where yf_applicant_sfzid = {1}", tableName, sfzid);
|
|
// break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
try
|
|
{
|
|
conn = new MySqlConnection(strConn);
|
|
conn.Open();
|
|
cmd = new MySqlCommand(sql, conn);
|
|
obj = cmd.ExecuteScalar();
|
|
info = obj.ToString();
|
|
flag = true;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
finally
|
|
{
|
|
cmd.Dispose();
|
|
conn.Close();
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
public static bool InsertCheckState(string sfzid, string state)
|
|
{
|
|
bool flag = false;
|
|
MySqlConnection conn = null;
|
|
MySqlCommand cmd = null;
|
|
string readTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
|
|
string jgh0 = null, gh0 = null;
|
|
if ("否" == state)
|
|
{
|
|
readTime = null;
|
|
}
|
|
else
|
|
{
|
|
jgh0 = jgh;
|
|
gh0 = gh;
|
|
}
|
|
string sql = string.Format("update {0} set yf_read_time = '{1}',yf_state = '{2}',yf_jgh = '{3}',yf_gh = '{4}' where yf_applicant_sfzid = '{5}'",
|
|
tableName, readTime, state, jgh0, gh0, sfzid);
|
|
try
|
|
{
|
|
conn = new MySqlConnection(strConn);
|
|
conn.Open();
|
|
cmd = new MySqlCommand(sql, conn);
|
|
cmd.ExecuteNonQuery();
|
|
flag = true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string str = ex.ToString();
|
|
}
|
|
finally
|
|
{
|
|
cmd.Dispose();
|
|
conn.Close();
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 建立带安全机制的access数据库
|
|
/// </summary>
|
|
/// <param name="Path">数据库路径</param>
|
|
/// <param name="User">数据库用户</param>
|
|
/// <param name="UserPass">数据库用户密码</param>
|
|
/// <param name="SecurityFile">数据库安全文件</param>
|
|
/// <param name="DataPass">数据库组密码</param>
|
|
private void CrtAccBase(string Path, string User, string UserPass, string SecurityFile, string DataPass)
|
|
{
|
|
try
|
|
{
|
|
ADOX.Catalog catalog = new Catalog();
|
|
catalog.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path + ";PassWord=" + UserPass + ";User Id=" + User + ";Jet OLEDB:Database Password=" + DataPass + ";Jet OLEDB:System database=" + SecurityFile + "");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message);
|
|
}
|
|
}
|
|
|
|
public static bool UploadRemoteData(ref DataTable dt)
|
|
{
|
|
double days;
|
|
DateTime writeTime;
|
|
string startTime, endTime;
|
|
FileInfo fi = new FileInfo(MySqlite.path);
|
|
writeTime = fi.LastWriteTime;
|
|
string writeDay = writeTime.ToString("yyyy/MM/dd");
|
|
string nowDay = DateTime.Now.ToString("yyyy/MM/dd");
|
|
long fiSize = fi.Length / 1024;
|
|
if (writeDay == nowDay && fiSize > 8)
|
|
{
|
|
return true;
|
|
}
|
|
if (fiSize <= 8)
|
|
{
|
|
startTime = DateTime.Now.AddDays(-60).ToString("yyyy/MM/dd");
|
|
}
|
|
else
|
|
{
|
|
startTime = writeTime.AddSeconds(1).ToString("yyyy/MM/dd HH:mm:SS");
|
|
}
|
|
bool ret = false;
|
|
string sql = null;
|
|
MySqlConnection conn = new MySqlConnection(OperMySql.strConn);
|
|
MySqlCommand cmd = null;
|
|
//DataTable dt = new DataTable();
|
|
|
|
endTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:SS");
|
|
|
|
//sql = string.Format("select * from yfj where yf_intime>='{0}' and yf_intime<='{1}' and yf_state = '{2}'", startTime, endTime, "否");
|
|
sql = string.Format("select yf_id ,yf_OddNumbers,yf_applicant_sfzid,yf_applicant_name,yf_receiver_name,yf_address,yf_phone_number,yf_intime time,yf_state,yf_read_time time,yf_jgh,yf_gh,ztc_state from yfj where yf_intime>='{0}' and yf_intime<='{1}' and yf_state = '{2}'", startTime, endTime, "否");
|
|
|
|
cmd = new MySqlCommand(sql, conn);
|
|
try
|
|
{
|
|
conn.Open();
|
|
MySqlDataAdapter sda = new MySqlDataAdapter(cmd);
|
|
sda.Fill(dt);
|
|
ret = true;
|
|
GlobalVariable.loadDataCount = dt.Rows.Count;
|
|
IniHelper.WriteToIni("今日导入", "数量", dt.Rows.Count.ToString(), GlobalVariable.configPath);
|
|
}
|
|
catch (System.Exception ex)
|
|
{
|
|
|
|
}
|
|
finally
|
|
{
|
|
cmd.Dispose();
|
|
conn.Close();
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
public static bool UpdateCheckState(string yfid, string state)
|
|
{
|
|
lock (GlobalVariable.lockUpdateRemoteSql)
|
|
{
|
|
bool flag = false;
|
|
MySqlConnection conn = null;
|
|
MySqlCommand cmd = null;
|
|
string readTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
|
|
string sql = string.Format("update {0} set yf_read_time = '{1}',yf_state = '{2}',yf_jgh = '{3}',yf_gh = '{4}' where yf_id = '{5}'",
|
|
tableName, readTime, state, jgh, gh, yfid);
|
|
try
|
|
{
|
|
conn = new MySqlConnection(strConn);
|
|
conn.Open();
|
|
cmd = new MySqlCommand(sql, conn);
|
|
int i = cmd.ExecuteNonQuery();
|
|
if (i > 0)
|
|
{
|
|
flag = true;
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string str = ex.ToString();
|
|
}
|
|
finally
|
|
{
|
|
cmd.Dispose();
|
|
conn.Close();
|
|
}
|
|
return flag;
|
|
}
|
|
}
|
|
|
|
public static bool UpdateCheckStateBySfzid(string sfzid, string state)
|
|
{
|
|
bool flag = false;
|
|
MySqlConnection conn = null;
|
|
MySqlCommand cmd = null;
|
|
string readTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
|
|
string sql = string.Format("update {0} set yf_read_time = '{1}',yf_state = '{2}',yf_jgh = '{3}',yf_gh = '{4}' where yf_applicant_sfzid = '{5}'",
|
|
tableName, readTime, state, jgh, gh, sfzid);
|
|
try
|
|
{
|
|
conn = new MySqlConnection(strConn);
|
|
conn.Open();
|
|
cmd = new MySqlCommand(sql, conn);
|
|
int i = cmd.ExecuteNonQuery();
|
|
if (i > 0)
|
|
{
|
|
flag = true;
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string str = ex.ToString();
|
|
}
|
|
finally
|
|
{
|
|
cmd.Dispose();
|
|
conn.Close();
|
|
}
|
|
return flag;
|
|
}
|
|
}
|
|
}
|