Esempio n. 1
0
        private void RetrieveBtn_Click(object sender, EventArgs e)
        {
            if (SearchNameTxt.Text == "" && SearchIdTxt.Text == "" && SelectNameCmb.SelectedIndex == -1)
            {
                MessageBox.Show("Θα πρέπει πρώτα να εισάγετε περιγραφή ή κωδικό του προϊόντος.");
            }
            else
            {
                using (SqlConnection sqlcon = new SqlConnection(con.ConnectionString))
                {
                    try
                    {
                        sqlcon.Open();
                        try
                        {
                            string query;
                            string param;
                            if (SearchNameTxt.Text != "")
                            {
                                query = "select a.Id,a.Description,a.LongDescr,a.Manufacture,b.Quant,dbo.FVAL_PRODUCT_MINSTOCK(a.Id),a.Unit, a.ProfitPerc,a.SupplierDescr from Products a, ProductsReserveView b where a.Id=b.Id and UPPER(a.Description)=@parameter";
                                param = SearchNameTxt.Text;
                            }
                            else if (SearchIdTxt.Text != "")
                            {
                                query = "select a.Id,a.Description,a.LongDescr,a.Manufacture,b.Quant,dbo.FVAL_PRODUCT_MINSTOCK(a.Id),a.Unit, a.ProfitPerc,a.SupplierDescr from Products a, ProductsReserveView b where a.Id=b.Id and a.Id=@parameter";
                                param = SearchIdTxt.Text;
                            }
                            else
                            {
                                query = "select a.Id,a.Description,a.LongDescr,a.Manufacture,b.Quant,dbo.FVAL_PRODUCT_MINSTOCK(a.Id),a.Unit, a.ProfitPerc,a.SupplierDescr from Products a, ProductsReserveView b where a.Id=b.Id and UPPER(a.Description)=@parameter";
                                param = SelectNameCmb.GetItemText(SelectNameCmb.SelectedItem);
                            }

                            SqlDataAdapter SearchAdapt = new SqlDataAdapter(query, sqlcon);
                            SearchAdapt.SelectCommand.Parameters.AddWithValue(@"parameter", param);
                            DataTable dt = new DataTable();
                            SearchAdapt.Fill(dt);
                            if (dt.Rows.Count == 0)
                            {
                                MessageBox.Show("Δε βρέθηκε προϊόν με τα στοιχεία που εισάγατε.");
                            }
                            else if (dt.Rows.Count > 1)
                            {
                                MessageBox.Show("Υπάρχουν " + dt.Rows.Count + " καταχωρημένα προϊόντα με τα στοιχεία που έχετε εισάγει. Παρακαλώ αλλάξτε τρόπο αναζήτησης.");
                            }
                            else
                            {
                                IdTxt.Text                  = dt.Rows[0][0].ToString();
                                DescrTxt.Text               = dt.Rows[0][1].ToString();
                                LongDescrTxt.Text           = dt.Rows[0][2].ToString();
                                ManufacTxt.Text             = dt.Rows[0][3].ToString();
                                QuantTxt.Text               = dt.Rows[0][4].ToString();
                                MinStockTxt.Text            = dt.Rows[0][5].ToString();
                                UnitTxt.Text                = dt.Rows[0][6].ToString();
                                ProfitPercTxt.Text          = dt.Rows[0][7].ToString();
                                SupplierDescrTxt.Text       = dt.Rows[0][8].ToString();
                                SearchNameTxt.Text          = "";
                                SearchIdTxt.Text            = "";
                                SelectNameCmb.SelectedIndex = -1;
                                EditBtn.Visible             = true;
                            }



                            string         query2       = @"select distinct Right('          '+InvoiceId,15),Right('          '+InvoiceSeries,8),InvoiceDate,Right('          '+ProductQuant,8),Right('          '+ProductPrice,12),Prev,Id from
                            (select InvoiceId, InvoiceSeries, InvoiceDate, ProductQuant, ProductPrice,'SupInvoice' Prev,b.Id from SupplierInvoiceProducts a, SupplierInvoice b where a.SupplierInvoiceId= b.id and ProductId = @id
                            union
                            select DebitInvoiceId, DebitInvoiceSeries, DebitInvoiceDate, ProductQuant, ProductPrice,'SupDebitInvoice',b.Id from SupplierDebitInvoiceProducts a, SupplierDebitInvoice b  where a.SupplierDebitInvoiceId = b.id and ProductId = @id
                            union
                            select DisNoteId, DisNoteSeries, DisNoteDate, ProductQuant, '','SupDisNoteInvoice',b.Id from SupplierDisNoteProducts a, SupplierDisNote b  where a.SupplierDisNoteId = b.id and dbo.SupplierDisNote_without_Invoice(b.Id) = 0 and ProductId = @id
                            union
                            select DisNoteId, DisNoteSeries, DisNoteDate, ProductQuant, '','SupDisNoteReturnInvoice',b.Id from SupplierReturnDisNoteProducts a, SupplierReturnDisNote b  where a.SupplierDisNoteId = b.id and ProductId = @id
                            union
                            select InvoiceId, InvoiceSeries, InvoiceDate, ProductQuant, ProductPrice,'CusInvoice',b.Id from CustomerInvoiceProducts a, CustomerInvoice b where a.CustomerInvoiceId = b.id and ProductId = @id
                            union
                            select DebitInvoiceId, DebitInvoiceSeries, DebitInvoiceDate, ProductQuant, ProductPrice,'CusDebitInvoice',b.Id  from CustomerDebitInvoiceProducts a, CustomerDebitInvoice b  where a.CustomerDebitInvoiceId = b.id and ProductId = @id
                            union
                            select DisNoteId, DisNoteSeries, DisNoteDate, ProductQuant, '','CusDisNoteInvoice',b.Id from CustomerDisNoteProducts a, CustomerDisNote b  where a.CustomerDisNoteId = b.id and dbo.CustomerDisNote_without_Invoice(b.Id) = 0 and ProductId = @id
                            ) a
                            order by InvoiceDate desc";
                            SqlDataAdapter SearchAdapt2 = new SqlDataAdapter(query2, sqlcon);
                            SearchAdapt2.SelectCommand.Parameters.AddWithValue(@"id", IdTxt.Text);
                            DataTable dt2 = new DataTable();
                            SearchAdapt2.Fill(dt2);
                            DocumentLbx.Items.Clear();
                            SupInvDc.Clear();
                            SupDebDc.Clear();
                            SupDisDc.Clear();
                            SupDisRDc.Clear();
                            CusInvDc.Clear();
                            CusDebDc.Clear();
                            CusDisDc.Clear();
                            for (int i = 0; (i < dt2.Rows.Count); i++)
                            {
                                DateTime dat = Convert.ToDateTime(dt2.Rows[i][2].ToString());
                                DocumentLbx.Items.Add(dt2.Rows[i][0].ToString() + " / " + dt2.Rows[i][1].ToString() + "  -  " + dat.Date.Day + "/" + dat.Date.Month + "/" + dat.Date.Year + "  -  " + dt2.Rows[i][3].ToString() + "  -  " + dt2.Rows[i][4].ToString());
                                if (dt2.Rows[i][5].ToString() == "SupInvoice")
                                {
                                    SupInvDc.Add(i.ToString(), dt2.Rows[i][6].ToString());
                                }
                                else if (dt2.Rows[i][5].ToString() == "SupDebitInvoice")
                                {
                                    SupDebDc.Add(i.ToString(), dt2.Rows[i][6].ToString());
                                }
                                else if (dt2.Rows[i][5].ToString() == "SupDisNoteInvoice")
                                {
                                    SupDisDc.Add(i.ToString(), dt2.Rows[i][6].ToString());
                                }
                                else if (dt2.Rows[i][5].ToString() == "SupDisNoteReturnInvoice")
                                {
                                    SupDisRDc.Add(i.ToString(), dt2.Rows[i][6].ToString());
                                }
                                else if (dt2.Rows[i][5].ToString() == "CusInvoice")
                                {
                                    CusInvDc.Add(i.ToString(), dt2.Rows[i][6].ToString());
                                }
                                else if (dt2.Rows[i][5].ToString() == "CusDebitInvoice")
                                {
                                    CusDebDc.Add(i.ToString(), dt2.Rows[i][6].ToString());
                                }
                                else if (dt2.Rows[i][5].ToString() == "CusDisNoteInvoice")
                                {
                                    CusDisDc.Add(i.ToString(), dt2.Rows[i][6].ToString());
                                }
                            }
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Παρουσιάστηκε κάποιο μη αναμενόμενο σφάλμα στην αναζήτηση του προϊόντος. Παρακαλώ επικοινωνήστε με το διαχειριστή του συστήματος.");
                        }
                        sqlcon.Close();
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Σφάλμα σύνδεσης. Παρακαλώ επικοινωνήστε με το διαχειριστή του συστήματος.");
                    }
                }
            }
        }
