public bool CapNhatDanhMucThietHai(DanhMucThietHaiDTO dm)
        {
            string sql = "sp_DanhMucThietHai_update";
            List<SqlParameter> ds = new List<SqlParameter>();

            SqlParameter ma = new SqlParameter("@ma", SqlDbType.Int);
            ma.Value = dm.Ma;
            ds.Add(ma);

            ds.Add(new SqlParameter("@maHangMuc", dm.MaHangMuc));
            ds.Add(new SqlParameter("@thiethaihoantoan", dm.ThietHaiHoanToan));

            SqlParameter trangthai = new SqlParameter("@trangthai",SqlDbType.NVarChar);
            trangthai.Value = dm.TrangThai;
            ds.Add(trangthai);

            SqlParameter tinhtrang = new SqlParameter("@tinhtrang", SqlDbType.VarChar);
            tinhtrang.Value = dm.TinhTrang;
            ds.Add(tinhtrang);

            SqlParameter ykien = new SqlParameter("@ykien", SqlDbType.NVarChar);
            ykien.Value = dm.YKienGDV;
            ds.Add(ykien);
            SqlParameter motachung = new SqlParameter("@motachung", SqlDbType.NVarChar);
            motachung.Value = dm.MoTaChung;
            ds.Add(motachung);

            bool kq = SqlDataAcessHelper.exNonStoreParas(sql, ds);
            return kq;
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                lblMessage.Text = "";

                DanhMucThietHaiDAO dao = new DanhMucThietHaiDAO();

                DanhMucThietHaiDTO thietHai = new DanhMucThietHaiDTO();
                string thamchieu = Session["ThamChieu"].ToString();
                thietHai.MaClaim = thamchieu;
                thietHai.MaHangMuc = int.Parse(drDamaged.SelectedValue);
                thietHai.ThietHaiHoanToan = txtTotally.Text;
                thietHai.TrangThai = txtPartial.Text;
                if(checkTinhTrang.Checked)
                    thietHai.TinhTrang = "Yes";
                else
                    thietHai.TinhTrang = "No";
                thietHai.YKienGDV = txtYKienGDV.Text;
                thietHai.MoTaChung = txtMoTaChung.Text;
                dao.ThemDanhMucThietHai(thietHai);

                Response.Write("<script>parent.reloaData();</script>");
                panelGrid.Visible = true;
                panelAddEdit.Visible = false;
                int maGDV = int.Parse(Request.Cookies["MaGDV"].Value);
                string noidung = gdv.LayTenTheoMa(maGDV) + " created a summary of loss of case SR01" + thamchieu + " .";
                SaveLogTracking(maGDV, noidung, thamchieu);
                loadDanhMucThietHai();
            }catch(Exception ex){
                lblMessage.Text = ex.Message;
            }
        }
        protected void btnThem_Click(object sender, EventArgs e)
        {
            dmdto = new DanhMucThietHaiDTO();
            dmdto.MaClaim = mathamchieu;
            int mahangmuc = int.Parse(drHangMucTaiSan.SelectedItem.Value.ToString());
            if (mahangmuc != 0)
            {
                dmdto.MaHangMuc = mahangmuc;

                string trangthai = txtTrangThai.Text;
                if (trangthai == "")
                    trangthai = "";

                if (ckTinhTrang.Checked == true)
                {
                    dmdto.TinhTrang = "Yes";
                    dmdto.ThietHaiHoanToan = trangthai;
                    dmdto.TrangThai = "";
                }
                else
                {
                    dmdto.TinhTrang = "No";
                    dmdto.ThietHaiHoanToan = "";
                    dmdto.TrangThai = trangthai;
                }
                string ykien = txtYKienGDV.Text;
                if (ykien != "")
                    dmdto.YKienGDV = ykien;
                else
                    dmdto.YKienGDV = "";
                bool kq = dmdao.ThemDanhMucThietHai(dmdto);
                if (kq == true)
                {
                    //Response.Write("<script> alert ('Update succeed!');</script>");
                    loadDanhSach(mathamchieu);
                    txtTrangThai.Text = "";
                    txtYKienGDV.Text = "";
                    ckTinhTrang.Checked = false;
                }

                else
                    Response.Write("<script> alert ('Fail!');</script>");
            }
            else
                Response.Write("<script>alert('Chưa chọn hạng mục tài sản !');</script>");
        }
        public bool ThemDanhMucThietHai(DanhMucThietHaiDTO dm)
        {
            string sql = "sp_DanhMucThietHai_insert";
            List<SqlParameter> ds = new List<SqlParameter>();

            SqlParameter maclaim = new SqlParameter("@maclaim",SqlDbType.VarChar);
            maclaim.Value = dm.MaClaim;
            ds.Add(maclaim);

            SqlParameter mahangmuc = new SqlParameter("@mahangmuc",SqlDbType.Int);
            mahangmuc.Value = dm.MaHangMuc;
            ds.Add(mahangmuc);

            SqlParameter trangthai = new SqlParameter("@trangthai", SqlDbType.NVarChar);
            trangthai.Value = dm.TrangThai;
            ds.Add(trangthai);

            SqlParameter tinhtrang = new SqlParameter("@tinhtrang",SqlDbType.VarChar);
            tinhtrang.Value = dm.TinhTrang;
            ds.Add(tinhtrang);

            SqlParameter ykien = new SqlParameter("@ykien", SqlDbType.NVarChar);
            ykien.Value = dm.YKienGDV;
            ds.Add(ykien);

            SqlParameter thiethaiht = new SqlParameter("@thiethaihoantoan", SqlDbType.NVarChar);
            thiethaiht.Value = dm.ThietHaiHoanToan;
            ds.Add(thiethaiht);

            SqlParameter motachung = new SqlParameter("@motachung",SqlDbType.NVarChar);
            motachung.Value = dm.MoTaChung;
            ds.Add(motachung);

            bool kq = SqlDataAcessHelper.exNonStoreParas(sql, ds);
            return kq;
        }
 protected void gvDanhSachHangMucThietHai_RowUpdating(object sender, GridViewUpdateEventArgs e)
 {
     dmdto= new DanhMucThietHaiDTO();
     GridViewRow row= gvDanhSachHangMucThietHai.Rows[e.RowIndex];
     //TextBox txtnhomhangmuc=row.Cells[0].Controls[0] as TextBox;
     TextBox trangthai = row.Cells[1].Controls[0] as TextBox;
     TextBox tinhtrang = row.Cells[2].Controls[0] as TextBox;
        // CheckBox cktinhtrangthiethai = row.Cells[2].Controls[0] as CheckBox;
     TextBox ykien = row.Cells[3].Controls[0] as TextBox;
     int mahangmuc= int.Parse(gvDanhSachHangMucThietHai.DataKeys[e.RowIndex].Value.ToString());
     dmdto.Ma=mahangmuc;
     //string mathamchieu=cl.LayMaTheoTen(thamchieu);
     dmdto.MaClaim=mathamchieu;
     //dmdto.TenHangMuc= txtnhomhangmuc.Text;
     dmdto.TrangThai=trangthai.Text;
     //if (ckTinhTrang.Checked == true)
     //    dmdto.TinhTrang = "Yes";
     //else
     //    dmdto.TinhTrang = "No";
     dmdto.TinhTrang = tinhtrang.Text; ;
     dmdto.YKienGDV = ykien.Text;
     bool kq= dmdao.CapNhatDanhMucThietHai(dmdto);
     if( kq==true)
     {
         e.Cancel=true;
         gvDanhSachHangMucThietHai.EditIndex=-1;
         loadDanhSach(mathamchieu);
     }
     else
         Response.Write("<script>alert('Fail!');</script>");
 }