Exemplo n.º 1
0
        bool checkUser(string uid, string pass, ref string group_list)
        {
            string strCmd = "";
            string _pass  = mahoa.mahoa(pass);

            bool b = false;

            SqlDataAdapter adapter = new SqlDataAdapter();

            strCmd = "select group_list,tennv from _User where user_id='" + uid + "' and user_pass='******'";
            conn.Open();
            myCommand = new SqlCommand(strCmd, conn);
            //myCommand.CommandText = "select group_list from _User where user_id='" + uid + "' and user_pass='******'";
            reader = myCommand.ExecuteReader();
            //adapter.SelectCommand = new SqlCommand(strCmd, frmMain.conn);
            //reader = adapter.SelectCommand.ExecuteReader();


            //olecom.CommandText= "select group_list from _User where user_id='"+uid+"' and user_pass='******'";
            //reader=olecom.ExecuteReader();

            if (reader.Read())
            {
                group_list = reader.GetString(0);
                b          = true;
                hoten      = reader.GetString(1);
            }

            reader.Close();
            conn.Close();
            return(b);
        }
Exemplo n.º 2
0
        private void layDanhsach()
        {
            dgvDanhsach.Refresh();
            DataTable  dtDanhsach = new DataTable();
            DataColumn col        = null;

            col = new DataColumn("STT", typeof(int));
            dtDanhsach.Columns.Add(col);
            col = new DataColumn("Mã CN", typeof(string));
            dtDanhsach.Columns.Add(col);
            col = new DataColumn("Tên đăng nhập", typeof(string));
            dtDanhsach.Columns.Add(col);
            col = new DataColumn("Mật khẩu", typeof(string));
            dtDanhsach.Columns.Add(col);
            col = new DataColumn("Họ tên", typeof(string));
            dtDanhsach.Columns.Add(col);
            col = new DataColumn("Nhóm người dùng", typeof(string));
            dtDanhsach.Columns.Add(col);
            col = new DataColumn("Phòng ban", typeof(string));
            dtDanhsach.Columns.Add(col);
            col = new DataColumn("Chức vụ", typeof(string));
            dtDanhsach.Columns.Add(col);
            col = new DataColumn("Ghi chú", typeof(string));
            dtDanhsach.Columns.Add(col);

            //strCmd = "Select nv.*, pb.TenPB from _USER as nv left join PHONGBAN as pb on (nv.MACN=pb.MACN and nv.MAPB=pb.MAPB) ";
            //strCmd += " Where nv.MACN='" + cbbMaCN.SelectedValue.ToString() + "' and nv.maPB='" + arrPhong[cbbPhong.Items.IndexOf(cbbPhong.Text.Trim())].ToString() + "' ";
            strCmd  = "Select nv.*, pb.TenPB from _USER as nv left join PHONGBAN as pb on (nv.MACN=pb.MACN and nv.MAPB=pb.MAPB) ";
            strCmd += " Where nv.MACN='" + cbbMaCN.SelectedValue.ToString() + "' and nv.maPB='" + cbbPhong.SelectedValue.ToString() + "' ";

            SqlDataAdapter adapter = new SqlDataAdapter();

            try
            {
                if (frmMain.conn.State == ConnectionState.Open)
                {
                    frmMain.conn.Close();
                }
                frmMain.conn.Open();
                adapter.SelectCommand = new SqlCommand(strCmd, frmMain.conn);
                adapter.SelectCommand.ExecuteReader();
                frmMain.conn.Close();
            }
            catch
            {
                if (frmMain.conn.State == ConnectionState.Open)
                {
                    frmMain.conn.Close();
                }
            }

            DataSet ds = new DataSet();

            adapter.Fill(ds);

            dtResult = ds.Tables[0];

            int iRows = dtResult.Rows.Count;

            for (int i = 0; i < iRows; i++)
            {
                try
                {
                    DataRow row = dtDanhsach.NewRow();
                    row[0] = i + 1;
                    row[1] = dtResult.Rows[i]["MaCN"].ToString();
                    row[2] = dtResult.Rows[i]["User_ID"].ToString();

                    string pass = dtResult.Rows[i]["User_Pass"].ToString();
                    pass   = mahoa.mahoa(pass);
                    row[3] = pass;

                    row[4] = dtResult.Rows[i]["TenNV"].ToString();

                    String   groupList = dtResult.Rows[i]["group_list"].ToString();
                    string[] groupID   = groupList.Split(',');
                    string   groupName = "";
                    foreach (string id in groupID)
                    {
                        string str = "select * from _group Where Group_ID='" + id + "' ";

                        SqlDataAdapter adapter1 = new SqlDataAdapter();
                        try
                        {
                            if (frmMain.conn.State == ConnectionState.Open)
                            {
                                frmMain.conn.Close();
                            }
                            frmMain.conn.Open();
                            adapter1.SelectCommand = new SqlCommand(str, frmMain.conn);
                            adapter1.SelectCommand.ExecuteReader();
                            frmMain.conn.Close();
                        }
                        catch
                        {
                            if (frmMain.conn.State == ConnectionState.Open)
                            {
                                frmMain.conn.Close();
                            }
                        }
                        DataSet ds1 = new DataSet();
                        adapter1.Fill(ds1);
                        DataTable dtResult1 = ds1.Tables[0];

                        try
                        {
                            if (groupName == "")
                            {
                                groupName = dtResult1.Rows[0]["group_Name"].ToString();
                            }
                            else
                            {
                                groupName += "," + dtResult1.Rows[0]["group_Name"].ToString();
                            }
                        }
                        catch { }
                    }
                    row[5] = groupName;
                    row[6] = dtResult.Rows[i]["TenPB"].ToString();
                    row[7] = dtResult.Rows[i]["Chucvu"].ToString();
                    row[8] = dtResult.Rows[i]["Ghichu"].ToString();
                    dtDanhsach.Rows.Add(row);
                }
                catch
                {
                    if (frmMain.conn.State == ConnectionState.Open)
                    {
                        frmMain.conn.Close();
                    }
                }
            }
            dgvDanhsach.DataSource = dtDanhsach;
            dgvDanhsach.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgvDanhsach.Columns[0].DefaultCellStyle.Alignment   = DataGridViewContentAlignment.MiddleRight;
            dgvDanhsach.Columns[0].Width   = 50;
            dgvDanhsach.Columns[1].Width   = 80;
            dgvDanhsach.Columns[2].Width   = 150;
            dgvDanhsach.Columns[3].Width   = 120;
            dgvDanhsach.Columns[3].Visible = false;
            dgvDanhsach.Columns[4].Width   = 200;
            dgvDanhsach.Columns[5].Width   = 300;
            dgvDanhsach.Columns[6].Width   = 200;
            dgvDanhsach.Columns[7].Width   = 150;
            dgvDanhsach.Columns[8].Width   = 200;
        }
