private void QuanLyLogin_Load(object sender, EventArgs e) { Nhanvien nv = new Nhanvien(); SqlCommand command = new SqlCommand("SELECT * FROM TTNV as a, Login as b WHERE a.IdNhanVien = b.Id "); dataGridView1.ReadOnly = true; dataGridView1.DataSource = nv.getLaoCong(command); }
private void Button1_Click(object sender, EventArgs e) { SqlCommand command = new SqlCommand("SELECT * FROM ChiTietPhong"); dataGridView1.ReadOnly = true; dataGridView1.RowTemplate.Height = 20; dataGridView1.DataSource = NhanVien.getLaoCong(command); dataGridView1.AllowUserToAddRows = false; }
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); } }
private void ButtonRefresh_Click(object sender, EventArgs e) { string cv = "LaoCong "; SqlCommand command = new SqlCommand("Select * from TTNV as a,Login as b where b.ChucVu like '" + cv + "%' and a.IdNhanVien = b.Id"); dataGridViewManagerStudent.ReadOnly = true; DataGridViewImageColumn piccol = new DataGridViewImageColumn(); dataGridViewManagerStudent.RowTemplate.Height = 40; dataGridViewManagerStudent.DataSource = NhanVien.getLaoCong(command); piccol = (DataGridViewImageColumn)dataGridViewManagerStudent.Columns[7]; piccol.ImageLayout = DataGridViewImageCellLayout.Stretch; dataGridViewManagerStudent.AllowUserToAddRows = false; }
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); } }
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) { } }