Esempio n. 1
0
        private bool isLoginSuccess(string userName, string password)
        {
            bool          check = false;
            SqlCommand    sqlCmd;
            SqlDataReader sqlDr;
            string        query;

            try
            {
                MyPublic.ConnectDatabase();
                if (MyPublic.conn.State == ConnectionState.Open)
                {
                    query  = "SELECT VT_MA FROM NGUOIDUNG WHERE ND_USERNAME=@USERNAME AND ND_PASSWORD=@PASSWORD";
                    sqlCmd = new SqlCommand(query, MyPublic.conn);
                    sqlCmd.Parameters.AddWithValue("@USERNAME", userName);
                    sqlCmd.Parameters.AddWithValue("@PASSWORD", password);
                    sqlDr = sqlCmd.ExecuteReader();
                    if (sqlDr.HasRows)
                    {
                        MyPublic.USERNAME = userName;
                        sqlDr.Read();
                        MyPublic.PURVIEW = sqlDr.GetString(0);
                        sqlDr.Close();
                        check = true;
                        MyPublic.conn.Close();
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Connect failed! " + e.Message);
            }
            return(check);
        }
        public DataTable Show_YC()
        {
            MyPublic.ConnectDatabase();
            string         query = "SELECT LSC.LSC_TEN AS TYPE,YC.YC_TENSUCO as NAME,YC.YC_NGAY AS DATE,YC.YC_THONGTINKEMTHEO AS CONTENT ,TT.TT_TEN AS STATE,XL.THOI_GIAN_HOAN_THANH AS FINISH FROM YEUCAU as YC inner join LOAI_SUCO as LSC on YC.LSC_MA = LSC.LSC_MA inner join TRANGTHAI as TT on YC.TT_MA = TT.TT_MA inner join XULY_SUCO as XL on YC.YC_STT = XL.YC_STT WHERE ND_USERNAME='******'";
            SqlCommand     sqlCm = new SqlCommand(query, MyPublic.conn);
            SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCm);
            DataTable      dt    = new DataTable();

            sqlDa.Fill(dt);
            MyPublic.conn.Close();
            sqlDa.Dispose();
            return(dt);
        }
        private void changeAvatar(string imageLocation)
        {
            MyPublic.ConnectDatabase();
            SqlCommand sqlCmd;
            string     newPath = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName, "HelpdeskSystem") + "\\Avatar\\" + MyPublic.USERNAME + ".jpg";

            File.Copy(imageLocation, newPath, true);
            string query = "UPDATE NHANVIEN SET NV_AVATAR=@avatar WHERE ND_USERNAME=@username";

            sqlCmd = new SqlCommand(query, MyPublic.conn);
            sqlCmd.Parameters.AddWithValue("@avatar", newPath);
            sqlCmd.Parameters.AddWithValue("@username", MyPublic.USERNAME);
            sqlCmd.ExecuteNonQuery();
            picPhotoProfile.ImageLocation = newPath;
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                MyPublic.ConnectDatabase();
                if (MyPublic.conn.State == ConnectionState.Open)
                {
                    object a     = cbProlem.SelectedValue;
                    string query = "INSERT INTO YEUCAU (ND_USERNAME,LSC_MA,TT_MA,YC_NGAY,YC_THONGTINKEMTHEO,YC_TENSUCO) VALUES(@username, @lsc_ma,@tt_ma, @date, @yc_tt,@ten_yc)" + "SELECT SCOPE_IDENTITY();";
                    using (SqlCommand cmd = new SqlCommand(query, MyPublic.conn))
                    {
                        cmd.Parameters.AddWithValue("@username", MyPublic.USERNAME);
                        cmd.Parameters.AddWithValue("@lsc_ma", cbProlem.SelectedValue);
                        cmd.Parameters.AddWithValue("@tt_ma", "TT001");
                        cmd.Parameters.AddWithValue("@date", DateTime.Now.ToString("yyyy-MM-dd"));
                        cmd.Parameters.AddWithValue("@yc_tt", txtDescription.Text);
                        cmd.Parameters.AddWithValue("@ten_yc", txtDescription.Text);
                        SqlDataReader reader = cmd.ExecuteReader();
                        reader.Read();
                        dgvYC.DataSource = Show_YC();
                        if (url != null)
                        {
                            MyPublic.ConnectDatabase();

                            for (int i = 0; i < url.Length; i++)
                            {
                                var    insertedId = reader[0].ToString();
                                string newPath    = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName, "HelpdeskSystem") + "\\Problem\\" + MyPublic.USERNAME + "YC" + insertedId + i + ".jpg";
                                File.Copy(url[i], newPath, true);
                                string     sql    = "INSERT INTO HINHANH(YC_STT,HA_URL) VALUES (@yc_stt,@URL);";
                                SqlCommand sqlCmd = new SqlCommand(sql, MyPublic.conn);
                                sqlCmd.Parameters.AddWithValue("@yc_stt", insertedId);
                                sqlCmd.Parameters.AddWithValue("@URL", url[i]);
                                sqlCmd.ExecuteNonQuery();
                            }
                        }
                    }
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message, "Connect database failed!"); }

            MessageBox.Show("Your request has been sent to Admin");
            dgvYC.ReadOnly = true;
            ResetFields(false);
            cbProlem.Enabled       = false;
            txtDescription.Enabled = false;
            btnUpload.Enabled      = false;
        }
        //Profile
        private void Load_Profile()
        {
            MyPublic.ConnectDatabase();
            SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM NHANVIEN WHERE ND_USERNAME='******'", MyPublic.conn);
            DataTable      dt  = new DataTable();

            sda.Fill(dt);
            txtPurview.Text = MyPublic.PURVIEW;
            txtName.Text    = dt.Rows[0][3].ToString();
            txtPhone.Text   = dt.Rows[0][4].ToString();
            txtEmail.Text   = dt.Rows[0][5].ToString();
            if (dt.Rows[0][6].ToString() != null)
            {
                imageAvatar.ImageLocation     = dt.Rows[0][6].ToString();
                picPhotoProfile.ImageLocation = dt.Rows[0][6].ToString();
            }
        }
