Example #1
0
 public frmTonKho()
 {
     InitializeComponent();
     db = new Data_QLKDataContext(SqlHelper.ConnectionString);
     Danh_Sach_Kho_Hang();
     bbiXem_ItemClick(this, null);
 }
Example #2
0
        private void Nap_Danh_Sach_Kho_Hang()
        {
            try
            {
                var db       = new Data_QLKDataContext(SqlHelper.ConnectionString);
                var khoHangs = (from kh in db.KHO_HANGs
                                select kh).ToList();

                var tatCa = new KHO_HANG();
                tatCa.Id      = 0;
                tatCa.Ma_Kho  = "(All)";
                tatCa.Ten_Kho = "Tất cả";

                //khoHangs.Add(tatCa);
                khoHangs.Insert(0, tatCa);

                txtKhoHang.Properties.DataSource = khoHangs;
                if (khoHangs.Count() > 0)
                {
                    txtKhoHang.EditValue = khoHangs.FirstOrDefault().Id;
                }
                txtKhoHang_View.BestFitColumns();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, JsonConvert.SerializeObject(ex), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #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;
            }
        }
Example #4
0
 public void ProcessCalculate(Data_QLKDataContext db, decimal quantity, long productId, string batch, string serialNo, long warehouseId_From, long warehouseId_To)
 {
     try
     {
         CalculateWareHouse(db, quantity, productId, batch, serialNo, warehouseId_From, 1);
         CalculateWareHouse(db, quantity, productId, batch, serialNo, warehouseId_To, 2);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #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);
            }
        }
Example #6
0
 public frmXuatKho()
 {
     InitializeComponent();
     bm.SetPopupContextMenu(gcList, pm);
     Khach_Hang();
     Hang_Hoa();
     Kho_Hang();
     Nhan_Vien();
     Nap_Hinh_Thuc_Thu_Chi();
     Nap_Hinh_Thuc_Cong_No();
     db = new Data_QLKDataContext(SqlHelper.ConnectionString);
     bbiTaoMoi_ItemClick(this, null);
     _mColumn   = new Column();
     _mColumn   = Column.None;
     tinh_trang = "them";
 }
Example #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);
                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);
            }
        }
Example #8
0
        public frmNhapKho(string ma)
        {
            InitializeComponent();
            bm.SetPopupContextMenu(gcList, pm);

            Khach_Hang();
            Hang_Hoa();
            Kho_Hang();
            Nhan_Vien();
            Nap_Hinh_Thuc_Thu_Chi();
            Nap_Hinh_Thuc_Thanh_Toan();

            db = new Data_QLKDataContext(SqlHelper.ConnectionString);
            bbiTaoMoi_ItemClick(this, null);
            _mColumn   = new Column();
            _mColumn   = Column.None;
            tinh_trang = "sua";

            var ct = (from c in db.CHUNG_TUs
                      where c.Ma_Chung_Tu == ma
                      select c).FirstOrDefault();

            txtMaChungTu.Text = ct.Ma_Chung_Tu;
            txtMaChungTu.Properties.ReadOnly = true;
            txtMaHoaDon.Text            = ct.Ma_Hoa_Don;
            txtNgay.EditValue           = ct.Ngay;
            txtNhanVien.EditValue       = ct.Nhan_Vien;
            txtKhachHang.EditValue      = ct.Ma_Khach_Hang;
            txtDiaChi.Text              = ct.Dia_Chi;
            txtLyDo.Text                = ct.Ly_Do;
            txtGhiChu.Text              = ct.Ghi_Chu;
            txtChietKhauPhanTram.Value  = ct.Chiet_Khau_Phan_Tram ?? 0;
            txtVATPhanTram.Value        = ct.VAT_Phan_Tram ?? 0;
            txtChietKhauThanhTien.Value = ct.Chiet_Khau_Thanh_Tien ?? 0;
            txtVATThanhTien.Value       = ct.VAT_Thanh_Tien ?? 0;
            txtThanhTien.Value          = ct.Thanh_Tien ?? 0;
            txtHinhThucCongNo.EditValue = ct.Hinh_Thuc_Cong_No ?? 0;
            txtHinhThucThuChi.EditValue = ct.Hinh_Thuc_Thu_Chi ?? 0;
            txtThanhToan.Value          = ct.Thanh_Toan ?? 0;

            cHUNG_TU_CHI_TIETTableAdapter.Connection.ConnectionString = SqlHelper.ConnectionString;
            cHUNG_TU_CHI_TIETTableAdapter.ClearBeforeFill             = true;
            cHUNG_TU_CHI_TIETTableAdapter.Fill(dsNhapKho.CHUNG_TU_CHI_TIET, txtMaChungTu.Text);
        }
Example #9
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);
            }
        }
Example #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);
            }
        }
Example #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);
            }
        }
Example #12
0
        private void frmNhapKho_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dsNhapVatTu.VAT_TU' table. You can move, or remove it, as needed.

            try
            {
                bm.SetPopupContextMenu(gcList, pm);

                Khach_Hang();
                Hang_Hoa();
                Kho_Hang();
                Nhan_Vien();
                this.vAT_TUTableAdapter.Fill(this.dsNhapVatTu.VAT_TU);
                db = new Data_QLKDataContext(SqlHelper.ConnectionString);

                this.Text = String.Format("{0} Vật Tư", this.loai == 1 ? "Nhập" : "Xuất");
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(this, JsonConvert.SerializeObject(ex), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #13
0
        public void LoadData(long id)
        {
            try
            {
                db = new Data_QLKDataContext(SqlHelper.ConnectionString);
                bbiTaoMoi_ItemClick(this, null);
                _mColumn   = new Column();
                _mColumn   = Column.None;
                tinh_trang = "sua";
                this.id    = id;

                var ct = (from c in db.CHUNG_TUs
                          where c.Id == id
                          select c).FirstOrDefault();

                txtMaChungTu.Text = ct.Ma_Chung_Tu;
                //txtMaChungTu.Properties.ReadOnly = true;
                txtNgay.EditValue = ct.Ngay;
                txtLyDo.Text      = ct.Ly_Do;
                txtGhiChu.Text    = ct.Ghi_Chu;
                loai = ct.Loai_Chung_Tu.Value;

                if (this.loai == 1)
                {
                    cbNhapDauKy.Checked = ct.Dau_Ky.Value;
                }

                cHUNG_TU_CHI_TIETTableAdapter.Connection.ConnectionString = SqlHelper.ConnectionString;
                cHUNG_TU_CHI_TIETTableAdapter.ClearBeforeFill             = true;
                cHUNG_TU_CHI_TIETTableAdapter.Fill(dsNhapVatTu.CHUNG_TU_CHI_TIET, id);
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(this, JsonConvert.SerializeObject(ex), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #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);
            }
        }
Example #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);
        }
Example #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);
        }
Example #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());
            }
        }