Ejemplo n.º 1
0
        public NV_NoiLuuTru_ChiTiet GetById(int id)
        {
            using (SqlConnection myConnection = new SqlConnection(ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("NV_NoiLuuTru_getByID", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;

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

                    DataTable            dt;
                    NV_NoiLuuTru_ChiTiet model = new NV_NoiLuuTru_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_NoiLuuTru_ChiTiet(dt.Rows[0]);
                    }
                    return(model);
                }
            }
        }
Ejemplo n.º 2
0
        public bool update(NV_NoiLuuTru_ChiTiet model)
        {
            using (SqlConnection myConnection = new SqlConnection(ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("NV_NoiLuuTru_update", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;

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

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


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

                    SqlParameter pThuocTinh = new SqlParameter("@ThuocTinh", SqlDbType.VarChar, 10);
                    pThuocTinh.Value = model.ThuocTinh;
                    myCommand.Parameters.Add(pThuocTinh);

                    SqlParameter pThuocHuyen = new SqlParameter("@ThuocHuyen", SqlDbType.VarChar, 10);
                    pThuocHuyen.Value = model.ThuocHuyen;
                    myCommand.Parameters.Add(pThuocHuyen);

                    SqlParameter pThuocXa = new SqlParameter("@ThuocXa", SqlDbType.VarChar, 10);
                    pThuocXa.Value = model.ThuocXa;
                    myCommand.Parameters.Add(pThuocXa);

                    SqlParameter pDienThoai = new SqlParameter("@DienThoai", SqlDbType.NVarChar, 50);
                    pDienThoai.Value = model.DienThoai;
                    myCommand.Parameters.Add(pDienThoai);

                    SqlParameter pFax = new SqlParameter("@Fax", SqlDbType.NVarChar, 50);
                    pFax.Value = model.Fax;
                    myCommand.Parameters.Add(pFax);

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

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

                    SqlParameter pEmail = new SqlParameter("@Email", SqlDbType.NVarChar, 50);
                    pEmail.Value = model.Email;
                    myCommand.Parameters.Add(pEmail);

                    SqlParameter pAnhDaiDien = new SqlParameter("@AnhDaiDien", SqlDbType.Int);
                    pAnhDaiDien.Value = model.AnhDaiDien;
                    myCommand.Parameters.Add(pAnhDaiDien);
                    SqlParameter pMoTa = new SqlParameter("@MoTa", SqlDbType.NVarChar, 2000);
                    pMoTa.Value = model.MoTa;
                    myCommand.Parameters.Add(pMoTa);

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

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