예제 #1
0
        void YeniKaydet()
        {
            Liste.AllowUserToAddRows = false;
            try
            {
                tblPurchasing[] pur = new tblPurchasing[Liste.RowCount];
                tblStock[]      stk = new tblStock[Liste.RowCount];

                for (int i = 0; i < Liste.RowCount; i++)
                {
                    int    pid = int.Parse(Liste.Rows[i].Cells[0].Value.ToString());
                    string lot = Liste.Rows[i].Cells[2].Value.ToString();
                    pur[i]       = new tblPurchasing();
                    pur[i].PurNo = int.Parse(txtAlisNo.Text);
                    //pur[i].PurNo = int.Parse(Liste.Rows[i].Cells[5].Value.ToString());
                    pur[i].CompanyID       = _db.tblCompanies.First(x => x.Name == txtFirma.Text).ID;
                    pur[i].ProductID       = int.Parse(Liste.Rows[i].Cells[0].Value.ToString());
                    pur[i].LotSerial       = Liste.Rows[i].Cells[2].Value.ToString();
                    pur[i].Date            = DateTime.Parse(dtpTarih.Text);
                    pur[i].PurchasingPrice = decimal.Parse(Liste.Rows[i].Cells[3].Value.ToString());
                    pur[i].Quantity        = int.Parse(Liste.Rows[i].Cells[4].Value.ToString());
                    pur[i].EmployeeID      = _db.tblEmployees.First(x => x.Name == txtPersonel.Text).ID;

                    _db.tblPurchasings.InsertOnSubmit(pur[i]);

                    AccountingDBDataContext _gb = new AccountingDBDataContext();

                    stk[i] = new tblStock();
                    var srg = (from s in _gb.tblStocks where s.ProductID == int.Parse(Liste.Rows[i].Cells[0].Value.ToString()) && s.LotSerial == Liste.Rows[i].Cells[2].Value.ToString() select s).ToList();

                    if (srg.Count == 0)
                    {
                        stk[i].ProductID = int.Parse(Liste.Rows[i].Cells[0].Value.ToString());
                        stk[i].LotSerial = Liste.Rows[i].Cells[2].Value.ToString();
                        stk[i].Quantity  = int.Parse(Liste.Rows[i].Cells[4].Value.ToString());

                        _gb.tblStocks.InsertOnSubmit(stk[i]);
                    }
                    else
                    {
                        tblStock st = _gb.tblStocks.First(x => x.ProductID == pid && x.LotSerial == lot);
                        st.Quantity += int.Parse(Liste.Rows[i].Cells[4].Value.ToString());
                    }
                    _gb.SubmitChanges();
                }
                _db.SubmitChanges();
                _m.YeniKayit("Kayıt başarılı!!");
            }
            catch (Exception e)
            {
                _m.Hata(e);
            }
        }
예제 #2
0
        void YeniKaydet()
        {
            Liste.AllowUserToAddRows = false;
            try
            {
                tblSalesDown[] sud = new tblSalesDown[Liste.RowCount];
                tblSalesUp     sup = new tblSalesUp();


                for (int i = 0; i < Liste.RowCount; i++)
                {
                    int    pid = int.Parse(Liste.Rows[i].Cells[0].Value.ToString());
                    string lot = Liste.Rows[i].Cells[2].Value.ToString();

                    sud[i]            = new tblSalesDown();
                    sud[i].SalesID    = int.Parse(txtSatisNo.Text);
                    sud[i].ProductID  = pid;
                    sud[i].LotSerial  = lot;
                    sud[i].SalesPrice = decimal.Parse(Liste.Rows[i].Cells[4].Value.ToString());
                    sud[i].Quantity   = int.Parse(Liste.Rows[i].Cells[5].Value.ToString());


                    sup.SalesID    = int.Parse(txtSatisNo.Text);
                    sup.CompanyID  = _db.tblCompanies.First(x => x.Name == txtFirma.Text).ID;
                    sup.Date       = DateTime.Parse(dtpTarih.Text);
                    sup.CityID     = _db.tblCities.First(x => x.City == cbSehir.Text).Id;
                    sup.EmployeeID = _db.tblEmployees.First(x => x.Name == txtPer.Text).ID;
                    sup.ShipperID  = _db.tblShippers.First(x => x.Name == txtKargo.Text).ID;

                    AccountingDBDataContext _gb = new AccountingDBDataContext();
                    tblStock st = _gb.tblStocks.First(x => x.ProductID == pid && x.LotSerial == lot);
                    if (st.Quantity.Value - int.Parse(Liste.Rows[i].Cells[5].Value.ToString()) > 0)
                    {
                        st.Quantity -= int.Parse(Liste.Rows[i].Cells[5].Value.ToString());
                        _gb.SubmitChanges();
                        _db.tblSalesDowns.InsertOnSubmit(sud[i]);
                        _db.tblSalesUps.InsertOnSubmit(sup);
                    }

                    else

                    {
                        MessageBox.Show("Elimizde Yeterli Ürün Yok!");
                    }
                }
                _db.SubmitChanges();
                _m.YeniKayit("Kayıt başarılı.");
            }
            catch (Exception e)
            {
                _m.Hata(e);
            }
        }
