コード例 #1
0
 /// <summary>
 /// 修改密码
 /// </summary>
 /// <param name="ID"></param>
 /// <param name="password"></param>
 /// <param name="msg"></param>
 /// <returns></returns>
 public static int ChangePwd(decimal ID, string oldPwd, string newPwd, out string msg)
 {
     try
     {
         using (IDAL dal = DALBuilder.CreateDAL(ConfigurationManager.ConnectionStrings["SYSDB"].ConnectionString, 0))
         {
             dal.BeginTran();
             StringBuilder sql = new StringBuilder(256);
             sql.Append("SELECT UPassword ,UserCode FROM tUser WHERE ID=@ID ");
             dal.OpenReader(sql.ToString(),
                            dal.CreateParameter("@ID", ID)
                            );
             string oldDbPwd, UserCode;
             if (dal.DataReader.Read())
             {
                 oldDbPwd = Convert.ToString(dal.DataReader["UPassword"]).TrimEnd();
                 UserCode = Convert.ToString(dal.DataReader["UserCode"]).TrimEnd();
             }
             else
             {
                 msg = "未找到该用户";
                 return(0);
             }
             dal.DataReader.Close();
             if (!oldDbPwd.Equals(Des.EncryStrHex(oldPwd, UserCode)))
             {
                 //密码验证失败
                 msg = "密码验证失败";
                 return(0);
             }
             sql.Clear();
             sql.Append("UPDATE tUser SET UPassword=@UPassword WHERE ID=@ID");
             int i;
             dal.Execute(sql.ToString(), out i,
                         dal.CreateParameter("@UPassword", Des.EncryStrHex(newPwd, UserCode)),
                         dal.CreateParameter("@ID", ID)
                         );
             if (i == 1)
             {
                 dal.CommitTran();
                 msg = "success";
                 return(1);
             }
             else
             {
                 dal.RollBackTran();
                 msg = "error";
                 return(0);
             }
         }
     }
     catch (System.Exception ex)
     {
         msg = ex.Message;
         return(-1);
     }
 }
コード例 #2
0
 /// <summary>
 /// 保存数据库
 /// </summary>
 /// <param name="db"></param>
 /// <returns></returns>
 public static int InsertDatabase(ref Database db, out string msg)
 {
     try
     {
         using (IDAL dal = DALBuilder.CreateDAL(ConfigurationManager.ConnectionStrings["SYSDB"].ConnectionString, 0))
         {
             StringBuilder sql = new StringBuilder(256);
             sql.Append(" INSERT INTO tDatabase ( DBCode ,DBType ,DataSource ,DbName ,UserID ,Password ,Remark) ");
             sql.Append("VALUES  (");
             sql.Append("@DbCode,@DbType,@DataSource,@DbName,@UserID,@Password,@Remark )");
             dal.BeginTran();
             int i;
             dal.Execute(sql.ToString(), out i,
                         dal.CreateParameter("@DbCode", db.DbCode),
                         dal.CreateParameter("@DbType", db.DbType),
                         dal.CreateParameter("@DataSource", db.DataSource),
                         dal.CreateParameter("@DbName", db.DbName),
                         dal.CreateParameter("@UserID", db.UserID),
                         dal.CreateParameter("@Password", Des.EncryStrHex(db.Password, db.UserID)),
                         dal.CreateParameter("@Remark", db.Remark)
                         );
             if (i == 1)
             {
                 sql.Clear();
                 sql.Append("SELECT IDENT_CURRENT('tDatabase') ");
                 dal.OpenReader(sql.ToString());
                 if (dal.DataReader.Read())
                 {
                     db.ID = Convert.ToDecimal(dal.DataReader[0]);
                     dal.DataReader.Close();
                 }
                 else
                 {
                     dal.DataReader.Close();
                     dal.RollBackTran();
                     throw new Exception("获取报表ID失败");
                 }
                 dal.CommitTran();
                 msg = "success";
                 return(1);
             }
             else
             {
                 dal.RollBackTran();
                 msg = "error";
                 return(0);
             }
         }
     }
     catch (Exception ex)
     {
         msg = ex.Message;
         return(-1);
     }
 }
