temu客户端程序
This commit is contained in:
commit
4aaf264e89
694 files changed
+263780
No files matched your search
@@ -0,0 +1,284 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
|
||||
namespace AllBase
|
||||
{
|
||||
public class SqlHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据库链接串
|
||||
/// </summary>
|
||||
private string ConnString = "";
|
||||
/// <summary>
|
||||
/// 是否已经链接成功
|
||||
/// </summary>
|
||||
public bool Connected {
|
||||
get { return Connection != null && Connection.State == ConnectionState.Open; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 数据库链接
|
||||
/// </summary>
|
||||
private SqlConnection Connection =null;
|
||||
/// <summary>
|
||||
/// 执行超时
|
||||
/// </summary>
|
||||
public int TimeOut = 100;
|
||||
|
||||
public SqlHelper(string conn)
|
||||
{
|
||||
ConnString = conn;
|
||||
ConnTo();
|
||||
}
|
||||
|
||||
public string Replace(string key)
|
||||
{
|
||||
return key.Replace("'", "''");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行指定数据库连接对象的命令
|
||||
/// </summary>
|
||||
/// <param name="sql">T存储过程名称或T-SQL语句</param>
|
||||
/// <returns>返回影响的行数</returns>
|
||||
public int ExecuteNonQuery(string sql)
|
||||
{
|
||||
SqlCommand cmd = PrepareCommand(sql);
|
||||
try
|
||||
{
|
||||
// Finally, execute the command
|
||||
int retval = cmd.ExecuteNonQuery();
|
||||
return retval;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ErrorDoing(e.Message,sql);
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取插入ID
|
||||
/// </summary>
|
||||
/// <param name="sql"></param>
|
||||
/// <returns></returns>
|
||||
public int InsertId(string sql)
|
||||
{
|
||||
sql += ";SELECT @@IDENTITY";
|
||||
string id = ExecuteFirst(sql);
|
||||
int i = 0;
|
||||
int.TryParse(id, out i);
|
||||
return i;
|
||||
}
|
||||
/// <summary>
|
||||
/// 是否存在
|
||||
/// </summary>
|
||||
/// <param name="sql"></param>
|
||||
/// <returns></returns>
|
||||
public bool Exists(string sql)
|
||||
{
|
||||
string id = ExecuteFirst(sql);
|
||||
return !string.IsNullOrEmpty(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行指定数据库连接对象的命令,指定存储过程参数,返回DataSet.
|
||||
/// </summary>
|
||||
/// <param name="sql">存储过程名或T-SQL语句</param>
|
||||
/// <returns>返回一个包含结果集的DataSet</returns>
|
||||
public DataSet ExecuteDataset(string sql)
|
||||
{
|
||||
|
||||
SqlCommand cmd = PrepareCommand(sql);
|
||||
try
|
||||
{
|
||||
// 创建SqlDataAdapter和DataSet.
|
||||
SqlDataAdapter da = new SqlDataAdapter(cmd);
|
||||
|
||||
DataSet ds = new DataSet();
|
||||
// 填充DataSet.
|
||||
da.Fill(ds);
|
||||
cmd.Parameters.Clear();
|
||||
return ds;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ErrorDoing(e.Message,sql);
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行指定数据库连接对象的命令,指定存储过程参数,返回DataSet.
|
||||
/// </summary>
|
||||
/// <param name="sql">存储过程名或T-SQL语句</param>
|
||||
/// <returns>返回一个包含结果集的DataSet</returns>
|
||||
public DataTable ExecuteDataTable(string sql)
|
||||
{
|
||||
|
||||
SqlCommand cmd = PrepareCommand(sql);
|
||||
try
|
||||
{
|
||||
// 创建SqlDataAdapter和DataSet.
|
||||
SqlDataAdapter da = new SqlDataAdapter(cmd);
|
||||
|
||||
DataTable ds = new DataTable();
|
||||
// 填充DataSet.
|
||||
da.Fill(ds);
|
||||
cmd.Parameters.Clear();
|
||||
return ds;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ErrorDoing(e.Message,sql);
|
||||
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行指定数据库连接对象的命令,指定存储过程参数,返回DataSet.
|
||||
/// </summary>
|
||||
/// <param name="sql">存储过程名或T-SQL语句</param>
|
||||
/// <returns>返回一个包含结果集的DataSet</returns>
|
||||
public DataRow ExecuteDataTableRow(string sql)
|
||||
{
|
||||
|
||||
SqlCommand cmd = PrepareCommand(sql);
|
||||
try
|
||||
{
|
||||
// 创建SqlDataAdapter和DataSet.
|
||||
SqlDataAdapter da = new SqlDataAdapter(cmd);
|
||||
|
||||
DataTable ds = new DataTable();
|
||||
// 填充DataSet.
|
||||
da.Fill(ds);
|
||||
if (ds.Rows.Count > 0)
|
||||
return ds.Rows[0];
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ErrorDoing(e.Message,sql);
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行指定数据库连接对象的命令,指定参数,返回结果集中的第一行第一列.
|
||||
/// </summary>
|
||||
/// <param name="sql">存储过程名称或T-SQL语句</param>
|
||||
/// <returns>返回结果集中的第一行第一列</returns>
|
||||
public string ExecuteFirst(string sql)
|
||||
{
|
||||
|
||||
SqlCommand cmd = PrepareCommand(sql);
|
||||
try
|
||||
{
|
||||
SqlDataAdapter da = new SqlDataAdapter(cmd);
|
||||
DataTable ds = new DataTable();
|
||||
// 填充DataSet.
|
||||
da.Fill(ds);
|
||||
// 执行SqlCommand命令,并返回结果.
|
||||
var retval = cmd.ExecuteScalar();
|
||||
|
||||
return retval==null?"": retval.ToString();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ErrorDoing(e.Message,sql);
|
||||
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 预处理用户提供的命令,数据库连接/事务/命令类型/参数
|
||||
/// </summary>
|
||||
/// <param name="commandText">存储过程名或都T-SQL命令文本</param>
|
||||
private SqlCommand PrepareCommand(string commandText)
|
||||
{
|
||||
SqlCommand command = new SqlCommand();
|
||||
if (Connection.State != ConnectionState.Open)
|
||||
ConnTo();
|
||||
|
||||
command.Connection = Connection;
|
||||
command.CommandText = commandText;
|
||||
command.CommandType = CommandType.Text;
|
||||
command.CommandTimeout = TimeOut;
|
||||
return command;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 针对不同错误,执行不同的修正
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
private void ErrorDoing(string message, string sql)
|
||||
{
|
||||
if (string.IsNullOrEmpty(message))
|
||||
return;
|
||||
if (message.Contains("Incorrect string value"))
|
||||
return;
|
||||
if (message.Contains("Connection must be valid and open"))
|
||||
ConnTo();
|
||||
if (message.Contains("There is already an open DataReader"))
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
ConnTo();
|
||||
}
|
||||
if (message.Contains("Fatal error encountered during command execution."))
|
||||
ConnTo();
|
||||
if (message.Contains(" StreamWriter ") || message.Contains("未将对象引用设置到对象的实例") || message.Contains("未将对象"))
|
||||
ConnTo();
|
||||
LogSave.Add("执行SQL:"+sql+" 错误:"+message);
|
||||
Random ra = new Random(Guid.NewGuid().GetHashCode());
|
||||
Thread.Sleep(ra.Next(200, 2000));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 链接数据库
|
||||
/// </summary>
|
||||
private void ConnTo()
|
||||
{
|
||||
try
|
||||
{
|
||||
Connection = new SqlConnection(ConnString);
|
||||
Connection.Open();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ErrorDoing(e.Message,ConnString);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭链接
|
||||
/// </summary>
|
||||
public void Close()
|
||||
{
|
||||
try
|
||||
{
|
||||
Connection.Close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static string ChatCss = ".el-message__closeBtn:focus,.el-message__content:focus{outline-width:0}.el-message{min-width:380px;-webkit-box-sizing:border-box;box-sizing:border-box;border-radius:4px;border-width:1px;border-style:solid;border-color:#ebeef5;position:fixed;left:50%;top:20px;-webkit-transform:translateX(-50%);transform:translateX(-50%);background-color:#edf2fc;-webkit-transition:opacity .3s,-webkit-transform .4s;transition:opacity .3s,-webkit-transform .4s;transition:opacity .3s,transform .4s;transition:opacity .3s,transform .4s,-webkit-transform .4s;overflow:hidden;padding:15px 15px 15px 20px;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-align:center;-ms-flex-align:center;align-items:center}.el-message.is-center{-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center}.el-message.is-closable .el-message__content{padding-right:16px}.el-message p{margin:0}.el-message--info .el-message__content{color:#909399}.el-message--success{background-color:#f0f9eb;border-color:#e1f3d8}.el-message--success .el-message__content{color:#67c23a}.el-message--warning{background-color:#fdf6ec;border-color:#faecd8}.el-message--warning .el-message__content{color:#e6a23c}.el-message--error{background-color:#fef0f0;border-color:#fde2e2}.el-message--error .el-message__content{color:#f56c6c}.el-message__icon{margin-right:10px}.el-message__content{padding:0;font-size:14px;line-height:1}.el-message__closeBtn{position:absolute;top:50%;right:15px;-webkit-transform:translateY(-50%);transform:translateY(-50%);cursor:pointer;color:#c0c4cc;font-size:16px}.el-message__closeBtn:hover{color:#909399}.el-message .el-icon-success{color:#67c23a}.el-message .el-icon-error{color:#f56c6c}.el-message .el-icon-info{color:#909399}.el-message .el-icon-warning{color:#e6a23c}.el-message-fade-enter,.el-message-fade-leave-active{opacity:0;-webkit-transform:translate(-50%,-100%);transform:translate(-50%,-100%)}.el-button,.el-input__inner{-webkit-appearance:none;outline:0}.el-message-box,.el-popup-parent--hidden{overflow:hidden}.v-modal-enter{-webkit-animation:v-modal-in .2s ease;animation:v-modal-in .2s ease}.v-modal-leave{-webkit-animation:v-modal-out .2s ease forwards;animation:v-modal-out .2s ease forwards}@-webkit-keyframes v-modal-in{0%{opacity:0}}@keyframes v-modal-in{0%{opacity:0}}@-webkit-keyframes v-modal-out{100%{opacity:0}}@keyframes v-modal-out{100%{opacity:0}}.v-modal{position:fixed;left:0;top:0;width:100%;height:100%;opacity:.5;background:#000}.el-button{display:inline-block;line-height:1;white-space:nowrap;cursor:pointer;background:#fff;border:1px solid #dcdfe6;color:#606266;text-align:center;-webkit-box-sizing:border-box;box-sizing:border-box;margin:0;-webkit-transition:.1s;transition:.1s;font-weight:500;-moz-user-select:none;-webkit-user-select:none;-ms-user-select:none;padding:12px 20px;font-size:14px;border-radius:4px}.el-button+.el-button{margin-left:10px}.el-button:focus,.el-button:hover{color:#409EFF;border-color:#c6e2ff;background-color:#ecf5ff}.el-button:active{color:#3a8ee6;border-color:#3a8ee6;outline:0}.el-button::-moz-focus-inner{border:0}.el-button [class*=el-icon-]+span{margin-left:5px}.el-button.is-plain:focus,.el-button.is-plain:hover{background:#fff;border-color:#409EFF;color:#409EFF}.el-button.is-active,.el-button.is-plain:active{color:#3a8ee6;border-color:#3a8ee6}.el-button.is-plain:active{background:#fff;outline:0}.el-button.is-disabled,.el-button.is-disabled:focus,.el-button.is-disabled:hover{color:#c0c4cc;cursor:not-allowed;background-image:none;background-color:#fff;border-color:#ebeef5}.el-button.is-disabled.el-button--text{background-color:transparent}.el-button.is-disabled.is-plain,.el-button.is-disabled.is-plain:focus,.el-button.is-disabled.is-plain:hover{background-color:#fff;border-color:#ebeef5;color:#c0c4cc}.el-button.is-loading{position:relative;pointer-events:none}.el-button.is-loading:before{pointer-events:none;position:absolute;left:-1px;top:-1px;right:-1px;bottom:-1px;border-radius:inherit;background-color:rgba(255,255,255,.35)}.el-button.is-round{border-radius:20px;padding:12px 23px}.el-button.is-circle{border-radius:50%;padding:12px}.el-button--primary{color:#fff;background-color:#409EFF;border-color:#409EFF}.el-button--primary:focus,.el-button--primary:hover{background:#66b1ff;border-color:#66b1ff;color:#fff}.el-button--primary.is-active,.el-button--primary:active{background:#3a8ee6;border-color:#3a8ee6;color:#fff}.el-button--primary:active{outline:0}.el-button--primary.is-disabled,.el-button--primary.is-disabled:active,.el-button--primary.is-disabled:focus,.el-button--primary.is-disabled:hover{color:#fff;background-color:#a0cfff;border-color:#a0cfff}.el-button--primary.is-plain{color:#409EFF;background:#ecf5ff;border-color:#b3d8ff}.el-button--primary.is-plain:focus,.el-button--primary.is-plain:hover{background:#409EFF;border-color:#409EFF;color:#fff}.el-button--primary.is-plain:active{background:#3a8ee6;border-color:#3a8ee6;color:#fff;outline:0}.el-but
Line truncated
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user