예제 #3
0
        void Guncelle()
        {
            AccountingDBDataContext _gb = new AccountingDBDataContext();

            try
            {
                tblProduct pro = _gb.tblProducts.First(x => x.ID == _urunId);
                pro.CategoryID = _gb.tblCategories.First(x => x.CategoryName == txtKategori.Text).ID;;
                pro.Name       = txtUadi.Text;
                pro.Note       = txtNot.Text;
                pro.UnitPrice  = decimal.Parse(txtBirimFiyat.Text);
                _gb.SubmitChanges();
                _m.Guncelle(true);
                Temizle();
            }
            catch (Exception e)
            {
                _m.Hata(e);
            }
        }
예제 #4
0
        private void YeniKaydet()
        {
            Liste.AllowUserToAddRows = false;
            bool kon = true;

            try
            {
                tblSalesDown[]          saled = new tblSalesDown[Liste.RowCount];
                tblSalesUp              saleu = new tblSalesUp();
                tblStock[]              stk   = new tblStock[Liste.RowCount];
                AccountingDBDataContext _gb   = new AccountingDBDataContext();
                AccountingDBDataContext _eb   = new AccountingDBDataContext();
                for (int i = 0; i < Liste.RowCount - 1; i++)
                {
                    for (int a = 0; a < Liste.ColumnCount - 1; a++)
                    {
                        var d = Liste.Rows[i].Cells[a].Value;
                        if (d == null)
                        {
                            MessageBox.Show("Alan boş bırakılamaz" + (i + 1) + ".satır " + a + ". sütunu kontrol edin");
                            kon = false;
                            break;
                        }
                    }
                }  //HÜCRE BOŞ BIRAKILAMAZ

                if (kon && txtFirma.Text != "" && txtPersonel.Text != "" && cbKargo.Text != "") //BOŞ ALAN BIRAKILMIŞSA KAYIT YAPILMASINI ÖNLEMEK İÇİN KULLANILAN İF
                {
                    #region SALESUP TABLOSUNA YAPILACAK KAYIT
                    saleu.SalesID    = int.Parse(txtSatisNo.Text);
                    saleu.EmployeeID = _eb.tblEmployees.First(x => x.Name == txtPersonel.Text).ID;
                    saleu.CompanyID  = _eb.tblCompanies.First(x => x.Name == txtFirma.Text).ID;
                    saleu.Date       = DateTime.Parse(dtpTarih.Text);
                    saleu.CityID     = cbSehir.SelectedIndex + 1;
                    saleu.ShipperID  = _eb.tblShippers.First(x => x.Name == cbKargo.Text).ID;


                    _eb.tblSalesUps.InsertOnSubmit(saleu);
                    #endregion

                    for (int i = 0; i < Liste.RowCount; i++)//SALES DOWNA YAPILACAK OLAN KAYIT VE STOCK TABLOSUNDAKİ DEĞİŞTİRİLECEK QUANTİTY
                    {
                        if (Liste.Rows[i].Cells[1].Value != null)
                        {
                            int pid = int.Parse(Liste.Rows[i].Cells[0].Value.ToString());

                            string[] lotseri = Liste.Rows[i].Cells[2].Value.ToString().Split('-');

                            Array.Resize(ref lotseri, lotseri.Length - 1);
                            string lot = string.Join("-", lotseri);

                            saled[i]            = new tblSalesDown();
                            saled[i].SalesID    = int.Parse(txtSatisNo.Text);
                            saled[i].ProductID  = pid;
                            saled[i].LotSerial  = lot;
                            saled[i].SalesPrice = decimal.Parse(Liste.Rows[i].Cells[4].Value.ToString());
                            saled[i].Quantity   = int.Parse(Liste.Rows[i].Cells[3].Value.ToString());


                            #region SATIŞ YAPILAN ÜRÜNÜN STOCK TABLSOUNDAKİ ADET SAYISININ AZALTILMASI
                            stk[i] = new tblStock();
                            var srg = (from s in _gb.tblStocks
                                       where s.ProductID == pid && s.LotSerial == lot
                                       select s
                                       ).ToList();
                            if (srg.Count > 0 && _db.tblStocks.First(x => x.ProductID == pid && x.LotSerial == lot).Quantity >= int.Parse(Liste.Rows[i].Cells[3].Value.ToString()))
                            {
                                tblStock st = _gb.tblStocks.First(x => x.ProductID == pid && x.LotSerial == lot);
                                st.Quantity -= int.Parse(Liste.Rows[i].Cells[3].Value.ToString());


                                _db.tblSalesDowns.InsertOnSubmit(saled[i]);
                                //_gb.tblStocks.InsertOnSubmit(stk[i]); //bu çalışırsa tblstock içine yeni bi null dolu kayıt ekliyor.

                                kont = true;
                            }
                            else
                            {
                                MessageBox.Show(Liste.Rows[i].Cells[5].Value.ToString() + "ürün stokta yeteri kadar yoktur.", "Stok Hatası", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                            #endregion
                        }
                    }


                    if (kont) //SATIŞ YAPIALCAK ÜRÜNÜN SAYISI ELİMİZDEKİ ÜRÜNDEN FAZLAYSA DEĞİŞİKLERİ GERÇEKLEŞTİR
                    {
                        _gb.SubmitChanges();
                        _eb.SubmitChanges();
                        _db.SubmitChanges();
                        _m.YeniKayit("Satış başarılı.");
                        Temizle();
                        _f.Satis();
                        Close();
                    }
                }
                else
                {
                    MessageBox.Show("Eksik bilgi girdiniz. Lütfen tüm bilgileri giriniz.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception e)
            {
                _m.Hata(e);
            }
        }