예제 #1
0
        void CheckUserPassword(string username, string password)
        {
            try
            {
                if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
                {
                    string query = "SELECT * FROM Staff Join Roles on Staff.RoleID = Roles.RoleID WHERE Tendangnhap ='" + username + "' and Matkhau='" + password + "';";
                    if (DBAccess.IsServerConnected())
                    {
                        using (SqlCeConnection connection = new SqlCeConnection(conn))
                        {
                            using (SqlCeCommand command = new SqlCeCommand(query, connection))
                            {
                                SqlCeDataAdapter sda = new SqlCeDataAdapter(command);
                                DataTable        dt  = new DataTable();
                                sda.Fill(dt);
                                if (dt.Rows.Count >= 1)
                                {
                                    string currentUser = dt.Rows[0].Field <string>("Tendangnhap").ToString();
                                    string currentRole = dt.Rows[0].Field <string>("RoleID").ToString();


                                    LoginForm childForm  = (LoginForm)this.ParentForm;
                                    Form1     parentForm = (Form1)childForm.ParentForm;
                                    Panel     pnMenu     = parentForm.Controls["pnMenu"] as Panel;
                                    pnMenu.Visible = true;
                                    Panel pnLeft = parentForm.Controls["pnLeft"] as Panel;
                                    pnLeft.Visible = true;
                                    pnLeft.Width   = 238;
                                    Panel pnStuff      = pnLeft.Controls["pnStuff"] as Panel;
                                    Panel pnSystem     = pnLeft.Controls["pnSystem"] as Panel;
                                    Panel pnInOutStock = pnLeft.Controls["pnInOutStock"] as Panel;
                                    if (currentRole == "0000001")
                                    {
                                        pnStuff.Visible  = true;
                                        pnSystem.Visible = true;
                                        Button btnStaff = pnSystem.Controls["btnStaff"] as Button;
                                        btnStaff.Visible     = true;
                                        pnInOutStock.Visible = false;
                                    }
                                    else if (currentRole == "0000003")
                                    {
                                        pnStuff.Visible      = false;
                                        pnSystem.Visible     = false;
                                        pnInOutStock.Visible = true;
                                    }

                                    Button btnMini = pnLeft.Controls["btnMini"] as Button;
                                    btnMini.Visible = true;

                                    Label lblCurrentUser = pnMenu.Controls["lblCurrentUser"] as Label;
                                    lblCurrentUser.Text    = username;
                                    lblCurrentUser.Visible = true;
                                    Button btnMinimize = pnMenu.Controls["btnMinimize"] as Button;
                                    btnMinimize.Visible = true;
                                    Button btnMaximize = pnMenu.Controls["btnMaximize"] as Button;
                                    btnMaximize.Visible = true;
                                    Panel SidePanelLeft = pnLeft.Controls["SidePanelLeft"] as Panel;
                                    SidePanelLeft.Visible = true;
                                    Button btnSignout = pnMenu.Controls["btnSignout"] as Button;
                                    btnSignout.Visible = true;
                                    this.Visible       = false;
                                    ClearField();
                                }
                                else
                                {
                                    CommonHelper.showDialog("Sai tên đăng nhập hoặc mật khẩu.", Color.FromArgb(255, 53, 71));
                                }
                            }
                        }
                    }
                }
                else
                {
                    CommonHelper.showDialog("Mời tên đăng nhập và mật khẩu.", Color.FromArgb(255, 187, 51));
                }
            }
            catch (SqlCeException Ceex)
            {
                MessageBox.Show(Ceex.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                string query = "";

                bool   isSuccess = false;
                string ngayxong = string.Empty;
                string SonID, Ten, Mota;
                SonID = Ten = Mota = string.Empty;


                if (string.IsNullOrEmpty(txtSonID.Text))
                {
                    // SonID
                    SonID = CommonHelper.RandomString(8);
                    // Ten
                    Ten = txtName.Text;
                    // Mota
                    Mota = txtMota.Text;

                    // Created Date
                    string createDate = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss");

                    query = "INSERT INTO [Color] ([SonID],[Ten],[Mieuta],[Ngaytao],[Ngaysua])VALUES('" + SonID + "','" + Ten + "','" + Mota + "','" + createDate + "','" + createDate + "')";
                }
                else
                {
                    SonID = txtSonID.Text;
                    string modifyDate = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss");

                    // Ten
                    Ten = txtName.Text;
                    // Mota
                    Mota = txtMota.Text;

                    query = "UPDATE [Color] SET[Ten] ='" + Ten + "',[Mieuta]= '" + Mota + "',[Ngaysua]= '" + modifyDate + "' WHERE SonID ='" + SonID + "';";
                }

                if (DBAccess.IsServerConnected())
                {
                    isSuccess = DBAccess.ExecuteQuery(query);

                    if (isSuccess)
                    {
                        if (string.IsNullOrEmpty(txtSonID.Text))
                        {
                            currentPageNumber = 1;
                            ClearText();
                            // Update datalist
                            GetTotalRow();
                            GetAllData(currentPageNumber, rowPerPage);
                        }
                        else
                        {
                            currentPageNumber = 1;
                            ClearText();
                            // Update datalist
                            GetAllData(currentPageNumber, rowPerPage);
                        }
                        MessageBox.Show("Cập nhật thành công!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Đang Hoàn Thiện Hệ Thống!");
            }
        }