protected void btnLuu_Click(object sender, EventArgs e) { string IDPhieuKiemKho = IDPhieuKiemKho_Temp.Value.ToString(); DataTable db = data.DanhSachKiemKhoTemp_IDPhieuKiemKho(IDPhieuKiemKho); if (db.Rows.Count > 0) { string IDNguoiDung = Session["IDNhanVien"].ToString(); string IDChiNhanh = Session["IDChiNhanh"].ToString(); DateTime NgayKiemKho = DateTime.Parse(txtNgayLapPhieu.Text.ToString()); string GhiChu = txtGhiChu.Text == null ? "" : txtGhiChu.Text.ToString(); data = new dtKiemKho(); data.CapNhatPhieuKiemKho(IDPhieuKiemKho, IDNguoiDung, NgayKiemKho, GhiChu, IDChiNhanh); foreach (DataRow dr in db.Rows) { string IDNguyenLieu = dr["IDNguyenLieu"].ToString(); string TonKho = dr["TonKho"].ToString(); string ChenhLech = dr["ChenhLech"].ToString(); string ThucTe = dr["ThucTe"].ToString(); string MaNguyenLieu = dr["MaNguyenLieu"].ToString(); string IDDonViTinh = dr["IDDonViTinh"].ToString(); data = new dtKiemKho(); data.ThemPhieuKiemKho(IDPhieuKiemKho, IDNguyenLieu, TonKho, ChenhLech, ThucTe, MaNguyenLieu, IDDonViTinh); } data = new dtKiemKho(); data.XoaPhieuKiemKho_Temp_IDPhieuKiemKho2(IDPhieuKiemKho); Response.Redirect("DanhSachKiemKho.aspx"); } else { cmbHangHoa.Focus(); Response.Write("<script language='JavaScript'> alert('Danh sách kiểm kho rỗng.'); </script>"); } }
protected void btnLuu_Click(object sender, EventArgs e) { string IDPhieuKiemKho = IDPhieuKiemKho_Temp.Value.ToString(); DataTable db = data.DanhSachKiemKhoTemp_IDPhieuKiemKho(IDPhieuKiemKho); if (db.Rows.Count > 0) { string IDNguoiDung = Session["IDNhanVien"].ToString(); DateTime NgayKiemKho = DateTime.Parse(txtNgayLapPhieu.Text.ToString()); string IDKho = Session["IDKho"].ToString(); string GhiChu = txtGhiChu.Text == null ? "" : txtGhiChu.Text.ToString(); data = new dtKiemKho(); object ID1 = data.ThemPhieu_Temp(); if (ID1 != null) { data.CapNhatPhieuKiemKho(ID1, IDNguoiDung, NgayKiemKho, IDKho, GhiChu); foreach (DataRow dr in db.Rows) { string IDHangHoa = dr["IDHangHoa"].ToString(); string TonKho = dr["TonKho"].ToString(); float ChenhLech = float.Parse(dr["ChenhLech"].ToString()); string ThucTe = dr["ThucTe"].ToString(); string MaHang = dr["MaHang"].ToString(); string IDDonViTinh = dr["IDDonViTinh"].ToString(); string IDKe = ""; data = new dtKiemKho(); data.ThemPhieuKiemKho(ID1, IDHangHoa, TonKho, ChenhLech.ToString(), ThucTe, MaHang, IDDonViTinh, IDKe); if (ChenhLech > 0) { object TheKho1 = dtTheKho.ThemTheKho("", "Kiểm kho: " + dtTheKho.LayTenKho_ID(IDKho), "0", "0", (dtCapNhatTonKho.SoLuong_TonKho(IDHangHoa, IDKho) + ChenhLech).ToString(), Session["IDNhanVien"].ToString(), IDKho, IDHangHoa, "Nhập", "0", "0", ChenhLech.ToString()); if (TheKho1 != null) { dtCapNhatTonKho.CapNhatKho(IDHangHoa, ThucTe, IDKho); } } else if (ChenhLech < 0) { object TheKho2 = dtTheKho.ThemTheKho("", "Kiểm kho: " + dtTheKho.LayTenKho_ID(IDKho), "0", "0", (dtCapNhatTonKho.SoLuong_TonKho(IDHangHoa, IDKho) + ChenhLech).ToString(), Session["IDNhanVien"].ToString(), IDKho, IDHangHoa, "Xuất", "0", "0", ChenhLech.ToString()); if (TheKho2 != null) { dtCapNhatTonKho.CapNhatKho(IDHangHoa, ThucTe, IDKho); } } } data = new dtKiemKho(); data.XoaPhieuKiemKho_Temp_IDPhieuKiemKho(IDPhieuKiemKho); Response.Redirect("DanhSachKiemKho.aspx"); //dtLichSuTruyCap.ThemLichSu(Session["IDNhanVien"].ToString(), Session["IDNhom"].ToString(), "Kiểm Kho", Session["IDKho"].ToString(), "Nhập xuất tồn", "Thêm"); } else { Response.Write("<script language='JavaScript'> alert('Cập nhật không thành công.'); </script>"); } } else { txtBarcode.Focus(); Response.Write("<script language='JavaScript'> alert('Danh sách kiểm kho rỗng.'); </script>"); } }