コード例 #3
0
 /// <summary>
 /// 增加用户
 /// </summary>
 /// <returns></returns>
 public static int AddUser(ref User user, out string msg)
 {
     try
     {
         using (IDAL dal = DALBuilder.CreateDAL(ConfigurationManager.ConnectionStrings["SYSDB"].ConnectionString, 0))
         {
             StringBuilder sql = new StringBuilder(256);
             sql.Append("insert into tUser(UserCode,UserName,UPassword,IsAdmin,Enabled) ");
             sql.Append("Values (");
             sql.AppendFormat("@UserCode,@UserName,@UPassword,@IsAdmin,@Enabled");
             sql.Append(")");
             dal.BeginTran();
             int i;
             dal.Execute(sql.ToString(), out i,
                         dal.CreateParameter("@UserCode", user.UserCode),
                         dal.CreateParameter("@UserName", user.UserName),
                         dal.CreateParameter("@UPassword", Des.EncryStrHex(user.UserCode, user.UserCode)),
                         dal.CreateParameter("@IsAdmin", user.IsAdmin ? 1 : 0),
                         dal.CreateParameter("@Enabled", user.Enabled)
                         );
             if (i == 1)
             {
                 sql.Clear();
                 sql.Append("SELECT IDENT_CURRENT('tUser') ");
                 dal.OpenReader(sql.ToString());
                 if (dal.DataReader.Read())
                 {
                     user.ID = Convert.ToInt32(dal.DataReader[0]);
                     dal.DataReader.Close();
                 }
                 else
                 {
                     dal.DataReader.Close();
                     dal.RollBackTran();
                     throw new Exception("获取ID失败");
                 }
                 dal.CommitTran();
                 msg = "success";
                 return(i);
             }
             else
             {
                 msg = "error";
                 dal.RollBackTran();
                 return(0);
             }
         }
     }
     catch (Exception ex)
     {
         msg = ex.Message;
         return(-1);
     }
 }
コード例 #4
0
 /// <summary>
 /// 初始化webservice 对象
 /// </summary>
 /// <param name="Url"></param>
 /// <param name="UserCode"></param>
 /// <param name="Password"></param>
 /// <param name="DeptNo"></param>
 public static void Init(string Url, string UserCode, string Password, string DeptNo)
 {
     if (TransClass == null)
     {
         TransClass = new Trans.TService.TransService();
         TransClass.CSoapHeaderValue = new CSoapHeader();
     }
     TransClass.Url = Url;
     TransClass.CSoapHeaderValue.UserCode = UserCode;
     TransClass.CSoapHeaderValue.Password = Des.EncryStrHex(Password, "0125" + UserCode);
     TransClass.CSoapHeaderValue.DeptNO   = DeptNo;
     TransClass.CSoapHeaderValue.PosNO    = PubGlobal.SysConfig.PosNO;
 }
コード例 #5
0
 /// <summary>
 /// 更新数据库
 /// </summary>
 /// <param name="id"></param>
 /// <param name="db"></param>
 /// <returns></returns>
 public static int UpdateDatabase(decimal ID, Database db, out string msg)
 {
     try
     {
         using (IDAL dal = DALBuilder.CreateDAL(ConfigurationManager.ConnectionStrings["SYSDB"].ConnectionString, 0))
         {
             StringBuilder sql = new StringBuilder(256);
             sql.Append(" UPDATE tDatabase SET DbCode=@DbCode,DbType=@DbType,DataSource=@DataSource,DbName=@DbName,UserID=@UserID,Password=@Password,Remark=@Remark ");
             sql.Append(" Where ID=@ID");
             dal.BeginTran();
             int i;
             dal.Execute(sql.ToString(), out i,
                         dal.CreateParameter("@DbCode", db.DbCode),
                         dal.CreateParameter("@DbType", db.DbType),
                         dal.CreateParameter("@DataSource", db.DataSource),
                         dal.CreateParameter("@DbName", db.DbName),
                         dal.CreateParameter("@UserID", db.UserID),
                         dal.CreateParameter("@Password", Des.EncryStrHex(db.Password, db.UserID)),
                         dal.CreateParameter("@Remark", db.Remark),
                         dal.CreateParameter("@ID", db.ID)
                         );
             if (i == 1)
             {
                 dal.CommitTran();
                 msg = "success";
                 return(1);
             }
             else
             {
                 dal.RollBackTran();
                 msg = "error";
                 return(0);
             }
         }
     }
     catch (System.Exception ex)
     {
         msg = ex.Message;
         return(-1);
     }
 }
コード例 #6
0
        internal static string GenerateLisense(string expDate, string serialNo, string reportNumber)
        {
            //string license = Des.EncryStrHex(expDate, reportNumber.ToString());
            //license = Des.EncryStrHex(license + reportNumber, serialNo);
            //return license;
            int    r   = new Random().Next(255, 4095);
            string key = Convert.ToString(r, 16).ToUpper().PadLeft(3, '0');

            char[] keys    = Des.EncryStrHex(key, serialNo).ToCharArray();
            char[] date    = Des.EncryStrHex(expDate, key).ToCharArray();
            char[] number  = Des.EncryStrHex(reportNumber, key).ToCharArray();
            char[] license = new char[48];

            for (int i = 0; i < 16; i++)
            {
                license[i * 3]     = date[i];
                license[i * 3 + 1] = number[i];
                license[i * 3 + 2] = keys[i];
            }
            return(new string(license));
        }