Esempio n. 2
0
        private void RetrieveBtn_Click(object sender, EventArgs e)
        {
            if (SearchNameTxt.Text == "" && SearchAfmTxt.Text == "" && SelectNameCmb.SelectedIndex == -1)
            {
                MessageBox.Show("Θα πρέπει πρώτα να εισάγετε Επωνυμία ή Α.Φ.Μ. του προμηθευτή.");
            }
            else if (Convert.ToDateTime(DateFrom.Value.ToShortDateString()) > Convert.ToDateTime(DateTo.Value.ToShortDateString()) || Convert.ToDateTime(DateFrom.Value.ToShortDateString()) > Convert.ToDateTime(DateTime.Today.ToShortDateString()) || Convert.ToDateTime(DateTo.Value.ToShortDateString()) > Convert.ToDateTime(DateTime.Today.ToShortDateString()))
            {
                MessageBox.Show("Θα πρέπει να επιλέξετε έγκυρες ημερομηνίες.");
            }
            else
            {
                using (SqlConnection sqlcon = new SqlConnection(con.ConnectionString))
                {
                    try
                    {
                        sqlcon.Open();
                        try
                        {
                            string query;
                            string param;
                            if (SearchNameTxt.Text != "")
                            {
                                query = "select Id,Name,Afm from Suppliers where UPPER(Name)=@parameter";
                                param = SearchNameTxt.Text;
                            }
                            else if (SearchAfmTxt.Text != "")
                            {
                                query = "select Id,Name,Afm from Suppliers where Afm=@parameter";
                                param = SearchAfmTxt.Text;
                            }
                            else
                            {
                                query = "select Id,Name,Afm from Suppliers where UPPER(Name)=@parameter";
                                param = SelectNameCmb.GetItemText(SelectNameCmb.SelectedItem);
                            }

                            SqlDataAdapter SearchAdapt = new SqlDataAdapter(query, sqlcon);
                            SearchAdapt.SelectCommand.Parameters.AddWithValue(@"parameter", param);
                            DataTable dt = new DataTable();
                            SearchAdapt.Fill(dt);
                            if (dt.Rows.Count == 0)
                            {
                                MessageBox.Show("Δε βρέθηκε προμηθευτής με τα στοιχεία που εισάγατε.");
                            }
                            else if (dt.Rows.Count > 1)
                            {
                                MessageBox.Show("Υπάρχουν " + dt.Rows.Count + " καταχωρημένοι προμηθευτές με τα στοιχεία που έχετε εισάγει. Παρακαλώ αλλάξτε τρόπο αναζήτησης.");
                            }
                            else
                            {
                                IdTxt.Text   = dt.Rows[0][0].ToString();
                                NameTxt.Text = dt.Rows[0][1].ToString();
                                AfmTxt.Text  = dt.Rows[0][2].ToString();

                                decimal        InitialDebit = 0;
                                string         query4       = @"select dbo.nvl(cast(Debit as decimal(18,2))-POS,0.00) from Suppliers b,(select dbo.nvl(sum(POS),0.00) as POS from
                                (select sum(cast(InvoicePrice as decimal(18,2))) as POS from SupplierInvoice where SupplierId = @id and InvoiceDate>=cast(@datefrom as Date)
                                union
                                select -sum(cast(DebitInvoicePrice as decimal(18,2))) from SupplierDebitInvoice where SupplierId = @id and DebitInvoiceDate>=cast(@datefrom as Date)
                                union
                                select -sum(cast(Price as decimal(18,2))) from SupplierBankDeposits where SupplierId = @id  and Date>=cast(@datefrom as Date)
                                union
                                select -sum(cast(ReceiptPrice as decimal(18,2))) from SupplierReceipt where SupplierId = @id  and ReceiptDate>=cast(@datefrom as Date)
                                union
                                select -sum(cast(ReceiptPrice as decimal(18,2))) from MySupplierReceipt where SupplierId = @id  and ReceiptDate>=cast(@datefrom as Date)) a) c
								where b.Id = @id"                                ;
                                SqlDataAdapter SearchAdapt4 = new SqlDataAdapter(query4, sqlcon);
                                SearchAdapt4.SelectCommand.Parameters.AddWithValue(@"id", IdTxt.Text);
                                SearchAdapt4.SelectCommand.Parameters.AddWithValue(@"datefrom", DateFrom.Value.ToShortDateString());
                                DataTable dt4 = new DataTable();
                                SearchAdapt4.Fill(dt4);
                                if (dt4.Rows.Count == 1)
                                {
                                    InitialDebit = Convert.ToDecimal(dt4.Rows[0][0].ToString());
                                }

                                string         query2       = @"select distinct InvoiceId,InvoiceSeries,InvoiceDate,InvoicePrice,Prev,Id from
                                (select InvoiceId, InvoiceSeries, InvoiceDate, InvoicePrice,'Invoice' Prev,Id from SupplierInvoice where SupplierId = @id
                                union
                                select DebitInvoiceId, DebitInvoiceSeries, DebitInvoiceDate, DebitInvoicePrice,'DebitInvoice',Id from SupplierDebitInvoice where SupplierId = @id
                                union
                                select Doc, '', Date, Price,'BankDeposits',Id from SupplierBankDeposits where SupplierId = @id
                                union
                                select ReceiptId, ReceiptSeries, ReceiptDate, ReceiptPrice,'Receipt',Id from SupplierReceipt where SupplierId = @id 
                                union
                                select ReceiptId, ReceiptSeries, ReceiptDate, ReceiptPrice,'Receipt',Id from MySupplierReceipt where SupplierId = @id ) a
                                where a.InvoiceDate>=cast(@datefrom as Date) and a.InvoiceDate<=cast(@dateto as Date)
                                order by InvoiceDate";
                                SqlDataAdapter SearchAdapt2 = new SqlDataAdapter(query2, sqlcon);
                                SearchAdapt2.SelectCommand.Parameters.AddWithValue(@"id", IdTxt.Text);
                                SearchAdapt2.SelectCommand.Parameters.AddWithValue(@"datefrom", DateFrom.Value.ToShortDateString());
                                SearchAdapt2.SelectCommand.Parameters.AddWithValue(@"dateto", DateTo.Value.ToShortDateString());
                                DataTable dt2 = new DataTable();
                                SearchAdapt2.Fill(dt2);
                                CardSupplierLst.Items.Clear();
                                lsview.Clear();
                                string[] Lbl = new string[] {
                                    "",
                                    "",
                                    "Ημ. λήξης αξιογράφου     -     Αξία",
                                    "",
                                    "",
                                    ""
                                };
                                List <string[]> DataLst = new List <string[]>();
                                decimal         PriceT  = InitialDebit;
                                string[]        mtf     = new string[] {
                                    "",
                                    "",
                                    "*** ΑΠΟ ΜΕΤΑΦΟΡΑ ΤΗΝ " + Convert.ToDateTime(DateFrom.Value).Day + "/" + Convert.ToDateTime(DateFrom.Value).Month + "/" + Convert.ToDateTime(DateFrom.Value).Year + " ***",
                                    "",
                                    "",
                                    InitialDebit.ToString()
                                };
                                lsview.Add(mtf);
                                CardSupplierLst.Items.Add(new ListViewItem(mtf));
                                for (int i = 0; (i < dt2.Rows.Count); i++)
                                {
                                    DataLst.Clear();
                                    DateTime dat    = Convert.ToDateTime(dt2.Rows[i][2].ToString());
                                    string   Reason = "";
                                    string   PriceX = "0";
                                    string   PriceP = "0";
                                    if (dt2.Rows[i][4].ToString() == "Invoice")
                                    {
                                        Reason = "ΤΙΜΟΛΟΓΙΟ ΠΩΛΗΣΗΣ";
                                        PriceP = dt2.Rows[i][3].ToString();
                                    }
                                    else if (dt2.Rows[i][4].ToString() == "DebitInvoice")
                                    {
                                        Reason = "ΠΙΣΤΩΤΙΚΟ ΤΙΜΟΛΟΓΙΟ";
                                        PriceX = dt2.Rows[i][3].ToString();
                                    }
                                    else if (dt2.Rows[i][4].ToString() == "Receipt")
                                    {
                                        Reason = "ΠΛΗΡΩΜΗ ΜΕΤΡΗΤΩΝ/ΠΑΡΑΔΟΣΗ ΑΞΙΟΓΡΑΦΩΝ";
                                        string         query3       = @"select ValueDocId,ValueDocDate,ValueDocPrice from ReceiptValueDocs where ReceiptKind='1' and ReceiptId=@id";
                                        SqlDataAdapter SearchAdapt3 = new SqlDataAdapter(query3, sqlcon);
                                        SearchAdapt3.SelectCommand.Parameters.AddWithValue(@"id", dt2.Rows[i][5].ToString());
                                        DataTable dt3 = new DataTable();
                                        SearchAdapt3.Fill(dt3);
                                        for (int j = 0; (j < dt3.Rows.Count); j++)
                                        {
                                            string[] datals = new string[] {
                                                "",
                                                "",
                                                Convert.ToDateTime(dt3.Rows[j][1].ToString()).Day + "/" + Convert.ToDateTime(dt3.Rows[j][1].ToString()).Month + "/" + Convert.ToDateTime(dt3.Rows[j][1].ToString()).Year + "                        -     " + dt3.Rows[j][2].ToString(),
                                                "",
                                                "",
                                                ""
                                            };
                                            DataLst.Add(datals);
                                        }
                                        PriceX = dt2.Rows[i][3].ToString();
                                    }
                                    else if (dt2.Rows[i][4].ToString() == "BankDeposits")
                                    {
                                        Reason = "ΕΜΒΑΣΜΑ ΣΕ ΤΡΑΠΕΖΑ";
                                        PriceX = dt2.Rows[i][3].ToString();
                                    }

                                    PriceT = PriceT + Convert.ToDecimal(PriceP) - Convert.ToDecimal(PriceX);

                                    string[] data = new string[] {
                                        dat.Date.Day + "/" + dat.Date.Month + "/" + dat.Date.Year,
                                        dt2.Rows[i][0].ToString() + "/" + dt2.Rows[i][1].ToString(),
                                        Reason,
                                        PriceX,
                                        PriceP,
                                        PriceT.ToString()
                                    };
                                    lsview.Add(data);
                                    CardSupplierLst.Items.Add(new ListViewItem(data));
                                    if (DataLst.Count() > 0)
                                    {
                                        lsview.Add(Lbl);
                                        CardSupplierLst.Items.Add(new ListViewItem(Lbl));
                                        foreach (var item in DataLst)
                                        {
                                            lsview.Add(item);
                                            CardSupplierLst.Items.Add(new ListViewItem(item));
                                        }
                                    }
                                }
                                string[] mtf2 = new string[] {
                                    "",
                                    "",
                                    "*** ΣΕ ΜΕΤΑΦΟΡΑ ΤΗΝ " + Convert.ToDateTime(DateTo.Value).Day + "/" + Convert.ToDateTime(DateTo.Value).Month + "/" + Convert.ToDateTime(DateTo.Value).Year + " ***",
                                    "",
                                    "",
                                    PriceT.ToString()
                                };
                                lsview.Add(mtf2);
                                CardSupplierLst.Items.Add(new ListViewItem(mtf2));
                                BankDepositPanel.Enabled = true;
                            }
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Παρουσιάστηκε κάποιο μη αναμενόμενο σφάλμα στην αναζήτηση της καρτέλας του προμηθευτή. Παρακαλώ επικοινωνήστε με το διαχειριστή του συστήματος.");
                        }
                        sqlcon.Close();
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Σφάλμα σύνδεσης. Παρακαλώ επικοινωνήστε με το διαχειριστή του συστήματος.");
                    }
                }
            }
        }
