Пример #1
0
        public bool Update(KhenThuong khenThuong)
        {
            try
            {
                string         query       = "SELECT * FROM KhenThuong";
                SqlDataAdapter dataAdapter = new SqlDataAdapter(query, connection);
                table            = GetData();
                table.PrimaryKey = new DataColumn[] { table.Columns[0] };
                DataRow row = table.Rows.Find(khenThuong.DoiTuongId);

                if (row != null)
                {
                    row["DoiTuongId"]    = khenThuong.DoiTuongId;
                    row["tenKhenThuong"] = khenThuong.TenKhenThuong;
                    row["noiDung"]       = khenThuong.NoiDung;
                    row["ngay"]          = khenThuong.Ngay;
                    row["ghiChu"]        = khenThuong.GhiChu;
                }

                SqlCommandBuilder sqlCommandBuilder = new SqlCommandBuilder(dataAdapter);
                dataAdapter.Update(table);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #2
0
        public bool Insert(KhenThuong khenThuong)
        {
            try
            {
                string         query       = "SELECT * FROM KhenThuong";
                SqlDataAdapter dataAdapter = new SqlDataAdapter(query, connection);
                table = GetData();
                DataRow row = table.NewRow();
                row["DoiTuongId"]    = khenThuong.DoiTuongId;
                row["tenKhenThuong"] = khenThuong.TenKhenThuong;
                row["noiDung"]       = khenThuong.NoiDung;
                row["ngay"]          = khenThuong.Ngay;
                row["ghiChu"]        = khenThuong.GhiChu;

                table.Rows.Add(row);

                SqlCommandBuilder sqlCommandBuilder = new SqlCommandBuilder(dataAdapter);
                dataAdapter.Update(table);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #3
0
        public Boolean ThemKhenThuong(KhenThuong pb)
        {
            SqlConnection conn = getConnection();

            conn.Open();
            try
            {
                string     sqlThem = "INSERT INTO Thuong VALUES(@MaPB ,@MaNV , @HoTen , @TienThuong , @MaThuong , @NgayThuong , @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("TienThuong", pb.TienThuong);
                cmd.Parameters.AddWithValue("MaThuong", pb.MaKhenThuong);
                cmd.Parameters.AddWithValue("NgayThuong", pb.NgayKhenThuong);
                cmd.Parameters.AddWithValue("LyDo", pb.LyDo);
                cmd.ExecuteNonQuery();
            }
            catch (Exception)
            {
                return(false);
            }
            finally
            {
                conn.Close();
            }
            return(true);
        }
Пример #4
0
        public Boolean SuaKhenThuong(KhenThuong pb)
        {
            SqlConnection conn = getConnection();

            conn.Open();
            try
            {
                string sqlSua = "DECLARE @dem int select @dem = COUNT(MaNV) FROM Thuong WHERE MaNV = @MaNV " +
                                "IF @dem != 0 UPDATE Thuong SET TienThuong = @TienThuong , MaThuong = @MaThuong , NgayThuong = @NgayThuong , LyDo = @LyDo WHERE MaNV = @MaNV else raiserror('',16,1)";
                SqlCommand cmd = new SqlCommand(sqlSua, conn);
                cmd.Parameters.AddWithValue("MaNV", pb.MaNV);
                cmd.Parameters.AddWithValue("TienThuong", pb.TienThuong);
                cmd.Parameters.AddWithValue("MaThuong", pb.MaKhenThuong);
                cmd.Parameters.AddWithValue("NgayThuong", pb.NgayKhenThuong);
                cmd.Parameters.AddWithValue("LyDo", pb.LyDo);
                cmd.ExecuteNonQuery();
            }
            catch (Exception)
            {
                return(false);
            }
            finally
            {
                conn.Close();
            }
            return(true);
        }
        // KHEN THƯỞNG.
        public bool Update_KhenThuong(KhenThuong khenThuong)
        {
            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "SP_Update_KHENTHUONG";

            cmd.Parameters.Add("@MADV", SqlDbType.NVarChar).Value         = khenThuong.MaDV;
            cmd.Parameters.Add("@THOIGIAN", SqlDbType.Date).Value         = khenThuong.ThoiGian;
            cmd.Parameters.Add("@LYDO", SqlDbType.NVarChar).Value         = khenThuong.LyDo;
            cmd.Parameters.Add("@HINHTHUC", SqlDbType.NVarChar).Value     = khenThuong.HinhThuc;
            cmd.Parameters.Add("@CAPQUYETDINH", SqlDbType.NVarChar).Value = khenThuong.CapQD;

            cmd.Connection = _conn;

            try
            {
                _conn.Open();
                cmd.ExecuteNonQuery();

                return(true);
            }
            catch { return(false); }
            finally { _conn.Close(); }
        }