Esempio n. 6
0
        private void frmTechnician_Load(object sender, EventArgs e)
        {
            MyPublic.ConnectDatabase();
            SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM KYTHUATVIEN WHERE ND_USERNAME='******'", MyPublic.conn);
            DataTable      dt      = new DataTable();

            adapter.Fill(dt);
            txtPurview.Text = MyPublic.PURVIEW;
            txtName.Text    = dt.Rows[0][3].ToString();
            txtPhone.Text   = dt.Rows[0][4].ToString();
            txtEmail.Text   = dt.Rows[0][5].ToString();
            if (dt.Rows[0][6].ToString() != null)
            {
                imgAvatar.ImageLocation       = dt.Rows[0][6].ToString();
                imgAvatarHeader.ImageLocation = dt.Rows[0][6].ToString();
            }
            dgvFaq.DataSource   = showFaq();
            dgvOffer.DataSource = showOffer();
            dgvTask.DataSource  = showTask();
        }
 void Load_cbProlem()
 {
     try
     {
         string Sql = "SELECT * from LOAI_SUCO";
         MyPublic.ConnectDatabase();
         SqlCommand cmd = new SqlCommand(Sql, MyPublic.conn);
         MyPublic.OpenData(Sql, dsSuCo, "LOAI_SUCO");
         dvSuco.Table           = dsSuCo.Tables["LOAI_SUCO"];
         cbProlem.DisplayMember = "LSC_TEN";
         cbProlem.ValueMember   = "LSC_MA";
         cbProlem.DataSource    = dvSuco;
         SqlDataReader DR = null;
         if (MyPublic.conn.State == ConnectionState.Closed)
         {
             MyPublic.conn.Open();
             DR = cmd.ExecuteReader();
         }
     }
     catch (Exception)
     {
         MessageBox.Show("Connect database failed! ");
     }
 }