// KỶ LUẬT. public bool Update_KyLuat(KyLuat kyLuat) { SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "SP_Update_KYLUAT"; cmd.Parameters.Add("@MADV", SqlDbType.NVarChar).Value = kyLuat.MaDV; cmd.Parameters.Add("@THOIGIAN", SqlDbType.Date).Value = kyLuat.ThoiGian; cmd.Parameters.Add("@LYDO", SqlDbType.NVarChar).Value = kyLuat.LyDo; cmd.Parameters.Add("@HINHTHUC", SqlDbType.NVarChar).Value = kyLuat.HinhThuc; cmd.Parameters.Add("@CAPQUYETDINH", SqlDbType.NVarChar).Value = kyLuat.CapQD; cmd.Connection = _conn; try { _conn.Open(); cmd.ExecuteNonQuery(); return(true); } catch { return(false); } finally { _conn.Close(); } }
public Boolean SuaKyLuat(KyLuat pb) { SqlConnection conn = getConnection(); conn.Open(); try { string sqlSua = "DECLARE @dem int select @dem = COUNT(MaNV) FROM KyLuat WHERE MaNV = @MaNV " + "IF @dem != 0 UPDATE KyLuat SET TienPhat = @TienPhat , MaKyLuat = @MaKyLuat , NgayKyLuat = @NgayKyLuat , LyDo = @LyDo WHERE MaNV = @MaNV else raiserror('',16,1)"; SqlCommand cmd = new SqlCommand(sqlSua, conn); cmd.Parameters.AddWithValue("MaNV", pb.MaNV); cmd.Parameters.AddWithValue("TienPhat", pb.TienPhat); cmd.Parameters.AddWithValue("MaKyLuat", pb.MaKyLuat); cmd.Parameters.AddWithValue("NgayKyLuat", pb.NgayKyLuat); cmd.Parameters.AddWithValue("LyDo", pb.LyDo); cmd.ExecuteNonQuery(); } catch (Exception) { return(false); } finally { conn.Close(); } return(true); }
public bool Update(KyLuat kyLuat) { try { string query = "SELECT * FROM KyLuat"; SqlDataAdapter dataAdapter = new SqlDataAdapter(query, connection); table = GetData(); table.PrimaryKey = new DataColumn[] { table.Columns[0] }; DataRow row = table.Rows.Find(kyLuat.KyLuatId); if (row != null) { row["DoiTuongId"] = kyLuat.DoiTuongId; row["tenKyLuat"] = kyLuat.TenKyLuat; row["noiDung"] = kyLuat.NoiDung; row["ngay"] = kyLuat.Ngay; row["ghiChu"] = kyLuat.GhiChu; } SqlCommandBuilder sqlCommandBuilder = new SqlCommandBuilder(dataAdapter); dataAdapter.Update(table); return(true); } catch { return(false); } }
public Boolean ThemKyLuat(KyLuat pb) { SqlConnection conn = getConnection(); conn.Open(); try { string sqlThem = "INSERT INTO KyLuat VALUES(@MaPB ,@MaNV , @HoTen , @TienPhat , @MaKyLuat , @NgayKyLuat , @LyDo)"; SqlCommand cmd = new SqlCommand(sqlThem, conn); cmd.Parameters.AddWithValue("MaPB", pb.MaPB); cmd.Parameters.AddWithValue("MaNV", pb.MaNV); cmd.Parameters.AddWithValue("HoTen", pb.HoTen); cmd.Parameters.AddWithValue("TienPhat", pb.TienPhat); cmd.Parameters.AddWithValue("MaKyLuat", pb.MaKyLuat); cmd.Parameters.AddWithValue("NgayKyLuat", pb.NgayKyLuat); cmd.Parameters.AddWithValue("LyDo", pb.LyDo); cmd.ExecuteNonQuery(); } catch (Exception) { return(false); } finally { conn.Close(); } return(true); }
public bool Insert(KyLuat kyLuat) { try { string query = "SELECT * FROM KyLuat"; SqlDataAdapter dataAdapter = new SqlDataAdapter(query, connection); table = GetData(); DataRow row = table.NewRow(); row["DoiTuongId"] = kyLuat.DoiTuongId; row["tenKyLuat"] = kyLuat.TenKyLuat; row["noiDung"] = kyLuat.NoiDung; row["ngay"] = kyLuat.Ngay; row["ghiChu"] = kyLuat.GhiChu; table.Rows.Add(row); SqlCommandBuilder sqlCommandBuilder = new SqlCommandBuilder(dataAdapter); dataAdapter.Update(table); return(true); } catch { return(false); } }