Exemplo n.º 1
0
        /// <summary>
        /// 判断用户登录
        /// </summary>
        /// <param name="sCode"></param>  编号
        /// <param name="sUser"></param>  用户名
        /// <param name="sPass"></param>  密码
        /// <param name="dba"></param>    数据库操作
        /// <returns></returns>           返回查询结果值
        public int loginJudge(string sCode, string sUser, string sPass, dbAccess dba)
        {
            String sLog = "Select count(1) as usercount from users where user_code ='"
                          + sCode + "' and user_detail = '" + sUser
                          + "' and user_pwd = '" + sPass + "'";

            return(Convert.ToInt32(getQueryResultBySQL(sLog)));
        }
Exemplo n.º 2
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtCode.Text.Trim() == "")
            {
                MessageBox.Show("用户编码不能为空,请输入!", "提示");
                txtCode.Focus();
                return;
            }
            ;
            if (txtUser.Text.Trim() == "")
            {
                MessageBox.Show("用户名称不能为空,请输入!", "提示");
                txtUser.Focus();
                return;
            }
            ;
            if (txtPass.Text.Trim() == "")
            {
                MessageBox.Show("用户密码不能为空,请输入!", "提示");
                txtPass.Focus();
                return;
            }
            ;
            dbAccess dA = new dbAccess();

            dA.conn.ConnectionString = GetConnectString();
            try
            {
                if (dA.OpenConn())
                {
                    if (dA.loginJudge(txtCode.Text.Trim(), txtUser.Text.Trim(), txtPass.Text.Trim(), dA) != 1)
                    {
                        MessageBox.Show("登录失败,请重新检查用户编码、用户姓名、登录密码!!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        txtCode.Focus();
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("数据库连接失败,请检查连接设置!", "提示");
                    return;
                }

                mainForm sMain = new mainForm();
                mainForm.dba = dA;
                sMain.Show();
                this.Hide();
            }
            catch (Exception e1)
            {
                MessageBox.Show(e1.Message + "\r\n请重新设置数据库连接!", "错误");
                return;
            }
            finally
            {
                if (dA.ConnState == ConnectionState.Open)
                {
                    dA.CloseConn();
                }
                dA = null;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 更新或新增记录  特殊用法
        /// </summary>
        /// <param name="sTable"></param>      表名
        /// <param name="sColValTye"></param>  字符串数组,组成方式为 “字段名,值,字段类型”
        /// <param name="sWhere"></param>      更新条件
        /// <param name="dba"></param>         数据库处理对象
        /// <returns></returns>                返回值,成功1、失败-1
        public static int UpdateOrInsert(string sTable, int iMode, List <string> sColValTye, string sWhere, dbAccess dba)
        {
            try
            {
                string   sSql = "", sSql2 = "", sTmp = "";
                string[] strTmp;
                if (iMode == 1) //新增
                {
                    for (int i = 0; i < sColValTye.Count; i++)
                    {
                        if (sColValTye[i] == null || sColValTye[i].Length == 0)
                        {
                            continue;
                        }
                        strTmp = sColValTye[i].Split(',');
                        if (strTmp.Length == 3)
                        {
                            if (strTmp[2].ToLower() == "string")
                            {
                                sSql  += strTmp[0] + ",";
                                sSql2 += "'" + strTmp[1] + "',";
                            }
                            else if (strTmp[2].ToLower() == "datetime")
                            {
                                sSql  += strTmp[0] + ",";
                                sSql2 += "cast('" + strTmp[1] + "' as datetime),";
                            }
                            else if (strTmp[2].ToLower() == "int")
                            {
                                sSql  += strTmp[0] + ",";
                                sSql2 += strTmp[1] + ",";
                            }
                        }
                        else if (strTmp.Length > 3)
                        {
                            sTmp = "";
                            for (int j = 1; j < strTmp.Length - 1; j++)
                            {
                                sTmp = sTmp + strTmp[j] + ",";
                            }
                            sTmp = sTmp.TrimEnd(',');
                            if (strTmp[strTmp.Length - 1].ToLower() == "string")
                            {
                                sSql  += strTmp[0] + ",";
                                sSql2 += "'" + sTmp + "',";
                            }
                            else if (strTmp[strTmp.Length - 1].ToLower() == "datetime")
                            {
                                sSql  += strTmp[0] + ",";
                                sSql2 += "cast('" + strTmp[1] + "' as datetime),";
                            }
                            else if (strTmp[strTmp.Length - 1].ToLower() == "int")
                            {
                                sSql  += strTmp[0] + ",";
                                sSql2 += sTmp + ",";
                            }
                        }
                    }
                    if (sSql.Length > 0)
                    {
                        sSql  = sSql.TrimEnd(',');
                        sSql2 = sSql2.TrimEnd(',');
                        sSql  = "Insert into " + sTable + "(" + sSql + ") values (" + sSql2 + ")";
                    }
                }
                else if (iMode == 2) //修改
                {
                    for (int i = 0; i < sColValTye.Count; i++)
                    {
                        if (sColValTye[i] == null || sColValTye[i].Length == 0)
                        {
                            continue;
                        }
                        strTmp = sColValTye[i].Split(',');

                        if (strTmp.Length == 3)
                        {
                            if (strTmp[2].ToLower() == "string")
                            {
                                sSql += strTmp[0] + " = '" + strTmp[1] + "',";
                            }
                            else if (strTmp[2].ToLower() == "datetime")
                            {
                                sSql += strTmp[0] + " = cast('" + strTmp[1] + "' as datetime),";
                            }
                            else if (strTmp[2].ToLower() == "int")
                            {
                                sSql += strTmp[0] + " = " + strTmp[1] + ",";
                            }
                        }
                        else if (strTmp.Length > 3)
                        {
                            sTmp = "";
                            for (int j = 1; j < strTmp.Length - 1; j++)
                            {
                                sTmp = sTmp + strTmp[j] + ",";
                            }
                            sTmp = sTmp.TrimEnd(',');
                            if (strTmp[strTmp.Length - 1].ToLower() == "string")
                            {
                                sSql += strTmp[0] + " = '" + sTmp + "',";
                            }
                            else if (strTmp[strTmp.Length - 1].ToLower() == "datetime")
                            {
                                sSql += strTmp[0] + " = cast('" + strTmp[1] + "' as datetime),";
                            }
                            else if (strTmp[strTmp.Length - 1].ToLower() == "int")
                            {
                                sSql += strTmp[0] + " = " + sTmp + ",";
                            }
                        }
                    }
                    if (sSql.Length > 0)
                    {
                        sSql = sSql.TrimEnd(',');
                        sSql = "Update " + sTable + " Set " + sSql + (sWhere.Length > 0 ? sWhere : "");
                    }
                }
                if (sSql.Length > 0 && dba.UpdateDbBySQL(sSql) != 1)
                {
                    return(-1);
                }
            }
            catch
            {
                return(-1);
            }
            return(1);
        }