Esempio n. 3
0
        private void RetrieveBtn_Click(object sender, EventArgs e)
        {
            if (SearchNameTxt.Text == "" && SearchAfmTxt.Text == "" && SelectNameCmb.SelectedIndex == -1)
            {
                MessageBox.Show("Θα πρέπει πρώτα να εισάγετε Επωνυμία ή Α.Φ.Μ. του πελάτη.");
            }
            else
            {
                using (SqlConnection sqlcon = new SqlConnection(con.ConnectionString))
                {
                    try
                    {
                        sqlcon.Open();
                        try
                        {
                            string query;
                            string param;
                            if (SearchNameTxt.Text != "")
                            {
                                query = "select Id,Name,Occupation,Afm,Address,Phone,Email,Tax_office,Credit,Tk,dbo.FVAL_CUSTOMER_VAT(Id,24),dbo.FVAL_CUSTOMER_PHONE2(Id),dbo.FVAL_CUSTOMER_MAXCREDIT(Id),Retail,Region from Customers where UPPER(Name)=@parameter";
                                param = SearchNameTxt.Text;
                            }
                            else if (SearchAfmTxt.Text != "")
                            {
                                query = "select Id,Name,Occupation,Afm,Address,Phone,Email,Tax_office,Credit,Tk,dbo.FVAL_CUSTOMER_VAT(Id,24),dbo.FVAL_CUSTOMER_PHONE2(Id),dbo.FVAL_CUSTOMER_MAXCREDIT(Id),Retail,Region from Customers where Afm=@parameter";
                                param = SearchAfmTxt.Text;
                            }
                            else
                            {
                                query = "select Id,Name,Occupation,Afm,Address,Phone,Email,Tax_office,Credit,Tk,dbo.FVAL_CUSTOMER_VAT(Id,24),dbo.FVAL_CUSTOMER_PHONE2(Id),dbo.FVAL_CUSTOMER_MAXCREDIT(Id),Retail,Region from Customers where UPPER(Name)=@parameter";
                                param = SelectNameCmb.GetItemText(SelectNameCmb.SelectedItem);
                            }

                            SqlDataAdapter SearchAdapt = new SqlDataAdapter(query, sqlcon);
                            SearchAdapt.SelectCommand.Parameters.AddWithValue(@"parameter", param);
                            DataTable dt = new DataTable();
                            SearchAdapt.Fill(dt);
                            if (dt.Rows.Count == 0)
                            {
                                MessageBox.Show("Δε βρέθηκε πελάτης με τα στοιχεία που εισάγατε.");
                            }
                            else if (dt.Rows.Count > 1)
                            {
                                MessageBox.Show("Υπάρχουν " + dt.Rows.Count + " καταχωρημένοι πελάτες με τα στοιχεία που έχετε εισάγει. Παρακαλώ αλλάξτε τρόπο αναζήτησης.");
                            }
                            else
                            {
                                IdTxt.Text                  = dt.Rows[0][0].ToString();
                                NameTxt.Text                = dt.Rows[0][1].ToString();
                                OccupationTxt.Text          = dt.Rows[0][2].ToString();
                                AfmTxt.Text                 = dt.Rows[0][3].ToString();
                                AddressTxt.Text             = dt.Rows[0][4].ToString();
                                PhoneTxt.Text               = dt.Rows[0][5].ToString();
                                EmailTxt.Text               = dt.Rows[0][6].ToString();
                                Tax_officeTxt.Text          = dt.Rows[0][7].ToString();
                                CreditTxt.Text              = dt.Rows[0][8].ToString();
                                TkTxt.Text                  = dt.Rows[0][9].ToString();
                                VatTxt.Text                 = dt.Rows[0][10].ToString();
                                Phone2Txt.Text              = dt.Rows[0][11].ToString();
                                MaxCreditTxt.Text           = dt.Rows[0][12].ToString();
                                RetailBox.Checked           = (dt.Rows[0][13].ToString() == "1" ?true :false);
                                RegionTxt.Text              = dt.Rows[0][14].ToString();
                                SearchNameTxt.Text          = "";
                                SearchAfmTxt.Text           = "";
                                SelectNameCmb.SelectedIndex = -1;
                                EditBtn.Visible             = true;
                            }
                            string         query2       = @"select distinct Right('          '+InvoiceId,15),Right('          '+InvoiceSeries,8),InvoiceDate,Right('          '+InvoicePrice,18),Prev,Id from
                            (select InvoiceId, InvoiceSeries, InvoiceDate, InvoicePrice,'Invoice' Prev,Id from CustomerInvoice where CustomerId = @id
                            union
                            select DebitInvoiceId, DebitInvoiceSeries, DebitInvoiceDate, DebitInvoicePrice,'DebitInvoice',Id from CustomerDebitInvoice where CustomerId = @id
                            union
                            select DisNoteId, DisNoteSeries, DisNoteDate, '','DisNote',Id from CustomerDisNote where CustomerId = @id
                            union
                            select ReceiptId, ReceiptSeries, ReceiptDate, ReceiptPrice,'Receipt',Id from CustomerReceipt where CustomerId = @id ) a
                            order by InvoiceDate desc";
                            SqlDataAdapter SearchAdapt2 = new SqlDataAdapter(query2, sqlcon);
                            SearchAdapt2.SelectCommand.Parameters.AddWithValue(@"id", IdTxt.Text);
                            DataTable dt2 = new DataTable();
                            SearchAdapt2.Fill(dt2);
                            DocumentLbx.Items.Clear();
                            InvDc.Clear();
                            DebDc.Clear();
                            DisDc.Clear();
                            RecDc.Clear();
                            for (int i = 0; (i < dt2.Rows.Count); i++)
                            {
                                DateTime dat = Convert.ToDateTime(dt2.Rows[i][2].ToString());
                                DocumentLbx.Items.Add(dt2.Rows[i][0].ToString() + " /" + dt2.Rows[i][1].ToString() + "   -   " + dat.Date.Day + "/" + dat.Date.Month + "/" + dat.Date.Year + "   -   " + dt2.Rows[i][3].ToString());
                                if (dt2.Rows[i][4].ToString() == "Invoice")
                                {
                                    InvDc.Add(i.ToString(), dt2.Rows[i][5].ToString());
                                }
                                else if (dt2.Rows[i][4].ToString() == "DebitInvoice")
                                {
                                    DebDc.Add(i.ToString(), dt2.Rows[i][5].ToString());
                                }
                                else if (dt2.Rows[i][4].ToString() == "DisNote")
                                {
                                    DisDc.Add(i.ToString(), dt2.Rows[i][5].ToString());
                                }
                                else if (dt2.Rows[i][4].ToString() == "Receipt")
                                {
                                    RecDc.Add(i.ToString(), dt2.Rows[i][5].ToString());
                                }
                            }
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Παρουσιάστηκε κάποιο μη αναμενόμενο σφάλμα στην ανάκτηση του πελάτη. Παρακαλώ επικοινωνήστε με το διαχειριστή του συστήματος.");
                        }
                        sqlcon.Close();
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Σφάλμα σύνδεσης. Παρακαλώ επικοινωνήστε με το διαχειριστή του συστήματος.");
                    }
                }
            }
        }
