Exemplo n.º 1
0
        public static ResultEN Delete_Type(EquiptmentEN en)
        {
            ResultEN   res    = new ResultEN();
            SqlCommand sqlCmd = new SqlCommand();

            sqlCmd.CommandText = "Delete From " + tb_name_master + " WHERE ID = " + en.ID;
            sqlCmd.CommandType = CommandType.Text;

            res.result = ClassMain.ExecuteComand(sqlCmd);

            return(res);
        }
Exemplo n.º 2
0
    public static ResultEN CreateUser(string username, string password, int role_id, int branch_id)
    {
        ResultEN res = new ResultEN();

        username = username.Trim().ToLower();
        SqlCommand sqlCmd = new SqlCommand();

        sqlCmd.CommandText = "select username from Users where username ='******'";

        // check duplicate username
        int count = ClassMain.intExecuteComand(sqlCmd);

        if (count > 0)
        {
            res.result      = false;
            res.returnValue = "Duplicate Username";
            return(res);
        }


        string strEnCrypt = SHA256.EcryptPassword(password, salt);

        StringBuilder Sql = new StringBuilder();

        Sql.AppendLine("INSERT INTO [dbo].[Users]");
        Sql.AppendLine("           ([Username]");
        Sql.AppendLine("           ,[Password]");
        Sql.AppendLine("           ,[Role_id]");
        Sql.AppendLine("           ,[CreatedDate]");
        Sql.AppendLine("           ,[CreatedBy]");

        Sql.AppendLine(")");
        Sql.AppendLine("     VALUES");
        Sql.AppendLine("           ('" + username + "'");
        Sql.AppendLine("           ,'" + strEnCrypt + "'");
        Sql.AppendLine("           ," + role_id);
        Sql.AppendLine("           ,getdate()");
        Sql.AppendLine("           ,'" + HttpContext.Current.User.Identity.Name + "')");

        sqlCmd             = new SqlCommand();
        sqlCmd.CommandText = Sql.ToString();
        res.result         = ClassMain.ExecuteComand(sqlCmd);
        if (res.result)
        {
            res.returnValue = "Create Username Success.";
        }

        return(res);
    }
Exemplo n.º 3
0
        public static ResultEN Delete_Type(EquipmentTypeEN en)
        {
            ResultEN   res    = new ResultEN();
            SqlCommand sqlCmd = new SqlCommand();

            sqlCmd.CommandText = "Delete From " + tb_name_type + " WHERE ParentID = " + en.ID;
            sqlCmd.CommandType = CommandType.Text;

            // delete child
            res.result = ClassMain.ExecuteComand(sqlCmd);


            // delete parent
            sqlCmd.CommandText = "Delete From " + tb_name_type + " WHERE ID = " + en.ID;
            res.result         = ClassMain.ExecuteComand(sqlCmd);

            return(res);
        }
Exemplo n.º 4
0
    public static ResultEN ChangeUsername(int id, string username_old, string username_new, string password)
    {
        ResultEN   res    = new ResultEN();
        SqlCommand sqlCmd = new SqlCommand();

        username_old       = username_old.Trim().ToLower();
        username_new       = username_new.Trim().ToLower();
        sqlCmd.CommandText = "select username from Users where username ='******' and username <> '" + username_old + "'";

        // check duplicate username not self
        int count = ClassMain.intExecuteComand(sqlCmd);

        if (count > 0)
        {
            res.result      = false;
            res.returnValue = "Duplicate Username";
            return(res);
        }

        string strEnCrypt = SHA256.EcryptPassword(password, salt);

        sqlCmd = new SqlCommand();
        StringBuilder Sql = new StringBuilder();

        Sql.AppendLine("UPDATE [dbo].[Users]");
        Sql.AppendLine("   SET [Username] = '" + username_new + "'");
        Sql.AppendLine("      ,[Password] = '" + strEnCrypt + "'");
        Sql.AppendLine("      ,[UpdDate] = getdate()");
        Sql.AppendLine("      ,[UpdTime] = getdate()");
        Sql.AppendLine("      ,[UpdBy] = '" + HttpContext.Current.User.Identity.Name + "'");
        Sql.AppendLine(" WHERE id = " + id);
        sqlCmd.CommandText = sqlCmd.ToString();

        res.result = ClassMain.ExecuteComand(sqlCmd);
        return(res);
    }