コード例 #1
0
ファイル: Phong.cs プロジェクト: nguyenhuahuy24/doan1
        public bool updateTraPhong(string maP, int mkphong)
        {
            My_DB      mydb    = new My_DB();
            SqlCommand command = new SqlCommand("UPDATE TTPhong SET TrangThai = @TP, MKPhong = @MK where MaPhong = @mp", mydb.GetConnection);

            command.Parameters.Add("@TP", SqlDbType.Int).Value     = 1;
            command.Parameters.Add("@mp", SqlDbType.VarChar).Value = maP;
            command.Parameters.Add("@MK", SqlDbType.Int).Value     = mkphong;

            mydb.openConnection();
            if ((command.ExecuteNonQuery() == 1))
            {
                mydb.closeConnection();
                return(true);
            }
            else
            {
                mydb.closeConnection();
                return(false);
            }
        }
コード例 #2
0
ファイル: LeTan.cs プロジェクト: nguyenhuahuy24/doan1
        private void ButtonBD_Click(object sender, EventArgs e)
        {
            int            ca;
            DemGio         dg     = new DemGio();
            My_DB          mydb   = new My_DB();
            int            id     = Global.GlobalUserId;
            string         chucvu = "len tan";
            DateTime       GioBD  = DateTime.Now;
            string         HT;
            SqlDataAdapter adapter = new SqlDataAdapter();
            DataTable      table   = new DataTable();
            SqlCommand     command = new SqlCommand("Select * From BaoCaoNgay WHERE @ID= Id", mydb.GetConnection);

            command.Parameters.Add("@ID", SqlDbType.VarChar).Value = id;
            adapter.SelectCommand = command;
            adapter.Fill(table);
            SqlCommand command3 = new SqlCommand("Select Fname From TTNV WHERE IdNhanVien =" + id);
            DataTable  table3   = nhanvien.getLaoCong(command3);

            HT = (string)table3.Rows[0]["Fname"];

            SqlCommand command2 = new SqlCommand("Select CaLamViec From TTNV WHERE IdNhanVien =" + id);
            DataTable  table2   = nhanvien.getLaoCong(command2);

            ca = (int)table2.Rows[0]["CaLamViec"];
            if ((table.Rows.Count) > 0)
            {
                MessageBox.Show("Đã Bắt Đầu Rồi Nhé", " Start Agint", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (dg.inserBaoCaoNgay(id, HT, GioBD, chucvu, ca))
            {
                dg.inserBaoCaoThang(id, GioBD, chucvu, ca);
                MessageBox.Show("Bắt Đầu Làm Việc", " Start", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Bị Lỗi", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #3
0
 private void ButtonAdd_Click(object sender, EventArgs e)
 {
     if ((TextboxID.Text.Trim() == ""))
     {
         MessageBox.Show("Enter ID To ADD", " Thêm Lao CÔng", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
     else
     {
         My_DB    db       = new My_DB();
         Nhanvien nhanvien = new Nhanvien();
         int      ca       = (int)ComboBoxCaDK.SelectedValue;
         string   CV       = "LaoCong";
         int      id       = Convert.ToInt32(TextboxID.Text);
         string   fname    = TextboxFirstName.Text;
         string   lname    = TextboxLastName.Text;
         DateTime bdate    = dateTimePickerLetan.Value;
         string   phone    = TextboxPhone.Text;
         string   adrs     = TextboxAddress.Text;
         string   UserName = TextBoxUSERNAME.Text;
         string   Password = TextBoxPASSWORD.Text;
         string   LBGT     = "Male";
         if (RadioButtonFemale.Checked)
         {
             LBGT = "Female";
         }
         MemoryStream   pic       = new MemoryStream();
         int            born_year = dateTimePickerLetan.Value.Year;
         int            this_year = DateTime.Now.Year;
         SqlDataAdapter adapter   = new SqlDataAdapter();
         DataTable      table     = new DataTable();
         SqlCommand     command   = new SqlCommand("Select * From TTNV WHERE @ID= IdNhanVien", db.GetConnection);
         command.Parameters.Add("@ID", SqlDbType.VarChar).Value = TextboxID.Text;
         adapter.SelectCommand = command;
         adapter.Fill(table);
         if ((table.Rows.Count) > 0)
         {
             MessageBox.Show("trung id", " nhap lai", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
         else if (((this_year - born_year) < 18) || ((this_year - born_year) > 50))
         {
             MessageBox.Show("Tuổi lao công từ 18 -> 50", " Birth Date error", MessageBoxButtons.OK, MessageBoxIcon.Error);;
         }
         else if (verif1())
         {
             pictureBox1.Image.Save(pic, pictureBox1.Image.RawFormat);
             if (nhanvien.insertNhanVien(id, fname, lname, bdate, LBGT, phone, adrs, pic, ca))
             {
                 if (nhanvien.insertLogin(UserName, Password, CV, id))
                 {
                     MessageBox.Show("Thành Công", " Thêm nhân viên", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 }
             }
             else
             {
                 MessageBox.Show("Thất bại", "Thêm nhân viên", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         else
         {
             MessageBox.Show("Thiếu thông tin", " Thêm nhân viên", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
     }
 }
コード例 #4
0
ファイル: Form1.cs プロジェクト: nguyenhuahuy24/doan1
        private void ButtonLogin_Click(object sender, EventArgs e)
        {
            Nhanvien nv = new Nhanvien();
            My_DB    db = new My_DB();

            db.openConnection();
            try
            {
                SqlCommand command = new SqlCommand("SELECT * FROM Login WHERE UserName = @User AND PassWord = @Pass ", db.GetConnection);
                command.Parameters.Add("@User", SqlDbType.VarChar).Value = TextBoxUser.Text;
                command.Parameters.Add("@Pass", SqlDbType.VarChar).Value = TextBoxPassword.Text;

                SqlDataAdapter adapter = new SqlDataAdapter(command);
                DataTable      table   = new DataTable();
                adapter.SelectCommand = command;
                adapter.Fill(table);
                SqlCommand command2 = new SqlCommand("Select ChucVu From Login where UserName like '" + TextBoxUser.Text + "%'");
                DataTable  table2   = nv.getLaoCong(command2);
                string     ChucVu   = (string)table2.Rows[0]["ChucVu"];
                SqlCommand command3 = new SqlCommand("Select Id From Login where UserName like '" + TextBoxUser.Text + "%'");
                DataTable  table3   = nv.getLaoCong(command3);
                int        Id       = (int)table3.Rows[0]["Id"];
                if (ChucVu == "LaoCong   ")
                {
                    if (table.Rows.Count > 0)
                    {
                        Global.SetGlobalUserId(Id);
                        LaoCong str = new LaoCong();
                        this.Hide();
                        str.ShowDialog();
                        this.Show();
                    }
                    else
                    {
                        MessageBox.Show("Invalid Username or Password");
                    }
                }
                else if (ChucVu == "LeTan     ")
                {
                    if (table.Rows.Count > 0)
                    {
                        Global.SetGlobalUserId(Id);
                        LeTan str = new LeTan();
                        this.Hide();
                        str.ShowDialog();
                        this.Show();
                    }
                    else
                    {
                        MessageBox.Show("Invalid Username or Password");
                    }
                }
                else if (ChucVu == "QuanLy    ")
                {
                    if (table.Rows.Count > 0)
                    {
                        Global.SetGlobalUserId(Id);
                        Quan_ly str = new Quan_ly();
                        this.Hide();
                        str.ShowDialog();
                        this.Show();
                    }
                    else
                    {
                        MessageBox.Show("Invalid Username or Password");
                    }
                }
                else
                {
                    MessageBox.Show("Invalid Username or Password");
                }
            }
            catch (Exception e1)
            {
                MessageBox.Show("Invalid Username or Password ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #5
0
        private void ButtonKT_Click_1(object sender, EventArgs e)
        {
            int id = Global.GlobalUserId;
            My_DB mydb = new My_DB();
            DemGio dg = new DemGio();
            DateTime GioBD;
            string fname;
            int ca;
            string HoTen;
            double luong = 0;
            Nhanvien nhanvien = new Nhanvien();
            DateTime gioKT = DateTime.Now;
            int tonggiolam;
            int tongphutlam;


            SqlDataAdapter adapter = new SqlDataAdapter();
            DataTable table = new DataTable();
            SqlCommand command = new SqlCommand("Select * From BaoCaoNgay WHERE @ID= Id", mydb.GetConnection);
            command.Parameters.Add("@ID", SqlDbType.VarChar).Value = id; ;
            adapter.SelectCommand = command;
            adapter.Fill(table);

            SqlCommand command4 = new SqlCommand("Select CaLamViec From TTNV WHERE IdNhanVien =" + id);
            DataTable table4 = nhanvien.getLaoCong(command4);
            ca = (int)table4.Rows[0]["CaLamViec"];

            SqlCommand command1 = new SqlCommand("Select Fname From TTNV WHERE IdNhanVien =" + id);
            DataTable table1 = nhanvien.getLaoCong(command1);
            fname = table1.Rows[0]["Fname"].ToString();

            

            SqlCommand command2 = new SqlCommand("Select GioBD From BaoCaoNgay WHERE Id =" + id);
            DataTable table2 = nhanvien.getLaoCong(command2);
            GioBD = (DateTime)table2.Rows[0]["GioBD"];
            try
            {
                if (table.Rows.Count > 0)
                {
                    if (gioKT.Hour < GioBD.Hour)
                    {
                        if (gioKT.Minute < GioBD.Minute)
                        {
                            tonggiolam = gioKT.Hour + 24 - GioBD.Hour - 1;
                            tongphutlam = gioKT.Minute + 60 - GioBD.Minute;
                        }
                        else
                        {
                            tonggiolam = gioKT.Hour + 24 - GioBD.Hour;
                            tongphutlam = gioKT.Minute - GioBD.Minute;

                        }
                    }
                    else
                    {
                        if (gioKT.Minute < GioBD.Minute)
                        {
                            tonggiolam = gioKT.Hour - GioBD.Hour - 1;
                            tongphutlam = gioKT.Minute + 60 - GioBD.Minute;
                        }
                        else
                        {
                            tonggiolam = gioKT.Hour - GioBD.Hour;
                            tongphutlam = gioKT.Minute - GioBD.Minute;

                        }
                    }
                    if (tonggiolam >= 8)
                    {
                        if (tonggiolam < 9)
                        {
                            luong = Math.Round(8 * 40000 + ((float)tongphutlam / 60) * 0, 0);

                        }
                        else if (tonggiolam >= 9)
                        {
                            luong = Math.Round(tonggiolam * 400000 + ((float)tongphutlam / 60) * 0, 0);


                        }
                    }
                    else
                    {
                        if (tonggiolam == 7 && tongphutlam >= 45)
                        {
                            luong = Math.Round(8 * 40000 + ((float)tongphutlam / 60) * 0, 0);
                        }
                        else
                        {
                            luong = Math.Round(8 * 40000 + ((float)tongphutlam / 60) * 0 - (8 - tonggiolam) * 80000, 0);
                        }
                    }
                    try
                    {
                        if (dg.updateBaoCaoNgay(id, fname, gioKT, tonggiolam, tongphutlam, luong))
                        {
                            dg.deleteBaoCao(id);
                            dg.updateBaoCaoThang(id, fname, gioKT, tonggiolam, tongphutlam, luong);
                            MessageBox.Show("Kết thúc giờ làm", " End", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            Close();
                        }
                        else
                        {
                            MessageBox.Show("Chưa bắt đầu", "Error Id", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    catch (Exception exp)
                    {
                        MessageBox.Show("Chưa Bắt đầu công việc", "Check-out", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }

                else
                {
                    MessageBox.Show("Chưa Bắt đầu công việc", "Check-out", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                }
            }
            catch(Exception exp)
            {

            }
        }