Esempio n. 4
0
        private void RetrieveBtn_Click(object sender, EventArgs e)
        {
            if (SearchNameTxt.Text == "" && SearchIdTxt.Text == "" && SelectNameCmb.SelectedIndex == -1)
            {
                MessageBox.Show("Θα πρέπει πρώτα να εισάγετε περιγραφή ή κωδικό του προϊόντος.");
            }
            else
            {
                using (SqlConnection sqlcon = new SqlConnection(con.ConnectionString))
                {
                    try
                    {
                        sqlcon.Open();
                        try
                        {
                            string query;
                            string param;
                            if (SearchNameTxt.Text != "")
                            {
                                query = "select Id,Description from Products where UPPER(Description)=@parameter";
                                param = SearchNameTxt.Text;
                            }
                            else if (SearchIdTxt.Text != "")
                            {

                                query = "select Id,Description from Products where Id=@parameter";
                                param = SearchIdTxt.Text;
                            }
                            else
                            {
                                query = "select Id,Description from Products where UPPER(Description)=@parameter";
                                param = SelectNameCmb.GetItemText(SelectNameCmb.SelectedItem);
                            }

                            SqlDataAdapter SearchAdapt = new SqlDataAdapter(query, sqlcon);
                            SearchAdapt.SelectCommand.Parameters.AddWithValue(@"parameter", param);
                            DataTable dt = new DataTable();
                            SearchAdapt.Fill(dt);
                            if (dt.Rows.Count == 0)
                            {
                                MessageBox.Show("Δε βρέθηκε προϊόν με τα στοιχεία που εισάγατε.");
                            }
                            else if (dt.Rows.Count > 1)
                            {
                                MessageBox.Show("Υπάρχουν " + dt.Rows.Count + " καταχωρημένα προϊόντα με τα στοιχεία που έχετε εισάγει. Παρακαλώ αλλάξτε τρόπο αναζήτησης.");
                            }
                            else
                            {
                                IdTxt.Text = dt.Rows[0][0].ToString();
                                DescrTxt.Text = dt.Rows[0][1].ToString();
                                SearchNameTxt.Text = "";
                                SearchIdTxt.Text = "";
                                SelectNameCmb.SelectedIndex = -1;
                                AddBtn.Visible = true;
                            }
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Παρουσιάστηκε κάποιο μη αναμενόμενο σφάλμα στην αναζήτηση του προϊόντος. Παρακαλώ επικοινωνήστε με το διαχειριστή του συστήματος.");
                        }
                        sqlcon.Close();
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Σφάλμα σύνδεσης. Παρακαλώ επικοινωνήστε με το διαχειριστή του συστήματος.");
                    }
                }
            }
        }
