Ejemplo n.º 1
0
        public bool update(NV_Document_ChiTiet model)
        {
            using (SqlConnection myConnection = new SqlConnection(ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("NV_Document_update", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;

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

                    SqlParameter pTenAnh = new SqlParameter("@TenTaiLieu", SqlDbType.NVarChar, 300);
                    pTenAnh.Value = model.TenTaiLieu;
                    myCommand.Parameters.Add(pTenAnh);

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

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

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

                    try
                    {
                        myConnection.Open();
                        myCommand.ExecuteNonQuery();
                        return(true);
                    }
                    catch
                    {
                        return(false);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public NV_Document_ChiTiet GetById(int id)
        {
            using (SqlConnection myConnection = new SqlConnection(ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("NV_Document_getByID", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;

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

                    NV_Document_ChiTiet model = new NV_Document_ChiTiet();
                    DataTable           dt;

                    myConnection.Open();
                    using (SqlDataAdapter mData = new SqlDataAdapter(myCommand))
                    {
                        dt = new DataTable();
                        mData.Fill(dt);
                    }
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        model.DocumentID = id;
                        model.TenTaiLieu = dt.Rows[0]["TenTaiLieu"].ToString();
                        try
                        {
                            model.NgayTao = Convert.ToDateTime(dt.Rows[0]["NgayTao"].ToString());
                        }
                        catch { }
                        model.DanhMuc = int.Parse(dt.Rows[0]["DanhMuc"].ToString());
                        model.File    = dt.Rows[0]["File"].ToString();
                    }
                    return(model);
                }
            }
        }