public ActionResult Adddetail(string ma_phieu_header, List <StatementDetail> details) { using (var dbConn = Helpers.OrmliteConnection.openConn()) { try { if (accessDetail.sua) { foreach (var item in details) { StatementDetail newdata = new StatementDetail(); newdata.ma_phieu_header = ma_phieu_header; newdata.ma_san_pham = item.ma_san_pham; newdata.so_luong = item.so_luong; newdata.thong_so_ky_thuat = item.thong_so_ky_thuat; newdata.muc_dich_su_dung = ""; newdata.nguoi_tao = currentUser.ma_nguoi_dung; newdata.ma_pyc_header = item.ma_pyc_header; newdata.ma_nha_cung_cap = item.ma_nha_cung_cap; newdata.don_gia_vat = item.don_gia_vat; newdata.don_gia = item.don_gia; newdata.thue_vat = item.thue_vat; newdata.don_vi_tinh = item.don_vi_tinh; newdata.ma_chinh_sach_gia = item.ma_chinh_sach_gia; newdata.ma_don_vi = item.ma_don_vi; newdata.ngay_tao = DateTime.Now; newdata.ngay_cap_nhat = DateTime.Parse("1900-01-01"); newdata.nguoi_cap_nhat = ""; newdata.trang_thai = ""; newdata.noi_dung_xac_nhan_ton_kho = item.noi_dung_xac_nhan_ton_kho; newdata.noi_dung_xac_nhan_cap_3 = item.noi_dung_xac_nhan_cap_3; newdata.ma_chi_nhanh = item.ma_chi_nhanh; dbConn.Insert <StatementDetail>(newdata); //PRequestDetail detail = dbConn.FirstOrDefault<PRequestDetail>(s => s.ma_phieu_header == item.ma_pyc_header && s.ma_san_pham == item.ma_san_pham && s.ma_nha_cung_cap == item.ma_nha_cung_cap); PRequestDetail detail = dbConn.FirstOrDefault <PRequestDetail>(s => s.id == item.id); detail.ma_to_trinh = ma_phieu_header; dbConn.Update(detail); } } else { return(Json(new { success = false, error = "Bạn không có quyền sửa dữ liệu" })); } return(Json(new { success = true, ma_phieu_header = ma_phieu_header })); } catch (Exception ex) { return(Json(new { success = false, error = ex.Message })); } } }
public ActionResult CreateUpdateNew(StatementHeader data, List <StatementDetail> details) { using (var dbConn = Helpers.OrmliteConnection.openConn()) { try { int id = 0; if (accessDetail.them) { string ma_phieu = ""; var loai = "BTH"; //var ma_don_vi = currentUser.ma_don_vi; var yyMMdd = DateTime.Now.ToString("yyMMdd"); var existLast = dbConn.SingleOrDefault <StatementHeader>("SELECT TOP 1 * FROM StatementHeader ORDER BY id DESC"); var nextNo = 0; var yearNow = int.Parse(DateTime.Now.Year.ToString().Substring(2, 2)); if (existLast != null) { nextNo = int.Parse(existLast.ma_phieu.Substring(9, existLast.ma_phieu.Length - 9)) + 1; var yearOld = int.Parse(existLast.ma_phieu.Substring(3, 2)); if (yearOld == yearNow) { ma_phieu = loai + yyMMdd + String.Format("{0:00000}", nextNo); } else { ma_phieu = loai + yyMMdd + "00001"; } } else { ma_phieu = loai + yyMMdd + "00001"; } data.ma_phieu = ma_phieu; //data.ngay_tao_yeu_cau = !string.IsNullOrEmpty(Request["ngay_tao_yeu_cau"]) ? DateTime.Parse(DateTime.ParseExact(Request["ngay_tao_yeu_cau"], "dd/MM/yyyy", CultureInfo.InvariantCulture).ToString("yyyy-MM-dd")) : DateTime.Parse("1900-01-01"); //data.ngay_cap_thiet_bi = !string.IsNullOrEmpty(Request["ngay_cap_thiet_bi"]) ? DateTime.Parse(DateTime.ParseExact(Request["ngay_cap_thiet_bi"], "dd/MM/yyyy", CultureInfo.InvariantCulture).ToString("yyyy-MM-dd")) : DateTime.Parse("1900-01-01"); data.ten_phieu = data.ma_phieu; data.ngay_tao_yeu_cau = DateTime.Now; data.ngay_cap_thiet_bi = DateTime.Now; data.ngay_tao = DateTime.Now; data.nguoi_tao = currentUser.ma_nguoi_dung; data.ngay_cap_nhat = DateTime.Parse("1900-01-01"); data.nguoi_cap_nhat = ""; data.trang_thai = "MOI"; dbConn.Insert(data); id = (int)dbConn.GetLastInsertId(); foreach (var item in details) { StatementDetail newdata = new StatementDetail(); newdata.ma_phieu_header = data.ma_phieu; newdata.ma_san_pham = item.ma_san_pham; newdata.so_luong = item.so_luong; newdata.thong_so_ky_thuat = item.thong_so_ky_thuat; newdata.muc_dich_su_dung = ""; newdata.nguoi_tao = currentUser.ma_nguoi_dung; newdata.ma_pyc_header = item.ma_pyc_header; newdata.ma_nha_cung_cap = item.ma_nha_cung_cap; newdata.don_gia_vat = item.don_gia_vat; newdata.don_gia = item.don_gia; newdata.thue_vat = item.thue_vat; newdata.don_vi_tinh = item.don_vi_tinh; newdata.ma_chinh_sach_gia = item.ma_chinh_sach_gia; newdata.ma_chi_nhanh = item.ma_chi_nhanh; newdata.ma_don_vi = item.ma_don_vi; newdata.noi_dung_xac_nhan_ton_kho = item.noi_dung_xac_nhan_ton_kho; newdata.noi_dung_xac_nhan_cap_3 = item.noi_dung_xac_nhan_cap_3; newdata.ngay_tao = DateTime.Now; newdata.ngay_cap_nhat = DateTime.Parse("1900-01-01"); newdata.nguoi_cap_nhat = ""; newdata.trang_thai = ""; dbConn.Insert <StatementDetail>(newdata); //PRequestDetail detail = dbConn.FirstOrDefault<PRequestDetail>(s => s.ma_phieu_header == item.ma_pyc_header && s.ma_san_pham == item.ma_san_pham && s.ma_nha_cung_cap == item.ma_nha_cung_cap); PRequestDetail detail = dbConn.FirstOrDefault <PRequestDetail>(s => s.id == item.id); detail.ma_to_trinh = ma_phieu; dbConn.Update(detail); } } else { return(Json(new { success = false, error = "Bạn không có quyền thêm dữ liệu" })); } return(Json(new { success = true, id = id })); } catch (Exception ex) { return(Json(new { success = false, error = ex.Message })); } } }