private void btnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { try { DateTime NgayKiemKe = DateTime.Now; string IDStore = (string)(lkTenKhoHang as LookUpEdit).EditValue; // ID Kho string tenKV = txtTenKhuVuc.Text; int index = 0; for (int i = 0; i < gvDSHangHoa.RowCount; i++) { var kiemke = new KiemKeHangHoa { STT = Convert.ToInt32(gvDSHangHoa.GetRowCellValue(i, colSoTT)), ID_Users = UserID, ID_HangHoa = (string)gvDSHangHoa.GetRowCellValue(i, colIDHangHoa), ID_Kho = IDStore, TenKeHang = tenKV, SoLuong = 1, NgayKiemKe = Convert.ToDateTime(gvDSHangHoa.GetRowCellValue(i, colThoiGianQuet)), updated_at = DateTime.Now, LoaiKiemKe = (int)gvDSHangHoa.GetRowCellValue(i, colLoaiKiemKe) }; db.KiemKeHangHoas.Add(kiemke); db.SaveChanges(); index = index + 1; } var baocao = new BaoCaoKiemKe { ID_User = UserID, TenKhuVuc = txtTenKhuVuc.Text, ID_Kho = IDStore, NgayTao = DateTime.Now, TongSoLuong = index }; db.BaoCaoKiemKes.Add(baocao); db.SaveChanges(); MessageBox.Show("Lưu dữ liệu thành công !", "Thông Báo ", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); list.Clear(); txtTenKhuVuc.Text = ""; txtMessage.Text = ""; bindingSource1.ResetBindings(true); gcDSHangHoa.RefreshDataSource(); _SoTT = 1; } catch { MessageBox.Show("Chưa thể lưu dữ liệu !"); } }
private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (i == 2) { int Gio = ThoiGian.Hour; int Phut = ThoiGian.Minute; int ngay = ThoiGian.Day; int thang = ThoiGian.Month; int nam = ThoiGian.Year; var data = (from slect in context.DuyetHangHoas where (slect.TenKeHang == TenKeHang && (int)slect.NgayCapNhat.Value.Day == ngay && (int)slect.NgayCapNhat.Value.Month == thang && (int)slect.NgayCapNhat.Value.Year == nam && (int)slect.NgayCapNhat.Value.Hour == Gio && (int)slect.NgayCapNhat.Value.Minute == Phut) select new { iduser = slect.IDUser, idkho = slect.IDKho, tenke = slect.TenKeHang, idhang = slect.IDHangHoa, mahh = slect.MaHH, tenhang = slect.TenHH, soluong = 1, ngaykiemke = slect.NgayKiemKe, ngaycapnhat = slect.NgayCapNhat, loaikiemke = slect.LoaiKiemKe, check = slect.Luu } ).ToList(); List <KiemKeHangHoa> listKKHH = new List <KiemKeHangHoa>(); int count = data.Count(); foreach (var lk in data) { KiemKeHangHoa kiemke = new KiemKeHangHoa(); { //kiemke.HangHoa = new HangHoa(); kiemke.ID_Users = lk.iduser; kiemke.ID_Kho = lk.idkho; kiemke.ID_HangHoa = lk.idhang; kiemke.LoaiKiemKe = lk.loaikiemke; kiemke.TenKeHang = lk.tenke; kiemke.SoLuong = 1; //kiemke.NgayKiemKe = lk.ngaykiemke; kiemke.updated_at = DateTime.Now; } context.KiemKeHangHoas.Add(kiemke); } //context.SaveChangesAsync(); context.SaveChanges(); //foreach(var d in data) //{ // var duyet = new DuyetHangHoa // { // LuuServer = true // }; // context.DuyetHangHoas.Add(duyet); //} //context.SaveChanges(); //context.SaveChanges(); MessageBox.Show("Finish", "Thông báo"); //foreach (var entity in listKKHH) //{ // entity.HangHoa = null; //} //string sJson = JsonConvert.SerializeObject(listKKHH); //var save = Barcocde.ReadAPI.SaveTo(ID_User.ToString(), sJson); //if (save.status == 1) //{ // MessageBox.Show("Finish", "Thông báo"); // this.DialogResult = DialogResult.OK; // this.Close(); //} //else //{ // MessageBox.Show(save.message); // this.DialogResult = DialogResult.Abort; //} //} //} ////try ////{ // bdListKiemKe.EndEdit(); // gvListKiemke.CloseEditor(); // if(i==2) // { // List<KiemKeHangHoa> listKKHH = new List<KiemKeHangHoa>(); // for (int k = 0; k < gvListKiemke.RowCount; k++) // { // string ID_HangHoa = (string)gvListKiemke.GetRowCellValue(k, colIDHangHoa); // } else { if (gvListKiemke.RowCount > 0) { List <KiemKeHangHoa> listKKHH = new List <KiemKeHangHoa>(); for (int k = 0; k < gvListKiemke.RowCount; k++) { //string ID_HangHoa = (string)gvListKiemke.GetRowCellValue(k, colIDHangHoa); var kiemke = new DuyetHangHoa(); { kiemke.STT = (int)gvListKiemke.GetRowCellValue(k, colSTT); // kiemke.STT = k; kiemke.IDUser = ID_User; foreach (var c in db.HangHoas) { if (c.TenHH == (string)gvListKiemke.GetRowCellValue(k, colTenHH)) { kiemke.IDHangHoa = c.HangHoaID; kiemke.MaHH = c.MaHH; } } kiemke.TenHH = (string)gvListKiemke.GetRowCellValue(k, colTenHH); //kiemke.MaHH = (string)gvListKiemke.GetRowCellValue(k, colMaHH); kiemke.IDKho = IDStore; kiemke.TenKeHang = TenKeHang; kiemke.SoLuong = 1; kiemke.NgayKiemKe = Convert.ToDateTime(gvListKiemke.GetRowCellValue(k, colNgayKiemKe1)); kiemke.NgayCapNhat = DateTime.Now; kiemke.LoaiKiemKe = (int)gvListKiemke.GetRowCellValue(k, colLoaiKiemKe); }; context.DuyetHangHoas.Add(kiemke); context.SaveChanges(); // listKKHH.Add(kiemke); } foreach (var xch in db.BaoCaoKiemKes) // update { if (xch.NgayTao == ThoiGian) { xch.TrangThaiLuu = 1; } } db.SaveChanges(); var baocao = new BaoCaoKiemKe { ID_User = ID_User, TenKhuVuc = TenKeHang, ID_Kho = IDStore, NgayTao = DateTime.Now }; context.BaoCaoKiemKes.Add(baocao); context.SaveChanges(); MessageBox.Show("Finish", "Thông báo"); } else { MessageBox.Show("Chưa có dữ liệu "); } ////} ////catch ////{ //// MessageBox.Show("Lỗi Mạng"); ////} this.Close(); } }