コード例 #7
0
 /// <summary>
 /// 普通用户登录
 /// </summary>
 /// <param name="userCode"></param>
 /// <param name="uPassword"></param>
 /// <param name="user"></param>
 /// <param name="msg"></param>
 /// <returns></returns>
 public static int UserSignin(string userCode, string uPassword, out User user, out string msg)
 {
     try
     {
         using (IDAL dal = DALBuilder.CreateDAL(ConfigurationManager.ConnectionStrings["SYSDB"].ConnectionString, 0))
         {
             StringBuilder sql = new StringBuilder(256);
             sql.Append("SELECT * FROM dbo.tUser WHERE UserCode=@UserCode AND UPassword=@UPassword AND Enabled=1");
             dal.OpenReader(sql.ToString(),
                            dal.CreateParameter("@UserCode", userCode),
                            dal.CreateParameter("@UPassword", Des.EncryStrHex(uPassword, userCode))
                            );
             if (dal.DataReader.Read())
             {
                 //登录成功
                 user = new User()
                 {
                     ID       = Convert.ToDecimal(dal.DataReader["ID"]),
                     UserCode = Convert.ToString(dal.DataReader["UserCode"]).TrimEnd(),
                     UserName = Convert.ToString(dal.DataReader["UserName"]).TrimEnd(),
                     IsAdmin  = Convert.ToDecimal(dal.DataReader["IsAdmin"]) == 1 ? true : false
                 };
                 msg = "登录成功";
             }
             else
             {
                 msg  = "用户名或密码错误";
                 user = null;
                 //登录失败
             }
         }
         return(user == null ? 0 : 1);
     }
     catch (Exception ex)
     {
         msg  = ex.Message;
         user = null;
         return(-1);
     }
 }
コード例 #8
0
 /// <summary>
 /// 管理员登录
 /// </summary>
 /// <param name="userCode"></param>
 /// <param name="uPassword"></param>
 /// <param name="msg"></param>
 /// <returns></returns>
 public static int AdminSignin(string userCode, string uPassword, out User user, out string msg)
 {
     try
     {
         using (IDAL dal = DALBuilder.CreateDAL(ConfigurationManager.ConnectionStrings["SYSDB"].ConnectionString, 0))
         {
             StringBuilder sql = new StringBuilder(256);
             sql.Append("select count(*) userCount from tUser where IsAdmin=1 And Enabled=1");
             dal.OpenReader(sql.ToString());
             int i = -1;
             if (dal.DataReader.Read())
             {
                 i = Convert.ToInt32(dal.DataReader["userCount"]);
             }
             dal.DataReader.Close();
             if (i == 0)
             {
                 //梅伊欧用户
                 if (userCode == "admin" && uPassword == "753951")
                 {
                     msg = "默认用户登录成功,请尽快添加管理员账户";
                     //登录成功
                     user = new User()
                     {
                         ID       = 0,
                         UserCode = "admin",
                         UserName = "******",
                         IsAdmin  = true
                     };
                     return(1);
                 }
                 else
                 {
                     msg  = "用户名或密码错误";
                     user = null;
                     return(0);
                 }
             }
             else
             {
                 sql.Clear();
                 sql.Append("SELECT * FROM tUser WHERE UserCode=@UserCode AND UPassword=@UPassword AND IsAdmin='1' AND Enabled=1 ");
                 dal.OpenReader(sql.ToString(),
                                dal.CreateParameter("@UserCode", userCode),
                                dal.CreateParameter("@UPassword", Des.EncryStrHex(uPassword, userCode))
                                );
                 if (dal.DataReader.Read())
                 {
                     //登录成功
                     msg = "登录成功";
                     //登录成功
                     user = new User()
                     {
                         ID       = Convert.ToDecimal(dal.DataReader["ID"]),
                         UserCode = Convert.ToString(dal.DataReader["UserCode"]).TrimEnd(),
                         UserName = Convert.ToString(dal.DataReader["UserName"]).TrimEnd(),
                         IsAdmin  = Convert.ToDecimal(dal.DataReader["IsAdmin"]) == 1 ? true : false
                     };
                     return(1);
                 }
                 else
                 {
                     msg  = "用户名或密码错误";
                     user = null;
                     return(0);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         msg  = ex.Message;
         user = null;
         return(-1);
     }
 }