private void bbiLuu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                if (!Check())
                {
                    return;
                }

                if (tinh_trang == "them")
                {
                    KHO_HANG kho = new KHO_HANG();

                    kho.Ma_Kho     = txtMaKho.Text;
                    kho.Ten_Kho    = txtTenKho.Text;
                    kho.Dia_Chi    = txtDiaChi.Text;
                    kho.Email      = txtEmail.Text;
                    kho.Dien_Thoai = txtDienThoai.Text;

                    kho.Fax         = txtFax.Text;
                    kho.Di_Dong     = txtDiDong.Text;
                    kho.Thu_Kho     = txtThuKho.Text;
                    kho.Ghi_Chu     = txtGhiChu.Text;
                    kho.CreatedDate = DateTime.Now;

                    kho.IsDeleted = false;

                    db.KHO_HANGs.InsertOnSubmit(kho);
                    db.SubmitChanges();
                    RaiseSendDataEventHander(kho);
                }
                else
                {
                    var kho = (from k in db.KHO_HANGs
                               where k.Ma_Kho == txtMaKho.Text
                               select k).FirstOrDefault();

                    kho.Ma_Kho     = txtMaKho.Text;
                    kho.Ten_Kho    = txtTenKho.Text;
                    kho.Dia_Chi    = txtDiaChi.Text;
                    kho.Email      = txtEmail.Text;
                    kho.Dien_Thoai = txtDienThoai.Text;

                    kho.Fax          = txtFax.Text;
                    kho.Di_Dong      = txtDiDong.Text;
                    kho.Thu_Kho      = txtThuKho.Text;
                    kho.Ghi_Chu      = txtGhiChu.Text;
                    kho.ModifiedDate = DateTime.Now;
                    db.SubmitChanges();
                    RaiseSendDataEventHander(kho);
                }

                RaiseReloadEventHander();
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, JsonConvert.SerializeObject(ex), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void bbiLuu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                if (!Check())
                {
                    return;
                }

                if (tinh_trang == "them")
                {
                    HANG_HOA hh = new HANG_HOA();

                    hh.Ma_Hang      = txtMaHangHoa.Text;
                    hh.Ten_Hang     = txtTenHangHoa.Text;
                    hh.Nhom_Hang_Id = string.IsNullOrEmpty(txtNhomHang.Text) ? 0 : Convert.ToInt64(txtNhomHang.EditValue);
                    hh.Don_Vi       = txtDonVi.Text;
                    hh.Ghi_Chu      = txtGhiChu.Text;

                    hh.IsDeleted   = false;
                    hh.CreatedDate = DateTime.Now;

                    db.HANG_HOAs.InsertOnSubmit(hh);
                    db.SubmitChanges();
                    RaiseSendDataEventHander(hh);
                }
                else
                {
                    var hh = (from h in db.HANG_HOAs
                              where h.Id == this.Id
                              select h).FirstOrDefault();

                    hh.Ma_Hang      = txtMaHangHoa.Text;
                    hh.Ten_Hang     = txtTenHangHoa.Text;
                    hh.Nhom_Hang_Id = string.IsNullOrEmpty(txtNhomHang.Text) ? 0 : Convert.ToInt64(txtNhomHang.EditValue);
                    hh.Don_Vi       = txtDonVi.Text;
                    hh.Ghi_Chu      = txtGhiChu.Text;

                    hh.ModifiedDate = DateTime.Now;

                    db.SubmitChanges();
                    RaiseSendDataEventHander(hh);
                }
                RaiseReloadEventHander();
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, JsonConvert.SerializeObject(ex), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#3
0
        public void CalculateWareHouse(Data_QLKDataContext db, decimal quantity, long productId, string batch, string serialNo, long warehouseId, int type) //1: nhap, 2 xuat
        {
            try
            {
                if (quantity != 0 && productId != 0)
                {
                    if (warehouseId != 0)
                    {
                        var tonkho = (from tk in db.TON_KHOs
                                      where tk.Vat_Tu_Id == productId &&
                                      tk.Kho_Id == warehouseId &&
                                      tk.Lo_Vat_Tu == batch &&
                                      tk.Serial_No == serialNo &&
                                      !tk.IsDeleted.Value
                                      select tk).FirstOrDefault();

                        if (tonkho != null)
                        {
                            if (type == 1)
                            {
                                tonkho.So_Luong += quantity;
                            }
                            else
                            {
                                tonkho.So_Luong -= quantity;
                            }
                            tonkho.ModifiedDate = DateTime.Now;
                        }
                        else
                        {
                            var item = new TON_KHO();
                            item.CreatedDate = DateTime.Now;
                            item.IsDeleted   = false;
                            item.Kho_Id      = warehouseId;
                            item.Lo_Vat_Tu   = batch;
                            item.Serial_No   = serialNo;
                            if (type == 1)
                            {
                                item.So_Luong = quantity;
                            }
                            else
                            {
                                item.So_Luong = (quantity * -1);
                            }
                            item.Vat_Tu_Id = productId;

                            db.TON_KHOs.InsertOnSubmit(item);
                        }
                        db.SubmitChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void bbiLuu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (!Kiem_Tra())
            {
                return;
            }

            try
            {
                if (tinh_trang == "them")
                {
                    THU_CHI thuchi = new THU_CHI();

                    thuchi.Ma_Chung_Tu       = txtMaChungTu.Text;
                    thuchi.Ngay              = txtNgay.DateTime;
                    thuchi.Ma_Khach_Hang     = string.IsNullOrEmpty(txtKhachHang.Text) ? "" : txtKhachHang.EditValue.ToString();
                    thuchi.Ten_Khach_Hang    = txtKhachHang.Text;
                    thuchi.Dia_Chi           = txtDiaChi.Text;
                    thuchi.So_Tien           = txtSoTien.Value;
                    thuchi.Ly_Do             = txtLyDo.Text;
                    thuchi.Chung_Tu_Ban_Hang = txtChungTuBanHang.Text;
                    thuchi.Loai_Chung_Tu     = Convert.ToInt32(txtLoaiChungTu.EditValue);
                    thuchi.Hinh_Thuc_Cong_No = Convert.ToInt32(txtHinhThucCongNo.EditValue);
                    thuchi.Ghi_Chu           = txtGhiChu.Text;

                    db.THU_CHIs.InsertOnSubmit(thuchi);
                }
                else
                {
                    var thuchi = (from tc in db.THU_CHIs
                                  where tc.Ma_Chung_Tu == txtMaChungTu.Text
                                  select tc).FirstOrDefault();

                    thuchi.Ma_Chung_Tu       = txtMaChungTu.Text;
                    thuchi.Ngay              = txtNgay.DateTime;
                    thuchi.Ma_Khach_Hang     = string.IsNullOrEmpty(txtKhachHang.Text) ? "" : txtKhachHang.EditValue.ToString();
                    thuchi.Ten_Khach_Hang    = txtKhachHang.Text;
                    thuchi.Dia_Chi           = txtDiaChi.Text;
                    thuchi.So_Tien           = txtSoTien.Value;
                    thuchi.Ly_Do             = txtLyDo.Text;
                    thuchi.Chung_Tu_Ban_Hang = txtChungTuBanHang.Text;
                    thuchi.Loai_Chung_Tu     = Convert.ToInt32(txtLoaiChungTu.EditValue);
                    thuchi.Hinh_Thuc_Cong_No = Convert.ToInt32(txtHinhThucCongNo.EditValue);
                    thuchi.Ghi_Chu           = txtGhiChu.Text;
                }

                db.SubmitChanges();
                RaiseReloadEventHander();
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
示例#5
0
        private void bbiXoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (MessageBox.Show("Có muốn xóa không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
            {
                return;
            }

            var db = new Data_QLKDataContext(SqlHelper.ConnectionString);
            var ma = gbList.GetFocusedRowCellValue(colMa_Chung_Tu);

            if (ma == null)
            {
                return;
            }

            int[]    selectedRows = gbList.GetSelectedRows();
            string[] thuchi       = new string[selectedRows.Length];
            for (int i = selectedRows.Length; i > 0; i--)
            {
                var arg = gbList.GetRowCellValue(selectedRows[i - 1], colMa_Chung_Tu);
                if (arg == null)
                {
                    continue;
                }
                thuchi[i - 1] = arg.ToString();
            }

            var tc = from tc_ in db.THU_CHIs
                     //where k.Ma_Khu_Vuc == ma.ToString()
                     where thuchi.Contains(tc_.Ma_Chung_Tu)
                     select tc_;


            foreach (var t in tc)
            {
                db.THU_CHIs.DeleteOnSubmit(t);
            }

            try
            {
                db.SubmitChanges();
                bbiXem_ItemClick(this, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#6
0
        private void bbiXoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                if (MessageBox.Show("Có muốn xóa không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                {
                    return;
                }

                var db = new Data_QLKDataContext(SqlHelper.ConnectionString);
                var ma = gbList.GetFocusedRowCellValue(colId);
                if (ma == null)
                {
                    return;
                }

                int[]  selectedRows = gbList.GetSelectedRows();
                long[] khuvuc       = new long[selectedRows.Length];
                for (int i = selectedRows.Length; i > 0; i--)
                {
                    var arg = gbList.GetRowCellValue(selectedRows[i - 1], colId);
                    if (arg == null)
                    {
                        continue;
                    }
                    khuvuc[i - 1] = Convert.ToInt64(arg);
                }

                var kv = from k in db.KHU_VUCs
                         where khuvuc.Contains(k.Id)
                         select k;

                foreach (var k in kv)
                {
                    k.IsDeleted   = true;
                    k.DeletedDate = DateTime.Now;
                    //db.KHU_VUCs.DeleteOnSubmit(k);
                }

                db.SubmitChanges();
                bbiXem_ItemClick(this, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, JsonConvert.SerializeObject(ex), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#7
0
        private void bbiXoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                if (MessageBox.Show("Có muốn xóa không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                {
                    return;
                }

                var db = new Data_QLKDataContext(SqlHelper.ConnectionString);

                int[]  selectedRows = gbList.GetSelectedRows();
                long[] nhomhang     = new long[selectedRows.Length];
                for (int i = selectedRows.Length; i > 0; i--)
                {
                    var arg = gbList.GetRowCellValue(selectedRows[i - 1], colId);
                    if (arg == null)
                    {
                        continue;
                    }
                    nhomhang[i - 1] = Convert.ToInt64(arg);
                }

                var nh = from n in db.NHOM_HANGs
                         where nhomhang.Contains(n.Id)
                         select n;


                foreach (var n in nh)
                {
                    n.IsDeleted   = true;
                    n.DeletedDate = DateTime.Now;
                    //db.NHOM_HANGs.DeleteOnSubmit(n);
                }

                db.SubmitChanges();
                bbiXem_ItemClick(this, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#8
0
        private void bbiLuu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (!Check())
            {
                return;
            }

            try
            {
                if (tinh_trang == "them")
                {
                    KHU_VUC kv = new KHU_VUC();

                    kv.Ma_Khu_Vuc  = txtMaKhuVuc.Text;
                    kv.Ten_Khu_Vuc = txtTenKhuVuc.Text;
                    kv.Ghi_Chu     = txtGhiChu.Text;
                    kv.IsDeleted   = false;
                    kv.CreatedDate = DateTime.Now;

                    db.KHU_VUCs.InsertOnSubmit(kv);
                }
                else
                {
                    var kv = (from k in db.KHU_VUCs
                              where k.Id == Id
                              select k).FirstOrDefault();

                    kv.Ma_Khu_Vuc   = txtMaKhuVuc.Text;
                    kv.Ten_Khu_Vuc  = txtTenKhuVuc.Text;
                    kv.Ghi_Chu      = txtGhiChu.Text;
                    kv.ModifiedDate = DateTime.Now;
                }

                db.SubmitChanges();
                RaiseReloadEventHander();
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, JsonConvert.SerializeObject(ex), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#9
0
        private void bbiLuu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                if (!Check())
                {
                    return;
                }
                if (tinh_trang == "them")
                {
                    NHOM_HANG nh = new NHOM_HANG();

                    nh.Ma_Nhom_Hang  = txtMaNhomHang.Text;
                    nh.Ten_Nhom_Hang = txtTenNhomHang.Text;
                    nh.Ghi_Chu       = txtGhiChu.Text;
                    nh.IsDeleted     = false;
                    nh.CreatedDate   = DateTime.Now;

                    db.NHOM_HANGs.InsertOnSubmit(nh);
                }
                else
                {
                    var nh = (from n in db.NHOM_HANGs
                              where n.Ma_Nhom_Hang == txtMaNhomHang.Text
                              select n).FirstOrDefault();

                    nh.Ma_Nhom_Hang  = txtMaNhomHang.Text;
                    nh.Ten_Nhom_Hang = txtTenNhomHang.Text;
                    nh.Ghi_Chu       = txtGhiChu.Text;
                    nh.ModifiedDate  = DateTime.Now;
                }

                db.SubmitChanges();
                RaiseReloadEventHander();
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, JsonConvert.SerializeObject(ex), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#10
0
        private void bbiXoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (XtraMessageBox.Show(this, "Có muốn xóa không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }

            var db = new Data_QLKDataContext(SqlHelper.ConnectionString);

            int[]  selectedRows = gbList.GetSelectedRows();
            long[] chungtu      = new long[selectedRows.Length];
            for (int i = selectedRows.Length; i > 0; i--)
            {
                var arg = gbList.GetRowCellValue(selectedRows[i - 1], colId);
                if (arg == null)
                {
                    continue;
                }
                chungtu[i - 1] = Convert.ToInt64(arg);
            }

            var ct = from c in db.CHUNG_TUs
                     where chungtu.Contains(c.Id)
                     select c;

            foreach (var c in ct)
            {
                c.IsDeleted   = true;
                c.DeletedDate = DateTime.Now;
            }

            try
            {
                db.SubmitChanges();
                bbiXem_ItemClick(this, null);
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(this, JsonConvert.SerializeObject(ex), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#11
0
        private void bbiXoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (MessageBox.Show("Có muốn xóa không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
            {
                return;
            }

            var db = new Data_QLKDataContext(SqlHelper.ConnectionString);

            int[]    selectedRows = gbList.GetSelectedRows();
            string[] cuahang      = new string[selectedRows.Length];
            for (int i = selectedRows.Length; i > 0; i--)
            {
                var arg = gbList.GetRowCellValue(selectedRows[i - 1], colMa_Cua_Hang);
                if (arg == null)
                {
                    continue;
                }
                cuahang[i - 1] = arg.ToString();
            }

            var chs = from ch in db.CUA_HANGs
                      where cuahang.Contains(ch.Ma_Cua_Hang)
                      select ch;


            foreach (var c in chs)
            {
                db.CUA_HANGs.DeleteOnSubmit(c);
            }

            try
            {
                db.SubmitChanges();
                bbiXem_ItemClick(this, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void bbiLuu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                if (!Check())
                {
                    return;
                }

                if (tinh_trang == "them")
                {
                    NHAN_VIEN nhanvien = new NHAN_VIEN();

                    nhanvien.Ma_Nhan_Vien = txtMaNhanVien.Text;
                    nhanvien.Ho_Ten       = txtHoTen.Text;
                    nhanvien.Dia_Chi      = txtDiaChi.Text;
                    nhanvien.Nam_Sinh     = txtNamSinh.Text;
                    nhanvien.Dien_Thoai   = txtDienThoai.Text;

                    nhanvien.Ngay_Vao_Lam = txtNgayVaoLam.Text;
                    nhanvien.Chuc_Vu      = txtChucVu.Text;
                    nhanvien.Bo_Phan      = txtBoPhan.Text;
                    nhanvien.Ghi_Chu      = txtGhiChu.Text;
                    nhanvien.IsDeleted    = false;

                    nhanvien.CreatedDate = DateTime.Now;

                    db.NHAN_VIENs.InsertOnSubmit(nhanvien);
                    db.SubmitChanges();
                    RaiseSendDataEventHander(nhanvien);
                }
                else
                {
                    var nhanvien = (from nv in db.NHAN_VIENs
                                    where nv.Id == this.Id
                                    select nv).FirstOrDefault();

                    nhanvien.Ma_Nhan_Vien = txtMaNhanVien.Text;
                    nhanvien.Ho_Ten       = txtHoTen.Text;
                    nhanvien.Dia_Chi      = txtDiaChi.Text;
                    nhanvien.Nam_Sinh     = txtNamSinh.Text;
                    nhanvien.Dien_Thoai   = txtDienThoai.Text;

                    nhanvien.Ngay_Vao_Lam = txtNgayVaoLam.Text;
                    nhanvien.Chuc_Vu      = txtChucVu.Text;
                    nhanvien.Bo_Phan      = txtBoPhan.Text;
                    nhanvien.Ghi_Chu      = txtGhiChu.Text;
                    nhanvien.ModifiedDate = DateTime.Now;

                    db.SubmitChanges();
                    RaiseSendDataEventHander(nhanvien);
                }

                RaiseReloadEventHander();
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, JsonConvert.SerializeObject(ex), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void bbiLuu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                if (!Check())
                {
                    return;
                }
                if (tinh_trang == "them")
                {
                    KHACH_HANG kh = new KHACH_HANG();

                    kh.Ma_Khach_Hang  = txtMaKhachHang.Text;
                    kh.Ten_Khach_Hang = txtTenKhachHang.Text;
                    kh.Khu_Vuc_Id     = string.IsNullOrEmpty(txtKhuVuc.Text) ? 0 : Convert.ToInt64(txtKhuVuc.EditValue);
                    kh.Dia_Chi        = txtDiaChi.Text;
                    kh.Ma_So_Thue     = txtMaSoThue.Text;

                    kh.Dien_Thoai = txtDienThoai.Text;
                    kh.Fax        = txtFax.Text;
                    kh.Email      = txtEmail.Text;
                    kh.Di_Dong    = txtDiDong.Text;
                    kh.Website    = txtWebsite.Text;

                    kh.Nguoi_Lien_He       = txtNguoiLienHe.Text;
                    kh.Tai_Khoan_Ngan_Hang = txtTaiKhoanNganHang.Text;
                    kh.Ten_Ngan_Hang       = txtTenNganHang.Text;
                    kh.Ghi_Chu             = txtGhiChu.Text;
                    kh.IsDeleted           = false;

                    kh.CreatedDate = DateTime.Now;

                    db.KHACH_HANGs.InsertOnSubmit(kh);
                    db.SubmitChanges();
                    RaiseSendDataEventHander(kh);
                }
                else
                {
                    var kh = (from k in db.KHACH_HANGs
                              where k.Id == this.Id
                              select k).FirstOrDefault();

                    kh.Ma_Khach_Hang  = txtMaKhachHang.Text;
                    kh.Ten_Khach_Hang = txtTenKhachHang.Text;
                    kh.Khu_Vuc_Id     = string.IsNullOrEmpty(txtKhuVuc.Text) ? 0 : Convert.ToInt64(txtKhuVuc.EditValue);
                    kh.Dia_Chi        = txtDiaChi.Text;
                    kh.Ma_So_Thue     = txtMaSoThue.Text;

                    kh.Dien_Thoai = txtDienThoai.Text;
                    kh.Fax        = txtFax.Text;
                    kh.Email      = txtEmail.Text;
                    kh.Di_Dong    = txtDiDong.Text;
                    kh.Website    = txtWebsite.Text;

                    kh.Nguoi_Lien_He       = txtNguoiLienHe.Text;
                    kh.Tai_Khoan_Ngan_Hang = txtTaiKhoanNganHang.Text;
                    kh.Ten_Ngan_Hang       = txtTenNganHang.Text;
                    kh.Ghi_Chu             = txtGhiChu.Text;

                    kh.ModifiedDate = DateTime.Now;
                    db.SubmitChanges();
                    RaiseSendDataEventHander(kh);
                }

                RaiseReloadEventHander();
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, JsonConvert.SerializeObject(ex), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#14
0
        private void bbiLuu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gbList.FocusedRowHandle += 1;
            gbList.UpdateCurrentRow();

            if (!Kiem_Tra())
            {
                return;
            }

            Data_QLKDataContext database = new Data_QLKDataContext(SqlHelper.ConnectionString);

            try
            {
                database.Connection.Open();
                System.Data.Common.DbTransaction transaction = database.Connection.BeginTransaction();
                database.Transaction = transaction;

                long chungTuId = 0;

                if (tinh_trang == "them")
                {
                    CHUNG_TU chung_tu = new CHUNG_TU();

                    chung_tu.Ma_Chung_Tu   = txtMaChungTu.Text;
                    chung_tu.Ngay          = txtNgay.DateTime;
                    chung_tu.Loai_Chung_Tu = this.loai; //1 la nhap kho 2 la xuat kho
                    chung_tu.Ly_Do         = txtLyDo.Text;
                    chung_tu.Ghi_Chu       = txtGhiChu.Text;
                    chung_tu.CreateDate    = DateTime.Now;
                    chung_tu.IsDeleted     = false;
                    if (loai == 1)
                    {
                        chung_tu.Dau_Ky = cbNhapDauKy.Checked;
                    }

                    database.CHUNG_TUs.InsertOnSubmit(chung_tu);
                    database.SubmitChanges();
                    chungTuId = chung_tu.Id;
                }
                else
                {
                    var chung_tu = (from ct in database.CHUNG_TUs
                                    where ct.Id == this.id
                                    select ct).FirstOrDefault();

                    chung_tu.Ma_Chung_Tu   = txtMaChungTu.Text;
                    chung_tu.Ngay          = txtNgay.DateTime;
                    chung_tu.Loai_Chung_Tu = this.loai; //1 la nhap kho 2 la xuat kho
                    chung_tu.Ly_Do         = txtLyDo.Text;
                    chung_tu.Ghi_Chu       = txtGhiChu.Text;
                    chung_tu.ModifiedDate  = DateTime.Now;
                    if (loai == 1)
                    {
                        chung_tu.Dau_Ky = cbNhapDauKy.Checked;
                    }

                    chungTuId = chung_tu.Id;
                }


                if (Luu_Chi_Tiet(database, chungTuId) == "OK")
                {
                    database.SubmitChanges();
                    database.Transaction.Commit();
                    RaiseReloadEventHander();
                    Close();
                }
                else
                {
                    database.Transaction.Rollback();
                }
            }
            catch (Exception ex)
            {
                database.Transaction.Rollback();
                XtraMessageBox.Show(this, JsonConvert.SerializeObject(ex), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#15
0
        string Luu_Chi_Tiet(Data_QLKDataContext database, long chungTuId)
        {
            var  result = "OK";
            var  dt     = dsNhapVatTu.CHUNG_TU_CHI_TIET;
            long id     = 0;
            var  row    = 0;
            CalulateInventory calulateInventory = new CalulateInventory();

            long    vatTuId    = 0;
            long    khoNhap    = 0;
            long    khoXuat    = 0;
            decimal soLuong    = 0;
            string  loVatTu    = "";
            string  serialNo   = "";
            decimal orgSoLuong = 0;

            for (var i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i].RowState != DataRowState.Deleted)
                {
                    row++;

                    if (dt.Rows[i]["Hang_Hoa_Id"] == DBNull.Value || Convert.ToInt64(dt.Rows[i]["Hang_Hoa_Id"]) == 0)
                    {
                        MessageBox.Show(this, String.Format("Dòng {0}: Vui lòng chọn mặt hàng.", row.ToString()), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);

                        result = "Chưa chọn mặt hàng";
                        gbList.FocusedRowHandle = row;
                        gbList.SetColumnError(colMa_Hang_Hoa, "Chưa chọn mặt hàng");
                        return(result);
                    }

                    if (dt.Rows[i]["Kho_Hang_Id"] == DBNull.Value || Convert.ToInt64(dt.Rows[i]["Kho_Hang_Id"]) == 0)
                    {
                        MessageBox.Show(this, String.Format("Dòng {0}: Vui lòng chọn kho hàng.", row.ToString()), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);

                        result = "Chưa chọn kho hàng";
                        gbList.FocusedRowHandle = row;
                        gbList.SetColumnError(colMa_Kho_Hang, "Chưa chọn kho hàng");
                        return(result);
                    }

                    id = Convert.ToInt64(dt.Rows[i]["Id"]);
                }
                var dr = dt.Rows[i];
                switch (dr.RowState)
                {
                case DataRowState.Added:

                    var chi_tiet_them = new CHUNG_TU_CHI_TIET();

                    chi_tiet_them.Chung_Tu_Id   = chungTuId;
                    chi_tiet_them.Hang_Hoa_Id   = Convert.ToInt64(dt.Rows[i]["Hang_Hoa_Id"]);
                    chi_tiet_them.Ma_Hang_Hoa   = dt.Rows[i]["Ma_Hang_Hoa"].ToString();
                    chi_tiet_them.Ten_Hang_Hoa  = dt.Rows[i]["Ten_Hang_Hoa"].ToString();
                    chi_tiet_them.Loai_Chung_Tu = this.loai; //1 nhap kho 2 xuat kho

                    chi_tiet_them.Tinh_Trang  = true;        //true nhap kho false xuat kho
                    chi_tiet_them.Kho_Hang_Id = Convert.ToInt64(dt.Rows[i]["Kho_Hang_Id"]);
                    chi_tiet_them.Ma_Kho_Hang = dt.Rows[i]["Ma_Kho_Hang"].ToString();
                    chi_tiet_them.So_Luong    = Convert.ToDecimal(dt.Rows[i]["So_Luong"]);
                    chi_tiet_them.Ghi_Chu     = dt.Rows[i]["Ghi_Chu"].ToString();

                    chi_tiet_them.Serial_No     = dt.Rows[i]["Serial_No"].ToString();
                    chi_tiet_them.Lo_Vat_Tu     = dt.Rows[i]["Lo_Vat_Tu"].ToString();
                    chi_tiet_them.Don_Vi        = dt.Rows[i]["Don_Vi"].ToString();
                    chi_tiet_them.Nhan_Vien_Id  = Convert.ToInt64(dt.Rows[i]["Nhan_Vien_Id"] == DBNull.Value ? 0 : dt.Rows[i]["Nhan_Vien_Id"]);
                    chi_tiet_them.Khach_Hang_Id = Convert.ToInt64(dt.Rows[i]["Khach_Hang_Id"] == DBNull.Value ? 0 : dt.Rows[i]["Khach_Hang_Id"]);

                    chi_tiet_them.So_Thu_Tu   = i;
                    chi_tiet_them.CreatedDate = DateTime.Now;

                    database.CHUNG_TU_CHI_TIETs.InsertOnSubmit(chi_tiet_them);

                    if (this.loai == 1)
                    {
                        khoNhap = chi_tiet_them.Kho_Hang_Id.Value;
                    }
                    else
                    {
                        khoXuat = chi_tiet_them.Kho_Hang_Id.Value;
                    }
                    vatTuId  = chi_tiet_them.Hang_Hoa_Id.Value;
                    soLuong  = chi_tiet_them.So_Luong.Value;
                    loVatTu  = chi_tiet_them.Lo_Vat_Tu;
                    serialNo = chi_tiet_them.Serial_No;


                    break;

                case DataRowState.Modified:

                    var chi_tiet_sua = (from ctct in database.CHUNG_TU_CHI_TIETs
                                        where ctct.Id == id
                                        select ctct).FirstOrDefault();

                    chi_tiet_sua.Chung_Tu_Id   = chungTuId;
                    chi_tiet_sua.Hang_Hoa_Id   = Convert.ToInt64(dt.Rows[i]["Hang_Hoa_Id"]);
                    chi_tiet_sua.Ma_Hang_Hoa   = dt.Rows[i]["Ma_Hang_Hoa"].ToString();
                    chi_tiet_sua.Ten_Hang_Hoa  = dt.Rows[i]["Ma_Hang_Hoa"].ToString();
                    chi_tiet_sua.Loai_Chung_Tu = this.loai; //1 nhap kho 2 xuat kho

                    chi_tiet_sua.Tinh_Trang  = true;        //true nhap kho false xuat kho
                    chi_tiet_sua.Kho_Hang_Id = Convert.ToInt64(dt.Rows[i]["Kho_Hang_Id"]);
                    chi_tiet_sua.Ma_Kho_Hang = dt.Rows[i]["Ma_Kho_Hang"].ToString();
                    chi_tiet_sua.So_Luong    = Convert.ToDecimal(dt.Rows[i]["So_Luong"]);
                    chi_tiet_sua.Ghi_Chu     = dt.Rows[i]["Ghi_Chu"].ToString();

                    chi_tiet_sua.Serial_No     = dt.Rows[i]["Serial_No"].ToString();
                    chi_tiet_sua.Lo_Vat_Tu     = dt.Rows[i]["Lo_Vat_Tu"].ToString();
                    chi_tiet_sua.Don_Vi        = dt.Rows[i]["Don_Vi"].ToString();
                    chi_tiet_sua.Nhan_Vien_Id  = Convert.ToInt64(dt.Rows[i]["Nhan_Vien_Id"] == DBNull.Value ? 0 : dt.Rows[i]["Nhan_Vien_Id"]);
                    chi_tiet_sua.Khach_Hang_Id = Convert.ToInt64(dt.Rows[i]["Khach_Hang_Id"] == DBNull.Value ? 0 : dt.Rows[i]["Khach_Hang_Id"]);

                    chi_tiet_sua.So_Thu_Tu    = i;
                    chi_tiet_sua.ModifiedDate = DateTime.Now;

                    orgSoLuong = Convert.ToDecimal(dt.Rows[i]["So_Luong", DataRowVersion.Original]);

                    if (this.loai == 1)
                    {
                        khoNhap = chi_tiet_sua.Kho_Hang_Id.Value;
                    }
                    else
                    {
                        khoXuat = chi_tiet_sua.Kho_Hang_Id.Value;
                    }
                    vatTuId  = chi_tiet_sua.Hang_Hoa_Id.Value;
                    soLuong  = chi_tiet_sua.So_Luong.Value - orgSoLuong;
                    loVatTu  = chi_tiet_sua.Lo_Vat_Tu;
                    serialNo = chi_tiet_sua.Serial_No;

                    break;

                case DataRowState.Deleted:
                    var idDetail     = Convert.ToInt64(dt.Rows[i]["Id", DataRowVersion.Original]); //dt.Rows[i]["Ma_Chi_Tiet", DataRowVersion.Original];
                    var chi_tiet_xoa = (from ctct in database.CHUNG_TU_CHI_TIETs
                                        where ctct.Id == idDetail
                                        select ctct).FirstOrDefault();
                    chi_tiet_xoa.IsDeleted     = true;
                    chi_tiet_xoa.DeletetedDate = DateTime.Now;

                    orgSoLuong = Convert.ToDecimal(dt.Rows[i]["So_Luong", DataRowVersion.Original]);

                    if (this.loai == 1)
                    {
                        khoNhap = chi_tiet_xoa.Kho_Hang_Id.Value;
                    }
                    else
                    {
                        khoXuat = chi_tiet_xoa.Kho_Hang_Id.Value;
                    }
                    vatTuId  = chi_tiet_xoa.Hang_Hoa_Id.Value;
                    soLuong  = chi_tiet_xoa.So_Luong.Value - orgSoLuong;
                    loVatTu  = chi_tiet_xoa.Lo_Vat_Tu;
                    serialNo = chi_tiet_xoa.Serial_No;
                    //database.CHUNG_TU_CHI_TIETs.DeleteOnSubmit(chi_tiet_xoa);
                    break;
                }
                database.SubmitChanges();
                calulateInventory.ProcessCalculate(database, soLuong, vatTuId, loVatTu, serialNo, khoNhap, khoXuat);
            }
            return(result);
        }
示例#16
0
        string Luu_Chi_Tiet(Data_QLKDataContext database, long chungTuId)
        {
            var  result = "OK";
            var  dt     = dsXuatKho.CHUNG_TU_CHI_TIET;
            long id     = 0;
            var  row    = 0;

            for (var i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i].RowState != DataRowState.Deleted)
                {
                    row++;

                    if (dt.Rows[i]["Ma_Hang_Hoa"] == DBNull.Value)
                    {
                        MessageBox.Show("Vui lòng chọn mặt hàng.", "Thông báo",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);

                        result = "Chưa chọn mặt hàng";
                        gbList.FocusedRowHandle = row;
                        gbList.SetColumnError(colMa_Hang_Hoa, "Chưa chọn mặt hàng");
                        return(result);
                    }

                    if (dt.Rows[i]["Ma_Kho_Hang"] == DBNull.Value)
                    {
                        MessageBox.Show("Chưa chọn kho hàng.", "Thông báo",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);

                        result = "Chưa chọn kho hàng";
                        gbList.FocusedRowHandle = row;
                        gbList.SetColumnError(colMa_Kho_Hang, "Chưa chọn kho hàng");
                        return(result);
                    }

                    id = Convert.ToInt64(dt.Rows[i]["Ma_Chi_Tiet"]);
                }
                var dr = dt.Rows[i];
                switch (dr.RowState)
                {
                case DataRowState.Added:

                    var chung_tu_chi_tiet = new CHUNG_TU_CHI_TIET
                    {
                        Chung_Tu_Id   = chungTuId,
                        Ma_Hang_Hoa   = dt.Rows[i]["Ma_Hang_Hoa"].ToString(),
                        Loai_Chung_Tu = 2,     //1 nhap kho 2 xuat kho
                        Tinh_Trang    = false, //true nhap kho false xuat kho
                        Ma_Kho_Hang   = dt.Rows[i]["Ma_Kho_Hang"].ToString(),
                        So_Luong      = Convert.ToDecimal(dt.Rows[i]["So_Luong"]),
                        Don_Gia       = Convert.ToDecimal(dt.Rows[i]["Don_Gia"]),
                        Thanh_Tien    = Convert.ToDecimal(dt.Rows[i]["Thanh_Tien"]),
                        Ghi_Chu       = dt.Rows[i]["Ghi_Chu"].ToString(),
                        So_Thu_Tu     = 0
                    };
                    database.CHUNG_TU_CHI_TIETs.InsertOnSubmit(chung_tu_chi_tiet);

                    break;

                case DataRowState.Modified:

                    var chi_tiet_sua = (from ctct in database.CHUNG_TU_CHI_TIETs
                                        where ctct.Id == id
                                        select ctct).FirstOrDefault();

                    //chi_tiet_sua.Ma_Chi_Tiet = new Guid(id);
                    chi_tiet_sua.Chung_Tu_Id   = chungTuId;
                    chi_tiet_sua.Ma_Hang_Hoa   = dt.Rows[i]["Ma_Hang_Hoa"].ToString();
                    chi_tiet_sua.Loai_Chung_Tu = 2;     //1 nhap kho 2 xuat kho
                    chi_tiet_sua.Tinh_Trang    = false; //true nhap kho false xuat kho
                    chi_tiet_sua.Ma_Kho_Hang   = dt.Rows[i]["Ma_Kho_Hang"].ToString();
                    chi_tiet_sua.So_Luong      = Convert.ToDecimal(dt.Rows[i]["So_Luong"]);
                    chi_tiet_sua.Don_Gia       = Convert.ToDecimal(dt.Rows[i]["Don_Gia"]);
                    chi_tiet_sua.Thanh_Tien    = Convert.ToDecimal(dt.Rows[i]["Thanh_Tien"]);
                    chi_tiet_sua.Ghi_Chu       = dt.Rows[i]["Ghi_Chu"].ToString();
                    chi_tiet_sua.So_Thu_Tu     = 0;
                    break;

                case DataRowState.Deleted:
                    var chi_tiet_xoa = (from ctct in database.CHUNG_TU_CHI_TIETs
                                        where ctct.Id == id
                                        select ctct).FirstOrDefault();
                    database.CHUNG_TU_CHI_TIETs.DeleteOnSubmit(chi_tiet_xoa);
                    break;
                }
                database.SubmitChanges();
            }
            return(result);
        }
示例#17
0
        private void bbiLuu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gbList.FocusedRowHandle += 1;
            gbList.UpdateCurrentRow();

            if (!Kiem_Tra())
            {
                return;
            }

            Data_QLKDataContext database = new Data_QLKDataContext(SqlHelper.ConnectionString);

            try
            {
                database.Connection.Open();
                System.Data.Common.DbTransaction transaction = database.Connection.BeginTransaction();
                database.Transaction = transaction;

                if (tinh_trang == "them")
                {
                    CHUNG_TU chung_tu = new CHUNG_TU
                    {
                        Ma_Chung_Tu           = txtMaChungTu.Text,
                        Ma_Hoa_Don            = txtMaHoaDon.Text,
                        Ngay                  = txtNgay.DateTime,
                        Loai_Chung_Tu         = 2, //1 la nhap kho 2 la xuat kho
                        Ma_Khach_Hang         = string.IsNullOrEmpty(txtKhachHang.Text) ? "" : txtKhachHang.EditValue.ToString(),
                        Dia_Chi               = txtDiaChi.Text,
                        Ly_Do                 = txtLyDo.Text,
                        VAT_Phan_Tram         = txtVATPhanTram.Value,
                        VAT_Thanh_Tien        = txtVATThanhTien.Value,
                        Chiet_Khau_Phan_Tram  = txtChietKhauPhanTram.Value,
                        Chiet_Khau_Thanh_Tien = txtChietKhauThanhTien.Value,
                        Thanh_Tien            = txtThanhTien.Value,
                        Hinh_Thuc_Cong_No     = Convert.ToInt32(txtHinhThucCongNo.EditValue),
                        Hinh_Thuc_Thu_Chi     = Convert.ToInt32(txtHinhThucThuChi.EditValue),
                        Thanh_Toan            = txtThanhToan.Value,
                        Ghi_Chu               = txtGhiChu.Text,
                        Nhan_Vien             = string.IsNullOrEmpty(txtNhanVien.Text) ? "" : txtNhanVien.EditValue.ToString(),
                        So_Thu_Tu             = 0
                    };
                    database.CHUNG_TUs.InsertOnSubmit(chung_tu);
                }
                else
                {
                    var chung_tu = (from ct in database.CHUNG_TUs
                                    where ct.Ma_Chung_Tu == txtMaChungTu.Text
                                    select ct).FirstOrDefault();

                    chung_tu.Ma_Chung_Tu           = txtMaChungTu.Text;
                    chung_tu.Ma_Hoa_Don            = txtMaHoaDon.Text;
                    chung_tu.Ngay                  = txtNgay.DateTime;
                    chung_tu.Loai_Chung_Tu         = 2; //1 la nhap kho 2 la xuat kho
                    chung_tu.Ma_Khach_Hang         = string.IsNullOrEmpty(txtKhachHang.Text) ? "" : txtKhachHang.EditValue.ToString();
                    chung_tu.Dia_Chi               = txtDiaChi.Text;
                    chung_tu.Ly_Do                 = txtLyDo.Text;
                    chung_tu.VAT_Phan_Tram         = txtVATPhanTram.Value;
                    chung_tu.VAT_Thanh_Tien        = txtVATThanhTien.Value;
                    chung_tu.Chiet_Khau_Phan_Tram  = txtChietKhauPhanTram.Value;
                    chung_tu.Chiet_Khau_Thanh_Tien = txtChietKhauThanhTien.Value;
                    chung_tu.Thanh_Tien            = txtThanhTien.Value;
                    chung_tu.Hinh_Thuc_Cong_No     = Convert.ToInt32(txtHinhThucCongNo.EditValue);
                    chung_tu.Hinh_Thuc_Thu_Chi     = Convert.ToInt32(txtHinhThucThuChi.EditValue);
                    chung_tu.Thanh_Toan            = txtThanhToan.Value;
                    chung_tu.Ghi_Chu               = txtGhiChu.Text;
                    chung_tu.Nhan_Vien             = string.IsNullOrEmpty(txtNhanVien.Text) ? "" : txtNhanVien.EditValue.ToString();
                    chung_tu.So_Thu_Tu             = 0;
                }


                if (Luu_Chi_Tiet(database, 0) == "OK")
                {
                    database.SubmitChanges();
                    database.Transaction.Commit();
                    RaiseReloadEventHander();
                    Close();
                }
                else
                {
                    database.Transaction.Rollback();
                }
            }
            catch (Exception ex)
            {
                database.Transaction.Rollback();
                MessageBox.Show(ex.ToString());
            }
        }
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (!Check())
            {
                return;
            }

            try
            {
                if (tinh_trang == "them")
                {
                    CUA_HANG cuahang = new CUA_HANG();

                    cuahang.Ma_Cua_Hang  = txtMaCuaHang.Text;
                    cuahang.Ten_Cua_Hang = txtTenCuaHang.Text;
                    cuahang.Dia_Chi      = txtDiaChi.Text;
                    cuahang.Ma_So_Thue   = txtMaSoThue.Text;
                    cuahang.Dien_Thoai   = txtDienThoai.Text;
                    cuahang.Email        = txtEmail.Text;
                    cuahang.Fax          = txtFax.Text;
                    cuahang.Di_Dong      = txtDiDong.Text;
                    cuahang.Quan_Ly      = txtQuanLy.Text;
                    cuahang.Ghi_Chu      = txtGhiChu.Text;

                    if (picAnh.Image != null)
                    {
                        Image        anh = picAnh.Image;
                        MemoryStream ms  = new MemoryStream();
                        anh.Save(ms, anh.RawFormat);
                        byte[] anh_Bytes = ms.GetBuffer();
                        ms.Close();

                        cuahang.Anh = anh_Bytes;
                    }

                    db.CUA_HANGs.InsertOnSubmit(cuahang);
                }
                else
                {
                    var cuahang = (from ch in db.CUA_HANGs
                                   where ch.Ma_Cua_Hang == txtMaCuaHang.Text
                                   select ch).FirstOrDefault();

                    cuahang.Ma_Cua_Hang  = txtMaCuaHang.Text;
                    cuahang.Ten_Cua_Hang = txtTenCuaHang.Text;
                    cuahang.Dia_Chi      = txtDiaChi.Text;
                    cuahang.Ma_So_Thue   = txtMaSoThue.Text;
                    cuahang.Dien_Thoai   = txtDienThoai.Text;
                    cuahang.Email        = txtEmail.Text;
                    cuahang.Fax          = txtFax.Text;
                    cuahang.Di_Dong      = txtDiDong.Text;
                    cuahang.Quan_Ly      = txtQuanLy.Text;
                    cuahang.Ghi_Chu      = txtGhiChu.Text;

                    if (picAnh.Image != null)
                    {
                        Image        anh = picAnh.Image;
                        MemoryStream ms  = new MemoryStream();
                        anh.Save(ms, anh.RawFormat);
                        byte[] anh_Bytes = ms.GetBuffer();
                        ms.Close();

                        cuahang.Anh = anh_Bytes;
                    }
                    else
                    {
                        cuahang.Anh = null;
                    }
                }

                db.SubmitChanges();
                RaiseReloadEventHander();
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }