コード例 #1
0
 public override int Insert(int id)
 {
     PhieuNhap pn = new PhieuNhap();
       return  pn.Insert(id);
 }
コード例 #2
0
        public override int Insert(int id)
        {
            DatabaseHelper help = new DatabaseHelper();
            help.ConnectDatabase();

            using (var dbcxtransaction = help.ent.Database.BeginTransaction())
            {

                PhieuNhap pn = new PhieuNhap();
                if (pn.Insert(id, help) == 1)
                {

                    {

                        var pnk = (from d in help.ent.Phieu_Nhap_Kho
                                   where d.ID_phieu_nhap == id
                                   select d).FirstOrDefault();
                        if (pnk == null)
                            return 0;

                        var entryPointCTPN = (from d in help.ent.Chi_Tiet_Phieu_Nhap_Vat_Tu
                                              where d.Ma_phieu_nhap == pnk.Ma_phieu_nhap
                                              select d).ToList();
                        if (entryPointCTPN.Count == 0)
                            return 0;
                        for (int i = 0; i < entryPointCTPN.Count; i++)
                        {
                            string mavattu = entryPointCTPN[i].Ma_vat_tu;
                            int idcl = (int)entryPointCTPN[i].Id_chat_luong;
                            string maphieu = entryPointCTPN[i].Ma_phieu_nhap;
                            decimal sl = (decimal)entryPointCTPN[i].So_luong_thuc_lanh;
                            DateTime ngay_xuat = (DateTime)pnk.Ngay_lap;

                            string dien_giai = pnk.Ly_do;
                            var entryPointGD = (from d in help.ent.Vat_Tu_Goi_Dau_Ky

                                                where d.ID_kho == pnk.ID_kho && d.Ma_vat_tu == mavattu && d.ID_chat_luong == idcl
                                                select d).FirstOrDefault();
                            if (entryPointGD == null)
                            {
                                Vat_Tu_Goi_Dau_Ky GD = new Vat_Tu_Goi_Dau_Ky();
                                GD.ID_chat_luong = idcl;
                                GD.ID_kho = pnk.ID_kho;
                                GD.Ma_vat_tu = mavattu;
                                GD.So_Luong = sl;
                                help.ent.Vat_Tu_Goi_Dau_Ky.Add(GD);
                                help.ent.SaveChanges();
                            }
                            else
                            {
                                entryPointGD.So_Luong = entryPointGD.So_Luong + sl;
                                help.ent.Vat_Tu_Goi_Dau_Ky.Attach(entryPointGD);
                                help.ent.Entry(entryPointGD).State = EntityState.Modified;
                                help.ent.SaveChanges();
                            }
                        }
                    }
                }
                dbcxtransaction.Commit();
                return 1;
            }
            return 0;
        }
