private void btntachdon_Click(object sender, EventArgs e) { DialogResult hoi = MessageBox.Show("Tạo 1 đơn mới từ dữ liệu gốc đã trừ đi số lượng vừa nhặt", "Hỏi", MessageBoxButtons.YesNo); if (hoi == DialogResult.Yes) { try { if (xuatexcel()) { xulyJSON hh = new xulyJSON(); lbThongbao.Text = "Đang tách đơn ... "; var dulieu = ketnoi.Khoitao(); dulieu.savevaobangchuyenhang(ngay, gio); dulieu.xoabangtamchuyenhang(); dulieu.xoabangthuathieu(); datag3.DataSource = hh.tachDON(datag2, "dulieucopy.json", hh.get()); lammoitatca(); lbsoluongdon.Text = hh.tongsoluongValue(hh.get()); hamtao.notifi_hts("OK ,Triển chiêu"); lbThongbao.Text = "-"; } return; } catch (Exception) { hamtao.notifi_hts("Có vấn đề - Xem lại"); } } }
void haminnhat() // ham xu ly thread innhat { try { var dulieu = ketnoi.Khoitao(); int slIN = 1; lbThongbao.Invoke(new MethodInvoker(delegate() { lbThongbao.Text = "Đang xử lý in đơn để nhặt ..."; })); DataTable dt = null; string soluong = null; datag3.Invoke(new MethodInvoker(delegate() { if (datag3.RowCount < 1) { return; } nut_checkmathieu.Invoke(new MethodInvoker(delegate() { if (nut_checkmathieu.Checked) { string tenfile = @"dulieutach.json"; File.Copy("dulieucopy.json", tenfile, true); xulyJSON xl = new xulyJSON(tenfile); dt = xl.tachDON(datag2, tenfile, xl.get(tenfile)); soluong = xl.tongsoluongValue(xl.get(tenfile)); } else { dt = (DataTable)(datag3.DataSource); soluong = lbsoluongdon.Text; } })); })); txtSLIN.Invoke(new MethodInvoker(delegate() { if (Regex.IsMatch(txtSLIN.Text, @"^\d+")) { slIN = int.Parse(txtSLIN.Text.Trim()); } })); hamtao.taovainfileexcel(dt, soluong, slIN); lbThongbao.Invoke(new MethodInvoker(delegate() { lbThongbao.Text = "IN xong - Nhặt thôi."; })); } catch (Exception) { return; } }