/// <summary> /// chi tiet kiem ke /// </summary> /// <param name="MaKiemKe"></param> private void LayKiemKeKhoTheoMaKiemKe(string MaKiemKe) { try { Entities.TruyenGiaTri truyen = new Entities.TruyenGiaTri(); dgvInsertOrder.DataSource = null; cl = new Server_Client.Client(); this.client = cl.Connect(Luu.IP, Luu.Ports); truyen = new Entities.TruyenGiaTri("Select", MaKiemKe); clientstrem = cl.SerializeObj(this.client, "LayKiemKeKhoTheoMaKiemKe", truyen); Entities.ThongTinKiemKeKho[] ddh = null; ddh = (Entities.ThongTinKiemKeKho[])cl.DeserializeHepper(clientstrem, ddh); client.Close(); clientstrem.Close(); if (ddh.Length > 0) { dgvInsertOrder.DataSource = ddh; this.ctTemp = ddh; } else { Entities.ThongTinKiemKeKho[] lay = new Entities.ThongTinKiemKeKho[0]; dgvInsertOrder.DataSource = lay; } fixDatagridview(); } catch (Exception ex) { string s = ex.Message; Entities.ThongTinKiemKeKho[] lay = new Entities.ThongTinKiemKeKho[0]; dgvInsertOrder.DataSource = lay; fixDatagridview(); } }
private void InThongTinKiemKe() { try { Entities.ThongTinKiemKeKho[] row = new Entities.ThongTinKiemKeKho[dgvInsertOrder.RowCount]; for (int k = 0; k < dgvInsertOrder.RowCount; k++) { Entities.ThongTinKiemKeKho banghi = new Entities.ThongTinKiemKeKho(); banghi.Mahang = dgvInsertOrder.Rows[k].Cells[0].Value.ToString(); banghi.Tenhang = dgvInsertOrder.Rows[k].Cells[1].Value.ToString(); banghi.Tonsosach = dgvInsertOrder.Rows[k].Cells[2].Value.ToString(); banghi.Tonthucte = dgvInsertOrder.Rows[k].Cells[3].Value.ToString(); banghi.Chenhlech = dgvInsertOrder.Rows[k].Cells[4].Value.ToString(); banghi.Lydo = dgvInsertOrder.Rows[k].Cells[5].Value.ToString(); banghi.Giavon = dgvInsertOrder.Rows[k].Cells[6].Value.ToString(); banghi.Giachechlech = dgvInsertOrder.Rows[k].Cells[7].Value.ToString(); row[k] = banghi; } Entities.KiemKeKho kiemke = new Entities.KiemKeKho(); kiemke.MaKiemKe = txtSochungtu.Text; kiemke.NgayKiemKe = Utils.StringToDateTime(makNgaychungtu.Text); //kiemke.NgayKiemKe = DateTime.Parse(new Common.Utilities().KiemTraDinhDangNgayThangNam("ThangNgayNam", makNgaychungtu.Text, '/')); kiemke.Tenkho = cbxKhoban.Text; kiemke.GhiChu = new Common.Utilities().FormatMoney(Double.Parse(txtTienhang.Text)); kiemke.Hanhdong = "Hóa Đơn Kiểm Kê Kho"; Entities.ThongTinCongTy conty = Congty(""); if (row.Length > 0 && kiemke != null && conty != null) { frmBaoCaoNhapHang frm = new frmBaoCaoNhapHang("In", Common.Utilities.User.TenNhanVien, row, kiemke, conty, string.Empty); frm.ShowDialog(); } else { MessageBox.Show("Không có dữ liệu"); return; } } catch (Exception ex) { string s = ex.Message; } }
/// <summary> /// hungvv them moi row ============================================================================== /// </summary> private void LayGiaTri(DataGridView dgv, Entities.ThongTinKiemKeKho themmoi) { try { ArrayList arr = new ArrayList(); Entities.ThongTinKiemKeKho[] list = null; if (dgv.RowCount > 0) { int count = dgv.RowCount; list = new Entities.ThongTinKiemKeKho[count]; Boolean check = false; for (int i = 0; i < count; i++) { Entities.ThongTinKiemKeKho row = new Entities.ThongTinKiemKeKho(); row.Mahang = dgv.Rows[i].Cells[0].Value.ToString(); row.Tenhang = dgv.Rows[i].Cells[1].Value.ToString(); string thucte = "0"; string chenh = "0"; string giachenh = "0"; if (dgv.Rows[i].Cells[0].Value.ToString() == themmoi.Mahang) { check = true; thucte = (Double.Parse(dgv.Rows[i].Cells[3].Value.ToString()) + Double.Parse(themmoi.Tonthucte)).ToString(); chenh = (Double.Parse(dgv.Rows[i].Cells[2].Value.ToString()) - Double.Parse(thucte)).ToString(); giachenh = new Common.Utilities().FormatMoney(Double.Parse(chenh) * Double.Parse(dgv.Rows[i].Cells[6].Value.ToString())).ToString(); } else { thucte = Double.Parse(dgv.Rows[i].Cells[3].Value.ToString()).ToString(); chenh = dgv.Rows[i].Cells[4].Value.ToString(); giachenh = new Common.Utilities().FormatMoney(Double.Parse(dgv.Rows[i].Cells[7].Value.ToString())).ToString(); } row.Tonsosach = dgv.Rows[i].Cells[2].Value.ToString(); row.Tonthucte = thucte; row.Chenhlech = chenh.ToString(); row.Lydo = dgv.Rows[i].Cells[5].Value.ToString(); row.Giavon = new Common.Utilities().FormatMoney(Double.Parse(dgv.Rows[i].Cells[6].Value.ToString())).ToString(); row.Giachechlech = giachenh.ToString(); arr.Add(row); } if (check == false) { Entities.ThongTinKiemKeKho row = new Entities.ThongTinKiemKeKho(); row.Mahang = themmoi.Mahang; row.Tenhang = themmoi.Tenhang; row.Tonsosach = themmoi.Tonsosach; row.Tonthucte = themmoi.Tonthucte; row.Chenhlech = themmoi.Chenhlech; row.Lydo = themmoi.Lydo; row.Giavon = themmoi.Giavon; row.Giachechlech = themmoi.Giachechlech; arr.Add(row); } } else { list = new Entities.ThongTinKiemKeKho[1]; Entities.ThongTinKiemKeKho row = new Entities.ThongTinKiemKeKho(); row.Mahang = themmoi.Mahang; row.Tenhang = themmoi.Tenhang; row.Tonsosach = themmoi.Tonsosach; row.Tonthucte = themmoi.Tonthucte; row.Chenhlech = themmoi.Chenhlech; row.Lydo = themmoi.Lydo; row.Giavon = themmoi.Giavon; row.Giachechlech = themmoi.Giachechlech; arr.Add(row); } int n = arr.Count; if (n == 0) { list = null; } list = new Entities.ThongTinKiemKeKho[n]; for (int i = 0; i < n; i++) { list[i] = (Entities.ThongTinKiemKeKho)arr[i]; } dgv.DataSource = null; dgv.DataSource = list; fixDatagridview(); } catch (Exception ex) { string s = ex.Message; Entities.ThongTinKiemKeKho[] lay = new Entities.ThongTinKiemKeKho[0]; dgv.DataSource = null; dgv.DataSource = lay; fixDatagridview(); } }
/// <summary> /// xoa hang hoa /// </summary> /// <param name="dgv"></param> private void getDataTable(DataGridView dgv) { try { ArrayList arr = new ArrayList(); Entities.ThongTinDatHang result; Entities.ThongTinKiemKeKho[] list = null; if (dgv.RowCount > 0 && i >= 0) { mahanghoa = toolStrip_txtTracuu.Text = dgv[0, i].Value.ToString(); toolStrip_txtTenhang.Text = dgv[1, i].Value.ToString(); var query = from item in hangHoaTrongKho where item.MaHangHoa.Trim().ToUpper().Equals(mahanghoa.Trim().ToUpper()) select item; result = query.ToArray()[0]; toolStrip_txtTonkho.Text = result.Tonkho; //int.Parse(new Common.Utilities().KhongDau(dgv[2, i].Value.ToString())).ToString(); toolStrip_txtTonThucTe.Text = int.Parse(new Common.Utilities().KhongDau(dgv[3, i].Value.ToString())).ToString(); toolStrip_txtLyDo.Text = dgv[5, i].Value.ToString(); for (int j = 0; j < dgv.RowCount; j++) { if (dgv[0, j].Value.ToString() != dgv[0, i].Value.ToString()) { Entities.ThongTinKiemKeKho row = new Entities.ThongTinKiemKeKho(); row.Mahang = dgv.Rows[j].Cells[0].Value.ToString(); row.Tenhang = "" + dgv.Rows[j].Cells[1].Value.ToString(); row.Tonsosach = new Common.Utilities().KhongDau(dgv.Rows[j].Cells[2].Value.ToString()); row.Tonthucte = new Common.Utilities().KhongDau(dgv.Rows[j].Cells[3].Value.ToString()); row.Chenhlech = Double.Parse(new Common.Utilities().KhongDau(dgv.Rows[j].Cells[4].Value.ToString())).ToString(); row.Lydo = dgv.Rows[j].Cells[5].Value.ToString(); row.Giavon = new Common.Utilities().FormatMoney(Double.Parse(new Common.Utilities().KhongDau(dgv.Rows[j].Cells[6].Value.ToString()))); row.Giachechlech = new Common.Utilities().FormatMoney(Double.Parse(new Common.Utilities().KhongDau(dgv.Rows[j].Cells[7].Value.ToString()))); arr.Add(row); } } int n = arr.Count; if (n == 0) { arr = null; } list = new Entities.ThongTinKiemKeKho[n]; for (int x = 0; x < n; x++) { list[x] = (Entities.ThongTinKiemKeKho)arr[x]; } dgv.DataSource = list; } else { list = new Entities.ThongTinKiemKeKho[0]; arr = null; dgv.DataSource = list; } fixDatagridview(); } catch (Exception ex) { string s = ex.Message; Entities.ThongTinKiemKeKho[] a = new Entities.ThongTinKiemKeKho[0]; dgv.DataSource = a; fixDatagridview(); } }
private void frmXuLy_KiemKeKho_Load(object sender, EventArgs e) { try { // Entities.CheckRefer ctxh; Entities.ThongTinKiemKeKho[] lay = new Entities.ThongTinKiemKeKho[0]; dgvInsertOrder.DataSource = lay; fixDatagridview(); string ngay = DateServer.Date().ToString("dd/MM/yyyy"); makNgaychungtu.Text = ngay; LayKhoHang(); if (hanhdong == "Insert") { toolStripStatus_Ghilai.Enabled = false; getID("KiemKeKho"); txtSochungtu.Text = makiemke; btnPDF.Enabled = false; // quy đổi đơn vị tính cl = new Server_Client.Client(); this.client = cl.Connect(Luu.IP, Luu.Ports); ctxh = new Entities.CheckRefer("QD"); clientstrem = cl.SerializeObj(this.client, "Select", ctxh); quidoidvt = new Entities.QuyDoiDonViTinh[0]; quidoidvt = (Entities.QuyDoiDonViTinh[])cl.DeserializeHepper1(clientstrem, quidoidvt); if (quidoidvt == null) { quidoidvt = new Entities.QuyDoiDonViTinh[0]; return; } } if (hanhdong == "Update") { toolStripStatus_Themmoi.Enabled = false; DoDuLieu(this.kk); if (txtSochungtu.Text.Length <= 0) { MessageBox.Show("Không tìm thấy mã kiểm kê cần sửa"); this.Close(); } btnPDF.Enabled = true; // quy đổi đơn vị tính cl = new Server_Client.Client(); this.client = cl.Connect(Luu.IP, Luu.Ports); ctxh = new Entities.CheckRefer("QD"); clientstrem = cl.SerializeObj(this.client, "Select", ctxh); quidoidvt = new Entities.QuyDoiDonViTinh[0]; quidoidvt = (Entities.QuyDoiDonViTinh[])cl.DeserializeHepper1(clientstrem, quidoidvt); if (quidoidvt == null) { quidoidvt = new Entities.QuyDoiDonViTinh[0]; return; } } // Lay Hang hoa hoa trong kho string maKho = cbxKhoban.SelectedValue.ToString().ToUpper(); cl = new Server_Client.Client(); this.client = cl.Connect(Luu.IP, Luu.Ports); Entities.TruyenGiaTri dh = new Entities.TruyenGiaTri("Select", maKho); clientstrem = cl.SerializeObj(this.client, "LayBang_HangHoaTheoMaKhoHang", dh); hangHoaTrongKho = new Entities.ThongTinDatHang[1]; hangHoaTrongKho = (Entities.ThongTinDatHang[])cl.DeserializeHepper(clientstrem, hangHoaTrongKho); } catch (Exception ex) { string s = ex.Message; if (txtSochungtu.Text == "") { txtSochungtu.Text = "KK_0001"; } } }
private void cbxKhoban_SelectedIndexChanged(object sender, EventArgs e) { try { if (this.hanhdong.Equals("Update")) return; if (dgvInsertOrder.Rows.Count > 0) { dgvInsertOrder.DataSource = null; Entities.ThongTinKiemKeKho[] lay = new Entities.ThongTinKiemKeKho[0]; dgvInsertOrder.DataSource = lay; fixDatagridview(); } toolStrip_txtTracuu.Text = "<F4 - Tra cứu>"; toolStrip_txtTenhang.Text = ""; toolStrip_txtTonkho.Text = "0"; toolStrip_txtTonThucTe.Text = "1"; toolStrip_txtLyDo.Text = "Chưa có lý do"; txtTienhang.Text = "0"; } catch (Exception ex) { string s = ex.Message; } }
private void toolStrip_txtLyDo_KeyDown(object sender, KeyEventArgs e) { try { if (e.KeyCode == Keys.Enter) { // Validate if (!Validate1()) return; // Qui đổi đơn vị tính foreach (Entities.QuyDoiDonViTinh item in quidoidvt) { if (item.MaHangQuyDoi == mahanghoa) { mahanghoa = toolStrip_txtTracuu.Text = item.MaHangDuocQuyDoi.ToUpper(); toolStrip_txtTenhang.Text = item.TenHangDuocQuyDoi; toolStrip_txtTonThucTe.Text = (double.Parse(item.SoLuongDuocQuyDoi.ToString()) * double.Parse(toolStrip_txtTonThucTe.Text)).ToString(); break; } } NewRow(); if (dgvInsertOrder.Rows.Count > 0) { txtTienhang.Text = new Common.Utilities().FormatMoney(Double.Parse(new Common.Utilities().KhongDau(tinhtong().ToString()))); } else { txtTienhang.Text = "0"; } // Forcus toolStrip_txtTracuu.Focus(); toolStrip_txtTracuu.Text = string.Empty; } } catch (Exception ex) { string s = ex.Message; Entities.ThongTinKiemKeKho[] lay = new Entities.ThongTinKiemKeKho[0]; dgvInsertOrder.DataSource = null; dgvInsertOrder.DataSource = lay; fixDatagridview(); } }
/// <summary> /// them hang moi /// </summary> private void NewRow() { Entities.ThongTinKiemKeKho chitiet = new Entities.ThongTinKiemKeKho(); try { if (cbxKhoban.SelectedValue.ToString() != "") { chitiet.Mahang = toolStrip_txtTracuu.Text.ToUpper(); string thongbao = toolStrip_txtTenhang.Text; //KiemTraMa(chitiet); chitiet.Tenhang = toolStrip_txtTenhang.Text; chitiet.Tonsosach = toolStrip_txtTonkho.Text; Double thucte = Double.Parse(toolStrip_txtTonThucTe.Text); chitiet.Tonthucte = thucte.ToString(); // lay gia von var query = from item in giaVon let a = item.MaKho.Trim().ToUpper().Equals(cbxKhoban.SelectedValue.ToString()) let b = item.MaHangHoa.Trim().ToUpper().Equals(toolStrip_txtTracuu.Text.Trim().ToUpper()) where a && b select item; Entities.GiaVon[] result = query.ToArray(); Entities.GiaVon gv = null; if (result != null && result.Length > 0) gv = result[0]; double von = double.Parse(gv.Gia.ToString()); if (thucte == 0) { chitiet.Chenhlech = toolStrip_txtTonkho.Text; chitiet.Giavon = new Common.Utilities().FormatMoney(von); chitiet.Giachechlech = new Common.Utilities().FormatMoney(von); } else { chitiet.Chenhlech = Math.Abs(thucte - Double.Parse(new Common.Utilities().KhongDau(toolStrip_txtTonkho.Text))).ToString(); chitiet.Giavon = new Common.Utilities().FormatMoney(von); chitiet.Giachechlech = new Common.Utilities().FormatMoney(von * Math.Abs(thucte - Double.Parse(new Common.Utilities().KhongDau(toolStrip_txtTonkho.Text)))).ToString(); } chitiet.Lydo = toolStrip_txtLyDo.Text; if (thongbao == "NO") { MessageBox.Show("Mã hàng không đúng"); toolStrip_txtTracuu.Focus(); return; } else { if (chitiet.Tenhang.Length > 0) { LayGiaTri(dgvInsertOrder, chitiet); ResetTool(); } else { MessageBox.Show("Phải nhập hàng hóa mới có thể thêm"); } } } else { ResetTool(); MessageBox.Show("Chọn kho hàng"); return; } } catch (Exception ex) { string s = ex.ToString(); Entities.ThongTinKiemKeKho[] lay = new Entities.ThongTinKiemKeKho[0]; dgvInsertOrder.DataSource = null; dgvInsertOrder.DataSource = lay; fixDatagridview(); } }