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(); } }
private void btnCapNhat_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { //DateTime NgayKiemKe = DateTime.Now; //string IDStore = (string)(lkTenKhoHang as LookUpEdit).EditValue; // ID Kho //string tenKV = txtTenKhuVuc.Text; //int index = 0; //var data = (from d in db.KiemKeHangHoas // join t in db.HangHoas on d.ID_HangHoa equals t.HangHoaID // where (d.ID_Users == ID_User && d.TenKeHang == TenKeHang && d.updated_at.Day == ThoiGian.Day && d.updated_at.Month == ThoiGian.Month && d.updated_at.Year == ThoiGian.Year&&d.updated_at.Hour == ThoiGian.Hour && d.updated_at.Minute == ThoiGian.Minute && d.updated_at.Second == ThoiGian.Second && d.ID_Kho == IDStore) // select new // { // ThoiGianQuet = d.updated_at // }).ToList(); // for (int i = 0; i < gridView1.RowCount; i++) //{ // DateTime TGQuet = Convert.ToDateTime(gridView1.GetRowCellValue(i, colThoiGianCapNhat)); // foreach (var c in data) // { // if(c.ThoiGianQuet.Day != TGQuet.Day || c.ThoiGianQuet.Month!= TGQuet.Month || c.ThoiGianQuet.Year!= TGQuet.Year || c.ThoiGianQuet.Hour != TGQuet.Hour || c.ThoiGianQuet.Minute!= TGQuet.Minute||c.ThoiGianQuet.Second !=TGQuet.Second) // { // var kiemke = new KiemKeHangHoa // { // STT = Convert.ToInt32(gridView1.GetRowCellValue(i, colSTT)), // ID_Users = ID_User, // ID_HangHoa = (string)gridView1.GetRowCellValue(i, IDHangHoa), // ID_Kho = IDStore, // TenKeHang = tenKV, // SoLuong = 1, // NgayKiemKe = Convert.ToDateTime(gridView1.GetRowCellValue(i, colThoiGianQuet)), // updated_at =c.ThoiGianQuet, // LoaiKiemKe = (int)gridView1.GetRowCellValue(i, colLoaiKiemKe) // }; // db.KiemKeHangHoas.Add(kiemke); // db.SaveChanges(); // TGQuet = c.ThoiGianQuet; // } // } // index = index + 1; //} //foreach (var d in db.KiemKeHangHoas) // update //{ // if (d.ID_Users == ID_User && d.TenKeHang == TenKeHang && d.updated_at.Day == ThoiGian.Day && d.updated_at.Month == ThoiGian.Month && d.updated_at.Year == ThoiGian.Year && d.ID_Kho == IDStore) // { // d.updated_at = DateTime.Now; // } //} //db.SaveChanges(); //foreach (var bc in db.BaoCaoKiemKes) //{ // if(bc.NgayTao == ThoiGian) // { // bc.NgayTao = DateTime.Now; // bc.TongSoLuong = index; // } //} //db.SaveChanges(); //MessageBox.Show("Lưu dữ liệu thành công !", "Thông Báo ", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); 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 < gridView1.RowCount; i++) { var kiemke = new KiemKeHangHoa { STT = _STT + 1, ID_Users = ID_User, ID_HangHoa = (string)gridView1.GetRowCellValue(i, IDHangHoa), ID_Kho = IDStore, TenKeHang = tenKV, SoLuong = 1, NgayKiemKe = Convert.ToDateTime(gridView1.GetRowCellValue(i, colThoiGianQuet)), updated_at = ThoiGian, LoaiKiemKe = (int)gridView1.GetRowCellValue(i, colLoaiKiemKe) }; db.KiemKeHangHoas.Add(kiemke); db.SaveChanges(); index = index + 1; _STT = _STT + 1; } foreach (var d in db.KiemKeHangHoas) // update { if (d.ID_Users == ID_User && d.TenKeHang == TenKeHang && d.updated_at.Day == ThoiGian.Day && d.updated_at.Month == ThoiGian.Month && d.updated_at.Year == ThoiGian.Year && d.ID_Kho == IDStore) { d.updated_at = DateTime.Now; } } db.SaveChanges(); foreach (var bc in db.BaoCaoKiemKes) { if (bc.NgayTao == ThoiGian) { bc.NgayTao = DateTime.Now; bc.TongSoLuong = TongSL + gridView1.RowCount; } } db.SaveChanges(); this.Close(); }