Exemplo n.º 3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtPass_old.Text == "")
            {
                MessageBox.Show("Chưa nhập mật khẩu cũ.");
                txtPass_old.Focus();
                return;
            }
            else if (txtPass_new.Text == "")
            {
                MessageBox.Show("Chưa nhập mật khẩu mới.");
                txtPass_new.Focus();
                return;
            }
            else if (txtConfirm.Text == "")
            {
                MessageBox.Show("Chưa xác nhận mật khẩu mới.");
                txtConfirm.Focus();
                return;
            }

            if (txtPass_old.Text != frmDangnhap.matkhau)
            {
                MessageBox.Show("Mật khẩu cũ không đúng.");
                txtPass_old.Focus();
                return;
            }

            if (txtConfirm.Text != txtConfirm.Text)
            {
                MessageBox.Show("Mật khẩu mới không giống nhau.");
                txtPass_new.Text = "";
                txtConfirm.Text  = "";
                txtPass_new.Focus();
                return;
            }

            string pass_new     = txtPass_new.Text;
            string pass_confirm = txtConfirm.Text;

            strCmd = "SELECT * FROM _User WHERE User_ID='" + frmDangnhap.UserID + "' ";

            SqlDataAdapter adapter = new SqlDataAdapter();

            try
            {
                if (frmMain.conn.State == ConnectionState.Open)
                {
                    frmMain.conn.Close();
                }
                frmMain.conn.Open();
                adapter.SelectCommand = new SqlCommand(strCmd, frmMain.conn);
                adapter.SelectCommand.ExecuteNonQuery();
                frmMain.conn.Close();
            }
            catch
            {
                if (frmMain.conn.State == ConnectionState.Open)
                {
                    frmMain.conn.Close();
                }
            }

            DataSet ds = new DataSet();

            adapter.Fill(ds);
            dtResult = ds.Tables[0];

            if (dtResult.Rows.Count > 0)
            {
                pass_new     = mahoa.mahoa(pass_new);
                pass_confirm = mahoa.mahoa(pass_confirm);

                strCmd = "Update _User Set User_pass='******' Where User_ID='" + frmDangnhap.UserID + "' ";

                try
                {
                    if (frmMain.conn.State == ConnectionState.Open)
                    {
                        frmMain.conn.Close();
                    }
                    frmMain.conn.Open();
                    adapter.UpdateCommand = new SqlCommand(strCmd, frmMain.conn);
                    adapter.UpdateCommand.ExecuteNonQuery();
                    frmMain.conn.Close();
                    MessageBox.Show("Đã thay đổi.", "Thông báo");
                    txtPass_old.Text = "";
                    txtPass_new.Text = "";
                    txtConfirm.Text  = "";
                }
                catch
                {
                    if (frmMain.conn.State == ConnectionState.Open)
                    {
                        frmMain.conn.Close();
                    }
                }
            }
        }