Example #1
0
        public NV_VanBan_ChiTiet GetById(int id)
        {
            using (SqlConnection myConnection = new SqlConnection(ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("NV_VanBan_getByID", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;

                    SqlParameter pID = new SqlParameter("@id", SqlDbType.VarChar, 10);
                    pID.Value = id;
                    myCommand.Parameters.Add(pID);

                    DataTable         dt;
                    NV_VanBan_ChiTiet model = new NV_VanBan_ChiTiet();

                    myConnection.Open();
                    using (SqlDataAdapter mData = new SqlDataAdapter(myCommand))
                    {
                        dt = new DataTable();
                        mData.Fill(dt);
                    }
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        model = new NV_VanBan_ChiTiet(dt.Rows[0]);
                    }
                    return(model);
                }
            }
        }
Example #2
0
        public bool update(NV_VanBan_ChiTiet model)
        {
            using (SqlConnection myConnection = new SqlConnection(ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("NV_VanBan_update", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;

                    SqlParameter pID = new SqlParameter("@VanBanID", SqlDbType.Int);
                    pID.Value = model.VanBanID;
                    myCommand.Parameters.Add(pID);

                    SqlParameter pTenVanBan = new SqlParameter("@TenVanBan", SqlDbType.NVarChar, 250);
                    pTenVanBan.Value = model.TenVanBan;
                    myCommand.Parameters.Add(pTenVanBan);

                    SqlParameter pLoaiVanBan = new SqlParameter("@LoaiVanBan", SqlDbType.Int);
                    pLoaiVanBan.Value = model.LoaiVanBan;
                    myCommand.Parameters.Add(pLoaiVanBan);

                    SqlParameter pDonViBanHanh = new SqlParameter("@DonViBanHanh", SqlDbType.NVarChar, 200);
                    pDonViBanHanh.Value = model.DonViBanHanh;
                    myCommand.Parameters.Add(pDonViBanHanh);

                    SqlParameter pNgayBanHanh = new SqlParameter("@NgayBanHanh", SqlDbType.DateTime);
                    pNgayBanHanh.Value = model.NgayBanHanh;
                    myCommand.Parameters.Add(pNgayBanHanh);

                    SqlParameter pMoTa = new SqlParameter("@MoTa", SqlDbType.NText);
                    pMoTa.Value = model.MoTa;
                    myCommand.Parameters.Add(pMoTa);

                    SqlParameter pNoiDung = new SqlParameter("@NoiDung", SqlDbType.NText);
                    pNoiDung.Value = model.NoiDung;
                    myCommand.Parameters.Add(pNoiDung);

                    SqlParameter pFile = new SqlParameter("@File", SqlDbType.NVarChar, 500);
                    pFile.Value = model.File;
                    myCommand.Parameters.Add(pFile);

                    SqlParameter pDuyet = new SqlParameter("@Duyet", SqlDbType.Bit);
                    pDuyet.Value = model.Duyet;
                    myCommand.Parameters.Add(pDuyet);

                    SqlParameter pTonTai = new SqlParameter("@TonTai", SqlDbType.Bit);
                    pTonTai.Value = model.TonTai;
                    myCommand.Parameters.Add(pTonTai);
                    try
                    {
                        myConnection.Open();
                        myCommand.ExecuteNonQuery();
                        return(true);
                    }
                    catch
                    {
                        return(false);
                    }
                }
            }
        }