コード例 #3
0
        private void XuLyNhap_Phieu()
        {
            try
            {
                Int32 selectedRowCount = gridDanhSachPhieuNhap.CurrentCell.RowIndex;
                string maphieu = gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["Ma_phieu"].Value.ToString();
                int idKho = int.Parse(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["ID_kho"].Value.ToString());

                bool Da_phan_kho = bool.Parse(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["Da_phan_kho"].Value.ToString());

                if (Da_phan_kho == true)
                {
                    MessageBox.Show("Phiếu này đã duyệt và phân kho ");
                    return;
                }

                int idphieu = string.IsNullOrEmpty(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["ID_phieu_nhap"].Value.ToString()) ? -1 : int.Parse(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["ID_phieu_nhap"].Value.ToString());
                int idloaiphieu = string.IsNullOrEmpty(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["id_loai_phieu_nhap"].Value.ToString()) ? -1 : int.Parse(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["id_loai_phieu_nhap"].Value.ToString());
                bool isgoidau = string.IsNullOrEmpty(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["isgoidau"].Value.ToString()) ? false : Boolean.Parse(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["isgoidau"].Value.ToString());
                bool isKNMN = string.IsNullOrEmpty(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["isKNMN"].Value.ToString()) ? false : Boolean.Parse(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["isKNMN"].Value.ToString());
                bool isToTrinh = string.IsNullOrEmpty(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["isToTrinh"].Value.ToString()) ? false : Boolean.Parse(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["isToTrinh"].Value.ToString());
                bool isKNTN = string.IsNullOrEmpty(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["isKNTN"].Value.ToString()) ? false : Boolean.Parse(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["isKNTN"].Value.ToString());
                bool isKCMN = string.IsNullOrEmpty(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["isKCMN"].Value.ToString()) ? false : Boolean.Parse(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["isKCMN"].Value.ToString());
                bool isKCTN = string.IsNullOrEmpty(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["isKCTN"].Value.ToString()) ? false : Boolean.Parse(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["isKCTN"].Value.ToString());
                bool isNVMN = string.IsNullOrEmpty(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["isNVMN"].Value.ToString()) ? false : Boolean.Parse(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["isNVMN"].Value.ToString());

                int ID_Kho = string.IsNullOrEmpty(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["ID_kho"].Value.ToString()) ? 0 : int.Parse(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["ID_kho"].Value.ToString());

                bool isKhoNgoai =  new clsDM_Kho().GetDataARow(ID_Kho);

                if (isKhoNgoai == true)
                {
                    if (idloaiphieu != -1)
                    {
                        clsLoaiPhieuNhap lpn = new clsLoaiPhieuNhap();
                        if (lpn.getTenLPN(idloaiphieu).Equals("XD"))
                        {
                            KhoNgoai pn = new KhoNgoai();

                            if (pn.Insert(idphieu) == 1)
                            {
                                MessageBox.Show("Đã xác nhận thành công!"); return;

                            }
                        }
                    }

                }
                if (isNVMN == true)
                {
                    KhoNgoai pn = new KhoNgoai();

                    if (pn.Insert(idphieu) == 1)
                    {
                        MessageBox.Show("Đã xác nhận thành công!"); return;

                    }
                }
                if (isToTrinh == true)
                {
                    BienBanToTrinh BBTT = new BienBanToTrinh();
                    if (BBTT.Insert(idphieu) == 1)
                    {
                        MessageBox.Show("Đã xác nhận thành công!"); return;
                    }
                }
                if (isgoidau == true)
                {
                    GoiDau gd = new GoiDau();
                    if (gd.Insert(idphieu) == 1)
                    {
                        MessageBox.Show("Đã xác nhận thành công!"); return;

                    }
                }
                if (CheckPhieuNo() == true)
                    return;
                if (isKCMN == true)
                {
                    DiMuonNo KCMN = new DiMuonNo();
                    if (KCMN.Insert(idphieu) == 1)
                    {
                        MessageBox.Show("Đã xác nhận thành công!"); return;

                    }

                }
                if (isKCTN == true)
                {
                    DiTraNo KCTN = new DiTraNo();
                    if (KCTN.Insert(idphieu) == 1)
                    {
                        MessageBox.Show("Đã xác nhận thành công!"); return;

                    }

                }
                if (isKNTN == true)
                {
                    KhoKhacTraNo gd = new KhoKhacTraNo();
                    if (gd.Insert(idphieu) == 1)
                    {
                        MessageBox.Show("Đã xác nhận thành công!"); return;

                    }
                }
                if (isKNMN == true)
                {
                    PhieuKhoKhacMuon gd = new PhieuKhoKhacMuon();
                    if (gd.Insert(idphieu) == 1)
                    {
                        MessageBox.Show("Đã xác nhận thành công!"); return;

                    }
                }
                if (isgoidau == true)
                {
                    GoiDau gd = new GoiDau();
                    if (gd.Insert(idphieu) == 1)
                    {
                        MessageBox.Show("Đã xác nhận thành công!"); return;

                    }

                }

                if (idloaiphieu != -1)
                {
                    clsLoaiPhieuNhap lpn = new clsLoaiPhieuNhap();
                    if (lpn.getTenLPN(idloaiphieu).Equals("XD"))
                    {
                        PhieuNhap pn = new PhieuNhap();

                        if (pn.Insert(idphieu) == 1)
                        {
                            MessageBox.Show("Đã xác nhận thành công!"); return;

                        }
                    }
                    if (lpn.getTenLPN(idloaiphieu).Equals("TD"))
                    {
                        PhieuHoanNhap phn = new PhieuHoanNhap();
                        if (phn.Insert(idphieu) == 1)
                        {
                            MessageBox.Show("Đã xác nhận thành công!"); return;

                        }
                    }
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(Utilities.clsThamSoUtilities.COException(ex));
            }
        }
コード例 #4
0
        private void btnDuyet_Click(object sender, EventArgs e)
        {
            dspn.LoadInitGridMaster();

            string maphieu = txtMaPhieuNhap.Text;
            clsPhieuNhapKho pn = new clsPhieuNhapKho();
            int idphieu = pn.GetIDPhieu(maphieu);
            PhieuNhap pnk = new PhieuNhap();
            pnk.Insert(idphieu);
            dspn.LoadData();
            this.Close();
        }