Esempio n. 5
0
        private void RetrieveBtn_Click(object sender, EventArgs e)
        {
            if (SearchNameTxt.Text == "" && SearchAfmTxt.Text == "" && SelectNameCmb.SelectedIndex == -1)
            {
                MessageBox.Show("Θα πρέπει πρώτα να εισάγετε Επωνυμία ή Α.Φ.Μ. του πελάτη.");
            }
            else
            {
                using (SqlConnection sqlcon = new SqlConnection(con.ConnectionString))
                {
                    try
                    {
                        sqlcon.Open();
                        try
                        {
                            string query;
                            string param;
                            if (SearchNameTxt.Text != "")
                            {
                                query = "select Id,Name,Afm,Credit,Occupation,Address,Tk,Tax_office,Phone, Email,dbo.FVAL_CUSTOMER_PHONE2(Id), Region, Retail from Customers where UPPER(Name)=@parameter";
                                param = SearchNameTxt.Text;
                            }
                            else if (SearchAfmTxt.Text != "")
                            {
                                query = "select Id,Name,Afm,Credit,Occupation,Address,Tk,Tax_office,Phone, Email,dbo.FVAL_CUSTOMER_PHONE2(Id), Region, Retail from Customers where Afm=@parameter";
                                param = SearchAfmTxt.Text;
                            }
                            else
                            {
                                query = "select Id,Name,Afm,Credit,Occupation,Address,Tk,Tax_office,Phone, Email,dbo.FVAL_CUSTOMER_PHONE2(Id), Region, Retail from Customers where UPPER(Name)=@parameter";
                                param = SelectNameCmb.GetItemText(SelectNameCmb.SelectedItem);
                            }

                            SqlDataAdapter SearchAdapt = new SqlDataAdapter(query, sqlcon);
                            SearchAdapt.SelectCommand.Parameters.AddWithValue(@"parameter", param);
                            DataTable dt = new DataTable();
                            SearchAdapt.Fill(dt);
                            if (dt.Rows.Count == 0)
                            {
                                MessageBox.Show("Δε βρέθηκε πελάτης με τα στοιχεία που εισάγατε.");
                            }
                            else if (dt.Rows.Count > 1)
                            {
                                MessageBox.Show("Υπάρχουν " + dt.Rows.Count + " καταχωρημένοι προμηθευτές με τα στοιχεία που έχετε εισάγει. Παρακαλώ αλλάξτε τρόπο αναζήτησης.");
                            }
                            else
                            {
                                CustomerId                  = dt.Rows[0][0].ToString();
                                CustomerName                = dt.Rows[0][1].ToString();
                                CustomerAfm                 = dt.Rows[0][2].ToString();
                                CustomerCredit              = dt.Rows[0][3].ToString();
                                CustomerOccupation          = dt.Rows[0][4].ToString();
                                CustomerAddress             = dt.Rows[0][5].ToString();
                                CustomerTk                  = dt.Rows[0][6].ToString();
                                CustomerTax_office          = dt.Rows[0][7].ToString();
                                CustomerPhone               = dt.Rows[0][8].ToString();
                                CustomerEmail               = dt.Rows[0][9].ToString();
                                CustomerPhone2              = dt.Rows[0][10].ToString();
                                CustomerRegion              = dt.Rows[0][11].ToString();
                                CustomerRetail              = dt.Rows[0][12].ToString();
                                SearchNameTxt.Text          = "";
                                SearchAfmTxt.Text           = "";
                                SelectNameCmb.SelectedIndex = -1;
                                this.Close();
                            }
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Παρουσιάστηκε κάποιο μη αναμενόμενο σφάλμα στην αναζήτηση του πελάτη. Παρακαλώ επικοινωνήστε με το διαχειριστή του συστήματος.");
                        }
                        sqlcon.Close();
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Σφάλμα σύνδεσης. Παρακαλώ επικοινωνήστε με το διαχειριστή του συστήματος.");
                    }
                }
            }
        }