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

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

                    NV_DM_LoaiDiSan_ChiTiet model = new NV_DM_LoaiDiSan_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 = new NV_DM_LoaiDiSan_ChiTiet(dt.Rows[0]);
                    }
                    return(model);
                }
            }
        }
Ejemplo n.º 2
0
        public bool them(NV_DM_LoaiDiSan_ChiTiet model, out int id)
        {
            using (SqlConnection myConnection = new SqlConnection(ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("NV_DM_LoaiDiSan_add", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;

                    SqlParameter pID = new SqlParameter("@LoaiID", SqlDbType.Int);
                    pID.Direction = ParameterDirection.Output;
                    myCommand.Parameters.Add(pID);

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

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

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

                    SqlParameter pGhichu = new SqlParameter("@Ghichu", SqlDbType.NVarChar, 500);
                    pGhichu.Value = model.GhiChu;
                    myCommand.Parameters.Add(pGhichu);

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

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

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

                    id = 0;
                    try
                    {
                        myConnection.Open();
                        myCommand.ExecuteNonQuery();
                        id = (int)pID.Value;
                        return(true);
                    }
                    catch
                    {
                        return(false);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public NV_DM_LoaiDiSan_ChiTiet GetByUrl(string url)
        {
            string    sql = "select * from DM_LoaiDiSan where Url='" + url + "'";
            DataTable dt  = Sys_Common.getDataByQuery(sql);
            NV_DM_LoaiDiSan_ChiTiet model = new NV_DM_LoaiDiSan_ChiTiet();

            if (dt != null && dt.Rows.Count > 0)
            {
                model.LoaiID  = int.Parse(dt.Rows[0]["LoaiID"].ToString());
                model.MaLoai  = dt.Rows[0]["MaLoai"].ToString();
                model.TenLoai = dt.Rows[0]["TenLoai"].ToString();
                model.EngName = dt.Rows[0]["EngName"].ToString();
                try
                {
                    model.ParentID = int.Parse(dt.Rows[0]["ParentID"].ToString());
                }
                catch { }
                model.GhiChu = dt.Rows[0]["GhiChu"].ToString();
                model.Stt    = int.Parse(dt.Rows[0]["Stt"].ToString());
            }
            return(model);
        }