private void btnDanhSachDonHang_Click(object sender, EventArgs e)
        {
            try
            {
                overlay.StartLoading(groupControl2);
                var db        = new MyDBContextDataContext();
                var dsdonhang = (from s in db.tbDonSanXuat_Averies where s.XacNhan == null && s.NhanVien == nvObj.Tennhanvien && s.No == s.GopDon
                                 orderby s.GopDon, s.No ascending
                                 select s).ToList();

                var tongsl = 0;
                var tongdh = 0;
                foreach (var ds in dsdonhang)
                {
                    tenSanPhamTextEdit.Text = ds.SO;
Taoscd:
                    sCDTextEdit.Text = sscd.TaoSCD();
                    var tong = (from s in db.tbDonSanXuats where s.SCD == sCDTextEdit.Text select s).ToList();
                    if (tong.Count > 0)
                    {
                        goto Taoscd;
                    }
                    //var donSanXuats = (from s in db.tbDonSanXuats select s).ToList();
                    //foreach (var itemDonSanXuat in donSanXuats)
                    //{
                    //    if (sCDTextEdit.Text == itemDonSanXuat.SCD)
                    //        goto scd;
                    //}
                    if (sCDTextEdit.Text.Length > 14 && !string.IsNullOrEmpty(sCDTextEdit.Text))
                    {
                        if (maDonHangTextEdit.Text.Length > 8)
                        {
                            var dsx     = (from a in db.tbDonSanXuat_Averies where a.SO == tenSanPhamTextEdit.Text select a).Single();
                            var soluong = Convert.ToInt32(soLuongSpinEdit.Value);
                            var tb      = new tbDonSanXuat();
                            tb.SCD          = sCDTextEdit.Text;
                            tb.MaDonHang    = maDonHangTextEdit.Text;
                            tb.PhienBan     = txtPhienBan.Text;
                            tb.TenKhachHang = txtKhachHang.Text;
                            tb.NgayXuongDon = ngayXuongDonDateEdit.DateTime;
                            tb.NgayGiaoHang = ngayGiaoHangDateEdit.DateTime;
                            var gopdon = (from s in db.GopDon_Avery(nvObj.Tennhanvien)
                                          where s.gopdon == dsx.GopDon
                                          select s).Single();
                            if (gopdon.CountNo == 1)
                            {
                                tb.TenSanPham = dsx.SO + " - " + dsx.Item; //
                            }
                            else
                            {
                                tb.TenSanPham = dsx.Item; //dsx.SO + " - " +
                            }

                            tb.LoaiSanPham    = txtLoaiSanPham.Text;
                            tb.PhuongPhapIn   = txtPhuongPhapIn.Text;
                            tb.KichThuoc      = kichThuocTextEdit.Text;
                            tb.SoLuong        = soluong;
                            tb.VatLieu        = vatLieuComboBox.Text;
                            tb.GiaCongMatPhai = giaCongMatPhaiTextEdit.Text;
                            tb.GiaCongMatTrai = giaCongMatTraiTextEdit.Text;
                            //var lst = (from s in db.tbDanhSachSanPhams select s).ToList();
                            //foreach (var dssPham in lst)
                            //{
                            //    if (dssPham.TenSanPham != tenSanPhamTextEdit.Text) continue;
                            //    tb.HinhMatPhai = dssPham.HinhMatPhai;
                            //    tb.HinhMatTrai = dssPham.HinhMatTrai;
                            //    tb.HinhKhuon = dssPham.HinhKhuon;
                            //}

                            tb.MauMatPhai       = mauMatPhaiTextEdit.Text;
                            tb.MauMatTrai       = mauMatTraiTextEdit.Text;
                            tb.PhuongPhapCat    = phuongPhapCatTextEdit.Text;
                            tb.BoGoc            = boGocTextEdit.Text;
                            tb.DucLo            = ducLoTextEdit.Text;
                            tb.LoaiChi          = loaiChiTextEdit.Text;
                            tb.BTPSoLuongTonKho = Convert.ToInt32(bTPSoLuongTonKhoSpinEdit.Value);
                            tb.TPSoLuongTonKho  = Convert.ToInt32(tPSoLuongTonKhoSpinEdit.Value);
                            tb.BTPTonKhoCongTy  = Convert.ToInt32(bTPTonKhoCongtySpinEdit.Value);
                            tb.TPTonKhoCongTy   = Convert.ToInt32(TPTonKhoCongtySpinEdit.Value);
                            tb.BoPhan           = txtBoPhan.Text;
                            tb.ChamCatDapHop    = chamCatDapHopTextEdit.Text;
                            tb.Khac             = khacTextEdit.Text;
                            tb.DoDai            = doDaiTextEdit.Text;
                            tb.InChu_MaVach     = inChu_MaVachTextEdit.Text;
                            tb.GiaCongSau       = giaCongSauTextEdit.Text;
                            tb.Kho = txtKho.Text;
                            tb.SKU = (int)txtSKU.Value;
                            tb.STT = dsx.No;



                            var so = Empty;
                            var tbDonSanXuatAveries =
                                (from s in db.tbDonSanXuat_Averies where s.XacNhan == null select s).ToList();
                            foreach (var item in tbDonSanXuatAveries)
                            {
                                if (item.GopDon != dsx.GopDon)
                                {
                                    continue;
                                }
                                item.scd     = sCDTextEdit.Text;
                                item.XacNhan = 1;
                                //db.SubmitChanges();
                                if (gopdon.CountNo > 1)
                                {
                                    so = so + item.SO + " , ";
                                }
                            }

                            if (gopdon.CountNo > 1)
                            {
                                tb.ChuY = chuYTextEdit.Text + Environment.NewLine + so + " dùng chung layout";
                            }
                            else
                            {
                                tb.ChuY = chuYTextEdit.Text;
                            }

                            tb.NhanVienNghiepVu = nvObj.Tennhanvien;
                            tb.ThoiGianXuongDon = DateTime.Now;
                            db.tbDonSanXuats.InsertOnSubmit(tb);
                            db.SubmitChanges();


                            var qldh = new tbQuanLyDonHang {
                                IDQuanLyDonHang = sCDTextEdit.Text
                            };
                            db.tbQuanLyDonHangs.InsertOnSubmit(qldh);

                            var ll = new tbLanhLieu {
                                IDLanhLieu = sCDTextEdit.Text
                            };
                            db.tbLanhLieus.InsertOnSubmit(ll);
                            db.SubmitChanges();

                            var thietke = new tbBaoCaoThietKe
                            {
                                IDBaoCaoThietKe = sCDTextEdit.Text,
                                Size            = khacTextEdit.Text,
                                SpSize          = soLuongSpinEdit.Text
                            };
                            db.tbBaoCaoThietKes.InsertOnSubmit(thietke);
                            db.SubmitChanges();

                            var nghiepvu = new tbBaoCaoNghiepVu()
                            {
                                IDBaoCaoNghiepVu = sCDTextEdit.Text,
                                Size             = khacTextEdit.Text
                            };
                            db.tbBaoCaoNghiepVus.InsertOnSubmit(nghiepvu);
                            db.SubmitChanges();

                            var tb4 = new tbQuanLyTienTe
                            {
                                IDTienTe        = sCDTextEdit.Text,
                                DonGiaSanPham   = Convert.ToDouble(donGiaSanPhamSpinEdit.Value),
                                DonGiaKhuon     = Convert.ToDouble(donGiaKhuonSpinEdit.Value),
                                DonGiaMau       = Convert.ToDouble(donGiaMauSpinEdit.Value),
                                DonGiaVanChuyen = Convert.ToDouble(donGiaVanChuyenSpinEdit.Value),
                                TongTien        = Convert.ToDouble(tongTienSpinEdit.Value),
                                NgoaiTe         = ngoaiTeComboBox.Text,
                                GiaTienUSD      = (int)txtGiaTienUSD.Value,
                                VAT             = vat
                            };
                            db.tbQuanLyTienTes.InsertOnSubmit(tb4);
                            db.SubmitChanges();

                            var tb6 = new tbSanXuat {
                                IDSanXuat = sCDTextEdit.Text
                            };
                            db.tbSanXuats.InsertOnSubmit(tb6);
                            db.SubmitChanges();


                            var donhang = new tbDonHangTemVaiAvery();
                            donhang.IDDonHangTemVaiAvery = sCDTextEdit.Text;
                            donhang.Item     = dsx.Item;
                            donhang.SO       = gopdon.CountNo != 1 ? so : dsx.SO;
                            donhang.DanhSach = dsx.DanhSach;
                            db.tbDonHangTemVaiAveries.InsertOnSubmit(donhang);
                            db.SubmitChanges();

                            //frmDonSanXuat_Avery_Them_Load(sender,e);
                            tongsl = tongsl + soluong;
                            tongdh = tongdh + 1;
                        }
                        else
                        {
                            MessageBox.Show("Bạn chưa nhập mã đơn hàng");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Bạn chưa nhập mã SCD, hoặc mã SCD bị trùng");
                    }
                }
                overlay.EndLoading();
                MessageBox.Show("Tổng số đơn hàng thêm vào: " + tongdh + Environment.NewLine + "Tổng số lượng là : " + tongsl);
            }
            catch (Exception exception)
            {
                overlay.EndLoading();
                MessageBox.Show(exception.ToString());
                // ignored
            }
        }
Beispiel #2
0
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            var db          = new MyDBContextDataContext();
            var donSanXuats = (from s in db.tbDonSanXuats select s).ToList();
            var tong        = 0;

            foreach (var itemDonSanXuat in donSanXuats)
            {
                if (sCDTextEdit.Text == itemDonSanXuat.SCD)
                {
                    tong = tong + 1;
                }
            }

            if (sCDTextEdit.Text.Length > 14 & tong == 0)
            {
                if (maDonHangTextEdit.Text.Length > 8)
                {
                    try
                    {
                        var tb = new tbDonSanXuat();
                        tb.SCD            = sCDTextEdit.Text;
                        tb.MaDonHang      = maDonHangTextEdit.Text;
                        tb.PhienBan       = txtPhienBan.Text;
                        tb.TenKhachHang   = txtKhachHang.Text;
                        tb.NgayXuongDon   = ngayXuongDonDateEdit.DateTime;
                        tb.NgayGiaoHang   = ngayGiaoHangDateEdit.DateTime;
                        tb.TenSanPham     = tenSanPhamTextEdit.Text;
                        tb.LoaiSanPham    = txtLoaiSanPham.Text;
                        tb.PhuongPhapIn   = txtPhuongPhapIn.Text;
                        tb.KichThuoc      = kichThuocTextEdit.Text;
                        tb.SoLuong        = Convert.ToInt32(soLuongSpinEdit.Value);
                        tb.VatLieu        = vatLieuComboBox.Text;
                        tb.GiaCongMatPhai = giaCongMatPhaiTextEdit.Text;
                        tb.GiaCongMatTrai = giaCongMatTraiTextEdit.Text;
                        var lst = (from s in db.tbDanhSachSanPhams select s).ToList();
                        foreach (var itemTbDanhSachSanPham in lst)
                        {
                            if (itemTbDanhSachSanPham.TenSanPham != tenSanPhamTextEdit.Text)
                            {
                                continue;
                            }
                            tb.HinhMatPhai = itemTbDanhSachSanPham.HinhMatPhai;
                            tb.HinhMatTrai = itemTbDanhSachSanPham.HinhMatTrai;
                            tb.HinhKhuon   = itemTbDanhSachSanPham.HinhKhuon;
                        }
                        tb.MauMatPhai       = mauMatPhaiTextEdit.Text;
                        tb.MauMatTrai       = mauMatTraiTextEdit.Text;
                        tb.PhuongPhapCat    = phuongPhapCatTextEdit.Text;
                        tb.BoGoc            = boGocTextEdit.Text;
                        tb.DucLo            = ducLoTextEdit.Text;
                        tb.LoaiChi          = loaiChiTextEdit.Text;
                        tb.BTPSoLuongTonKho = Convert.ToInt32(bTPSoLuongTonKhoSpinEdit.Value);
                        tb.TPSoLuongTonKho  = Convert.ToInt32(tPSoLuongTonKhoSpinEdit.Value);
                        tb.BTPTonKhoCongTy  = Convert.ToInt32(bTPTonKhoCongtySpinEdit.Value);
                        tb.TPTonKhoCongTy   = Convert.ToInt32(TPTonKhoCongtySpinEdit.Value);
                        tb.BoPhan           = txtBoPhan.Text;
                        tb.ChamCatDapHop    = chamCatDapHopTextEdit.Text;
                        tb.Khac             = khacTextEdit.Text;
                        tb.DoDai            = doDaiTextEdit.Text;
                        tb.InChu_MaVach     = inChu_MaVachTextEdit.Text;
                        tb.GiaCongSau       = giaCongSauTextEdit.Text;
                        tb.Kho              = txtKho.Text;
                        tb.ChuY             = chuYTextEdit.Text;
                        tb.SKU              = (int)txtSKU.Value;
                        tb.NhanVienNghiepVu = nvObj.Tennhanvien;
                        tb.ThoiGianXuongDon = DateTime.Now;
                        db.tbDonSanXuats.InsertOnSubmit(tb);

                        var tb2 = new tbQuanLyDonHang {
                            IDQuanLyDonHang = sCDTextEdit.Text
                        };
                        db.tbQuanLyDonHangs.InsertOnSubmit(tb2);

                        var tb3 = new tbLanhLieu {
                            IDLanhLieu = sCDTextEdit.Text
                        };
                        db.tbLanhLieus.InsertOnSubmit(tb3);

                        if (CheckVAT.CheckState == CheckState.Unchecked || tongTienSpinEdit.Text == null)
                        {
                            vat = 1;
                        }
                        var tb4 = new tbQuanLyTienTe
                        {
                            IDTienTe        = sCDTextEdit.Text,
                            DonGiaSanPham   = Convert.ToDouble(donGiaSanPhamSpinEdit.Value),
                            DonGiaKhuon     = Convert.ToDouble(donGiaKhuonSpinEdit.Value),
                            DonGiaMau       = Convert.ToDouble(donGiaMauSpinEdit.Value),
                            DonGiaVanChuyen = Convert.ToDouble(donGiaVanChuyenSpinEdit.Value),
                            TongTien        = Convert.ToDouble(tongTienSpinEdit.Value),
                            NgoaiTe         = ngoaiTeComboBox.Text,
                            VAT             = vat
                        };
                        db.tbQuanLyTienTes.InsertOnSubmit(tb4);

                        var sanxuat = new tbSanXuat {
                            IDSanXuat = sCDTextEdit.Text
                        };
                        db.tbSanXuats.InsertOnSubmit(sanxuat);

                        var thietke = new tbBaoCaoThietKe
                        {
                            IDBaoCaoThietKe = sCDTextEdit.Text,
                            SpSize          = soLuongSpinEdit.Text
                        };
                        db.tbBaoCaoThietKes.InsertOnSubmit(thietke);

                        var _nghiepvu = new tbBaoCaoNghiepVu()
                        {
                            IDBaoCaoNghiepVu = sCDTextEdit.Text,
                        };
                        db.tbBaoCaoNghiepVus.InsertOnSubmit(_nghiepvu);

                        var donhangtemvai = new tbDonHangTemVaiAvery
                        {
                            IDDonHangTemVaiAvery = sCDTextEdit.Text,
                        };
                        db.tbDonHangTemVaiAveries.InsertOnSubmit(donhangtemvai);

                        db.SubmitChanges();
                        MessageBox.Show(PrintRibbon.themthanhcong);

                        var xn = nvObj.Tennhanvien + " " + DateTime.Now;
                        if (nvObj.Bophan == "QUẢN LÝ SẢN XUẤT")
                        {
                            var qldh = (from s in db.tbQuanLyDonHangs where s.IDQuanLyDonHang == sCDTextEdit.Text select s).Single();
                            qldh.NghiepVu_XuongDon = xn;
                            db.SubmitChanges();
                        }
                    }
                    catch
                    {
                        // ignored
                    }
                }
                else
                {
                    MessageBox.Show("Bạn chưa nhập mã đơn hàng");
                }
            }
            else
            {
                MessageBox.Show("Bạn chưa nhập mã SCD, hoặc mã SCD bị trùng");
            }
        }