Ejemplo n.º 1
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[] nhanvien = new string[selectedRows.Length];
            for (int i = selectedRows.Length; i > 0; i--)
            {
                var arg = gbList.GetRowCellValue(selectedRows[i - 1], colMa_Nhan_Vien);
                if (arg == null)
                    continue;
                nhanvien[i - 1] = arg.ToString();
            }

            var nv = from h in db.NHAN_VIENs
                     where nhanvien.Contains(h.Ma_Nhan_Vien)
                     select h;

            foreach (var n in nv)
            {
                db.NHAN_VIENs.DeleteOnSubmit(n);
            }

            try
            {
                db.SubmitChanges();
                bbiXem_ItemClick(this, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 2
0
        string Luu_Chi_Tiet(Data_QLKDataContext database)
        {
            var result = "OK";
            var dt = dsNhapKho.CHUNG_TU_CHI_TIET;
            var id = "";
            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 = dt.Rows[i]["Ma_Chi_Tiet"].ToString();
                }
                var dr = dt.Rows[i];
                switch (dr.RowState)
                {
                    case DataRowState.Added:

                        var chung_tu_chi_tiet = new CHUNG_TU_CHI_TIET
                        {
                            Ma_Chi_Tiet = Guid.NewGuid(),
                            Ma_Chung_Tu = txtMaChungTu.Text,
                            Ma_Hang_Hoa = dt.Rows[i]["Ma_Hang_Hoa"].ToString(),
                            Loai_Chung_Tu = 1, //1 nhap kho 2 xuat kho
                            Tinh_Trang = true, //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.Ma_Chi_Tiet == new Guid(id)
                                                select ctct).FirstOrDefault();

                        chi_tiet_sua.Ma_Chi_Tiet = new Guid(id);
                        chi_tiet_sua.Ma_Chung_Tu = txtMaChungTu.Text;
                        chi_tiet_sua.Ma_Hang_Hoa = dt.Rows[i]["Ma_Hang_Hoa"].ToString();
                        chi_tiet_sua.Loai_Chung_Tu = 1; //1 nhap kho 2 xuat kho
                        chi_tiet_sua.Tinh_Trang = true; //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.Ma_Chi_Tiet == new Guid(id)
                                        select ctct).FirstOrDefault();
                        database.CHUNG_TU_CHI_TIETs.DeleteOnSubmit(chi_tiet_xoa);
                        break;
                }
                database.SubmitChanges();
            }
            return result;
        }
Ejemplo n.º 3
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[] chungtu = 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;
                chungtu[i - 1] = arg.ToString();
            }

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

            foreach (var c in ct)
            {
                db.CHUNG_TUs.DeleteOnSubmit(c);
            }

            try
            {
                db.SubmitChanges();
                bbiXem_ItemClick(this, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 4
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 = 1, //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,
                        So_Thu_Tu = 0,
                        Nhan_Vien = string.IsNullOrEmpty(txtNhanVien.Text) ? "" : txtNhanVien.EditValue.ToString()
                    };
                    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 = 1; //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) == "OK")
                {
                    database.SubmitChanges();
                    database.Transaction.Commit();
                    RaiseReloadEventHander();
                    Close();
                }
                else
                {
                    database.Transaction.Rollback();
                }
            }
            catch (Exception ex)
            {
                database.Transaction.Rollback();
                MessageBox.Show(ex.ToString());
            }
        }
Ejemplo n.º 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);
            }
        }