Ejemplo n.º 1
0
        private void AddBtn_Click(object sender, EventArgs e)
        {
            string errorMessages = "";

            if (NameTxt.Text == "" || OccupationTxt.Text == "" || AfmTxt.Text == "" || AddressTxt.Text == "" || RegionTxt.Text == "" || PhoneTxt.Text == "" || Tax_officeTxt.Text == "")
            {
                errorMessages = "- Θα πρέπει να συμπληρώσετε όλα τα πεδία με αστερίσκο (*).\n";;
            }
            else
            {
                errorMessages += chk.CheckAfm(AfmTxt.Text);
                errorMessages += chk.CheckPhone(PhoneTxt.Text);
                if (Phone2Txt.Visible == true)
                {
                    errorMessages += chk.CheckPhone(Phone2Txt.Text);
                }
                if (TkTxt.Text != "")
                {
                    errorMessages += chk.CheckTk(TkTxt.Text);
                }
                if (VatTxt.Text != "")
                {
                    errorMessages += chk.CheckVat(VatTxt.Text);
                }
                if (EmailTxt.Text != "")
                {
                    errorMessages += chk.CheckEmail(EmailTxt.Text);
                }
                if (CreditTxt.Text != "")
                {
                    errorMessages += chk.CheckCredit(CreditTxt.Text);
                }
                if (MaxCreditTxt.Text != "")
                {
                    errorMessages += chk.CheckMaxCredit(MaxCreditTxt.Text);
                }
            }
            if (errorMessages != "")
            {
                MessageBox.Show(errorMessages);
            }
            else
            {
                using (SqlConnection sqlcon = new SqlConnection(con.ConnectionString))
                {
                    try
                    {
                        sqlcon.Open();
                        SqlDataAdapter SearchAdapt = new SqlDataAdapter("select * from Customers where Afm=@parameter", sqlcon);
                        SearchAdapt.SelectCommand.Parameters.AddWithValue(@"parameter", AfmTxt.Text);
                        DataTable dt = new DataTable();
                        SearchAdapt.Fill(dt);
                        if (dt.Rows.Count > 0)
                        {
                            MessageBox.Show("Υπάρχει ήδη καταχωρημένος πελάτης με το Α.Φ.Μ. που έχετε εισάγει.");
                        }
                        else
                        {
                            SqlDataAdapter SearchAdapt2 = new SqlDataAdapter("select dbo.nvl(Max(Id)+1,1000) from Customers", sqlcon);
                            DataTable      dt2          = new DataTable();
                            SearchAdapt2.Fill(dt2);
                            if (dt2.Rows.Count == 1)
                            {
                                CustomerId = dt2.Rows[0][0].ToString();
                            }
                            SqlTransaction InsTrans = sqlcon.BeginTransaction("InsertTransaction");
                            SqlCommand     InsCmd1  = sqlcon.CreateCommand();
                            InsCmd1.Connection = sqlcon;
                            SqlCommand InsCmd2 = sqlcon.CreateCommand();
                            InsCmd2.Connection = sqlcon;
                            SqlCommand InsCmd3 = sqlcon.CreateCommand();
                            InsCmd3.Connection = sqlcon;
                            SqlCommand InsCmd4 = sqlcon.CreateCommand();
                            InsCmd4.Connection  = sqlcon;
                            InsCmd1.Transaction = InsTrans;
                            InsCmd2.Transaction = InsTrans;
                            InsCmd3.Transaction = InsTrans;
                            InsCmd4.Transaction = InsTrans;
                            try
                            {
                                InsCmd1.CommandText = "insert into Customers(Id, Name, Occupation, Address, Tk, Afm, Tax_office, Phone, Email, Credit, Retail, Region) values(@id, @name, @occup, @addr, @tk, @afm, @to, @phone, @email, @credit, @ret, @reg)";
                                InsCmd1.Parameters.AddWithValue("@id", CustomerId);
                                InsCmd1.Parameters.AddWithValue("@name", NameTxt.Text);
                                InsCmd1.Parameters.AddWithValue("@occup", OccupationTxt.Text);
                                InsCmd1.Parameters.AddWithValue("@addr", AddressTxt.Text);
                                InsCmd1.Parameters.AddWithValue("@tk", TkTxt.Text);
                                InsCmd1.Parameters.AddWithValue("@afm", AfmTxt.Text);
                                InsCmd1.Parameters.AddWithValue("@to", Tax_officeTxt.Text);
                                InsCmd1.Parameters.AddWithValue("@phone", PhoneTxt.Text);
                                InsCmd1.Parameters.AddWithValue("@email", EmailTxt.Text);
                                InsCmd1.Parameters.AddWithValue("@credit", ((CreditTxt.Text == "") ? "0" : CreditTxt.Text));
                                InsCmd1.Parameters.AddWithValue("@ret", (RetailBox.Checked ? "1" : "0"));
                                InsCmd1.Parameters.AddWithValue("@reg", RegionTxt.Text);
                                InsCmd1.ExecuteNonQuery();
                                if (Phone2Txt.Text != "")
                                {
                                    InsCmd2.CommandText = "insert into CustomersPhone2 (Id, CustomerId, Phone2) values((select dbo.nvl(Max(Id) + 1, 0) from CustomersPhone2), (select dbo.nvl(Max(Id),1000) from dbo.Customers), @phone2)";
                                    InsCmd2.Parameters.AddWithValue("@phone2", Phone2Txt.Text);
                                    InsCmd2.ExecuteNonQuery();
                                }

                                if (VatTxt.Text != "")
                                {
                                    InsCmd3.CommandText = "insert into CustomersVat (Id,CustomerId,Vat) values ((select dbo.nvl(Max(Id)+1,0) from CustomersVat),(select dbo.nvl(Max(Id),1000) from dbo.Customers),@vat)";
                                    InsCmd3.Parameters.AddWithValue("@vat", VatTxt.Text);
                                    InsCmd3.ExecuteNonQuery();
                                }
                                if (MaxCreditTxt.Text != "")
                                {
                                    InsCmd4.CommandText = "insert into CustomersMaxCredit (Id,CustomerId,MaxCredit) values ((select dbo.nvl(Max(Id)+1,0) from CustomersMaxCredit),(select dbo.nvl(Max(Id),1000) from dbo.Customers),@maxcredit)";
                                    InsCmd4.Parameters.AddWithValue("@maxcredit", MaxCreditTxt.Text);
                                    InsCmd4.ExecuteNonQuery();
                                }
                                InsTrans.Commit();
                                MessageBox.Show("Ο Πελάτης προστέθηκε με επιτυχία.");
                                CustomerName       = NameTxt.Text;
                                CustomerOccupation = OccupationTxt.Text;
                                CustomerAddress    = AddressTxt.Text;
                                CustomerTk         = TkTxt.Text;
                                CustomerTax_office = Tax_officeTxt.Text;
                                CustomerPhone      = PhoneTxt.Text;
                                CustomerPhone2     = Phone2Txt.Text;
                                CustomerEmail      = EmailTxt.Text;
                                CustomerAfm        = AfmTxt.Text;
                                CustomerRegion     = RegionTxt.Text;
                                CustomerCredit     = ((CreditTxt.Text == "") ? "0" : CreditTxt.Text);
                                CustomerRetail     = (RetailBox.Checked ? "1" : "0");
                                ClearValues();
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.GetType() + ": " + ex.Message + "\n Commit Exception \n Παρουσιάστηκε κάποιο μη αναμενόμενο σφάλμα στην καταχώρηση του πελάτη. Παρακαλώ επικοινωνήστε με το διαχειριστή του συστήματος.");
                                try
                                {
                                    InsTrans.Rollback();
                                }
                                catch (Exception ex2)
                                {
                                    MessageBox.Show(ex2.GetType() + ": " + ex2.Message + "\n Rollback Exception \n Παρουσιάστηκε κάποιο μη αναμενόμενο σφάλμα στην καταχώρηση του πελάτη. Παρακαλώ επικοινωνήστε με το διαχειριστή του συστήματος.");
                                }
                            }
                        }
                        sqlcon.Close();
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Σφάλμα σύνδεσης. Παρακαλώ επικοινωνήστε με το διαχειριστή του συστήματος.");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void SaveBtn_Click(object sender, EventArgs e)
        {
            List <string> NewCustomerList = new List <string>(new string[] {
                NameTxt.Text,
                OccupationTxt.Text,
                AfmTxt.Text,
                AddressTxt.Text,
                TkTxt.Text,
                VatTxt.Text,
                PhoneTxt.Text,
                Phone2Txt.Text,
                EmailTxt.Text,
                Tax_officeTxt.Text,
                CreditTxt.Text,
                MaxCreditTxt.Text,
                (RetailBox.Checked ?"1" :"0"),
                RegionTxt.Text
            });
            int cnt = 0;

            for (int i = 0; i < NewCustomerList.Count; i++)
            {
                if (NewCustomerList[i] != CustomerList[i])
                {
                    cnt++;
                }
            }
            if (cnt == 0)
            {
                MessageBox.Show("Δεν έχετε πραγματοποιήσει κάποια αλλαγή στα στοιχεία του πελάτη.");
            }
            else
            {
                string errorMessages = "";
                if (NameTxt.Text == "" || OccupationTxt.Text == "" || AfmTxt.Text == "" || AddressTxt.Text == "" || RegionTxt.Text == "" || PhoneTxt.Text == "" || Tax_officeTxt.Text == "")
                {
                    errorMessages = "- Θα πρέπει να συμπληρώσετε όλα τα απαραίτητα πεδία.\n";;
                }
                else
                {
                    errorMessages += chk.CheckAfm(AfmTxt.Text);
                    errorMessages += chk.CheckPhone(PhoneTxt.Text);
                    if (Phone2Txt.Visible == true)
                    {
                        errorMessages += chk.CheckPhone(Phone2Txt.Text);
                    }
                    if (TkTxt.Text != "")
                    {
                        errorMessages += chk.CheckTk(TkTxt.Text);
                    }
                    if (VatTxt.Text != "")
                    {
                        errorMessages += chk.CheckVat(VatTxt.Text);
                    }
                    if (EmailTxt.Text != "")
                    {
                        errorMessages += chk.CheckEmail(EmailTxt.Text);
                    }
                    if (CreditTxt.Text != "")
                    {
                        errorMessages += chk.CheckCredit(CreditTxt.Text);
                    }
                    if (MaxCreditTxt.Text != "")
                    {
                        errorMessages += chk.CheckMaxCredit(MaxCreditTxt.Text);
                    }
                }
                if (errorMessages != "")
                {
                    MessageBox.Show(errorMessages);
                }
                else
                {
                    using (SqlConnection sqlcon = new SqlConnection(con.ConnectionString))
                    {
                        try
                        {
                            sqlcon.Open();
                            SqlDataAdapter SearchAdapt = new SqlDataAdapter("select * from Customers where Afm=@afm and Id!=@id", sqlcon);
                            SearchAdapt.SelectCommand.Parameters.AddWithValue(@"afm", AfmTxt.Text);
                            SearchAdapt.SelectCommand.Parameters.AddWithValue(@"id", IdTxt.Text);
                            DataTable dt = new DataTable();
                            SearchAdapt.Fill(dt);
                            if (dt.Rows.Count > 0)
                            {
                                MessageBox.Show("Υπάρχει ήδη καταχωρημένος πελάτης με το Α.Φ.Μ. που έχετε εισάγει.");
                            }
                            else
                            {
                                SqlTransaction InsTrans = sqlcon.BeginTransaction("UpdateTransaction");
                                SqlCommand     UpdCmd1  = sqlcon.CreateCommand();
                                UpdCmd1.Connection = sqlcon;
                                SqlCommand UpdCmd2 = sqlcon.CreateCommand();
                                UpdCmd2.Connection = sqlcon;
                                SqlCommand UpdCmd3 = sqlcon.CreateCommand();
                                UpdCmd3.Connection = sqlcon;
                                SqlCommand UpdCmd4 = sqlcon.CreateCommand();
                                UpdCmd4.Connection  = sqlcon;
                                UpdCmd1.Transaction = InsTrans;
                                UpdCmd2.Transaction = InsTrans;
                                UpdCmd3.Transaction = InsTrans;
                                UpdCmd4.Transaction = InsTrans;
                                try
                                {
                                    UpdCmd1.CommandText = "update Customers set Name=@name, Occupation=@occup, Address = @addr, Tk = @tk, Afm = @afm, Tax_office = @to, Phone = @phone, Email= @email, Credit= @credit , Retail= @ret, Region=@reg where Id=@id";
                                    UpdCmd1.Parameters.AddWithValue("@name", NameTxt.Text);
                                    UpdCmd1.Parameters.AddWithValue("@occup", OccupationTxt.Text);
                                    UpdCmd1.Parameters.AddWithValue("@addr", AddressTxt.Text);
                                    UpdCmd1.Parameters.AddWithValue("@tk", TkTxt.Text);
                                    UpdCmd1.Parameters.AddWithValue("@afm", AfmTxt.Text);
                                    UpdCmd1.Parameters.AddWithValue("@to", Tax_officeTxt.Text);
                                    UpdCmd1.Parameters.AddWithValue("@phone", PhoneTxt.Text);
                                    UpdCmd1.Parameters.AddWithValue("@email", EmailTxt.Text);
                                    UpdCmd1.Parameters.AddWithValue("@credit", ((CreditTxt.Text == "") ? "0" : CreditTxt.Text));
                                    UpdCmd1.Parameters.AddWithValue("@ret", ((RetailBox.Checked) ? "1" : "0"));
                                    UpdCmd1.Parameters.AddWithValue("@reg", RegionTxt.Text);
                                    UpdCmd1.Parameters.AddWithValue("@id", IdTxt.Text);
                                    UpdCmd1.ExecuteNonQuery();
                                    if (NewCustomerList[7] != "" && CustomerList[7] == "") //phone2
                                    {
                                        UpdCmd2.CommandText = "insert into CustomersPhone2 (Id, CustomerId, Phone2) values((select dbo.nvl(Max(Id) + 1, 0) from CustomersPhone2), @id, @phone2)";
                                        UpdCmd2.Parameters.AddWithValue("@id", IdTxt.Text);
                                        UpdCmd2.Parameters.AddWithValue("@phone2", Phone2Txt.Text);
                                        UpdCmd2.ExecuteNonQuery();
                                    }
                                    else if (NewCustomerList[7] == "" && CustomerList[7] != "")
                                    {
                                        UpdCmd2.CommandText = "delete CustomersPhone2 where CustomerId=@id";
                                        UpdCmd2.Parameters.AddWithValue("@id", IdTxt.Text);
                                        UpdCmd2.ExecuteNonQuery();
                                    }
                                    else if (NewCustomerList[7] != "" && CustomerList[7] != "" && CustomerList[7] != NewCustomerList[7])
                                    {
                                        UpdCmd2.CommandText = "update CustomersPhone2 set Phone2=@phone2 where CustomerId=@id";
                                        UpdCmd2.Parameters.AddWithValue("@id", IdTxt.Text);
                                        UpdCmd2.Parameters.AddWithValue("@phone2", Phone2Txt.Text);
                                        UpdCmd2.ExecuteNonQuery();
                                    }


                                    if (NewCustomerList[5] != "" && CustomerList[5] == "") //vat
                                    {
                                        UpdCmd3.CommandText = "insert into CustomersVat (Id,CustomerId,Vat) values ((select dbo.nvl(Max(Id)+1,0) from CustomersVat),@id,@vat)";
                                        UpdCmd3.Parameters.AddWithValue("@id", IdTxt.Text);
                                        UpdCmd3.Parameters.AddWithValue("@vat", VatTxt.Text);
                                        UpdCmd3.ExecuteNonQuery();
                                    }
                                    else if (NewCustomerList[5] == "" && CustomerList[5] != "")
                                    {
                                        UpdCmd3.CommandText = "delete CustomersVat where CustomerId=@id";
                                        UpdCmd3.Parameters.AddWithValue("@id", IdTxt.Text);
                                        UpdCmd3.ExecuteNonQuery();
                                    }
                                    else if (NewCustomerList[5] != "" && CustomerList[5] != "" && CustomerList[5] != NewCustomerList[5])
                                    {
                                        UpdCmd3.CommandText = "update CustomersVat set Vat=@vat where CustomerId=@id";
                                        UpdCmd3.Parameters.AddWithValue("@id", IdTxt.Text);
                                        UpdCmd3.Parameters.AddWithValue("@vat", VatTxt.Text);
                                        UpdCmd3.ExecuteNonQuery();
                                    }

                                    if (NewCustomerList[11] != "" && CustomerList[11] == "") //max credit
                                    {
                                        UpdCmd4.CommandText = "insert into CustomersMaxCredit (Id,CustomerId,MaxCredit) values ((select dbo.nvl(Max(Id)+1,0) from CustomersVat),@id,@maxcredit)";
                                        UpdCmd4.Parameters.AddWithValue("@id", IdTxt.Text);
                                        UpdCmd4.Parameters.AddWithValue("@maxcredit", MaxCreditTxt.Text);
                                        UpdCmd4.ExecuteNonQuery();
                                    }
                                    else if (NewCustomerList[11] == "" && CustomerList[11] != "")
                                    {
                                        UpdCmd4.CommandText = "delete CustomersMaxCredit where CustomerId=@id";
                                        UpdCmd4.Parameters.AddWithValue("@id", IdTxt.Text);
                                        UpdCmd4.ExecuteNonQuery();
                                    }
                                    else if (NewCustomerList[11] != "" && CustomerList[11] != "" && CustomerList[11] != NewCustomerList[11])
                                    {
                                        UpdCmd4.CommandText = "update CustomersMaxCredit set MaxCredit=@maxcredit where CustomerId=@id";
                                        UpdCmd4.Parameters.AddWithValue("@id", IdTxt.Text);
                                        UpdCmd4.Parameters.AddWithValue("@maxcredit", MaxCreditTxt.Text);
                                        UpdCmd4.ExecuteNonQuery();
                                    }
                                    InsTrans.Commit();
                                    MessageBox.Show("Οι αλλαγές πραγματοποιήθηκαν με επιτυχία.");
                                    ClearValues();
                                    NameTxt.Enabled       = false;
                                    OccupationTxt.Enabled = false;
                                    AfmTxt.Enabled        = false;
                                    AddressTxt.Enabled    = false;
                                    RegionTxt.Enabled     = false;
                                    TkTxt.Enabled         = false;
                                    VatTxt.Enabled        = false;
                                    PhoneTxt.Enabled      = false;
                                    Phone2Txt.Enabled     = false;
                                    EmailTxt.Enabled      = false;
                                    Tax_officeTxt.Enabled = false;
                                    CreditTxt.Enabled     = false;
                                    MaxCreditTxt.Enabled  = false;
                                    RetailBox.Enabled     = false;
                                    SearchNameTxt.Enabled = true;
                                    SearchAfmTxt.Enabled  = true;
                                    SelectNameCmb.Enabled = true;
                                    RetrieveBtn.Enabled   = true;
                                    SaveBtn.Visible       = false;
                                    CancelBtn.Visible     = false;
                                    CustomerList.Clear();
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show(ex.GetType() + ": " + ex.Message + "\n Commit Exception \n Παρουσιάστηκε κάποιο μη αναμενόμενο σφάλμα στην καταχώρηση του πελάτη. Παρακαλώ επικοινωνήστε με το διαχειριστή του συστήματος.");
                                    try
                                    {
                                        InsTrans.Rollback();
                                    }
                                    catch (Exception ex2)
                                    {
                                        MessageBox.Show(ex2.GetType() + ": " + ex2.Message + "\n Rollback Exception \n Παρουσιάστηκε κάποιο μη αναμενόμενο σφάλμα στην καταχώρηση του πελάτη. Παρακαλώ επικοινωνήστε με το διαχειριστή του συστήματος.");
                                    }
                                }
                            }
                            sqlcon.Close();
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Σφάλμα σύνδεσης. Παρακαλώ επικοινωνήστε με το διαχειριστή του συστήματος.");
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void SaveBtn_Click(object sender, EventArgs e)
        {
            List <string> NewMyProf = new List <string>(new string[] {
                NameTxt.Text,
                OccupationTxt.Text,
                AfmTxt.Text,
                Tax_officeTxt.Text,
                AddressTxt.Text,
                TkTxt.Text,
                Phone1Txt.Text,
                Phone2Txt.Text,
                EmailTxt.Text,
                VatTxt.Text,
                MaxTotalCreditTxt.Text,
                MaxTotalDebitTxt.Text,
                InvoiceSeriesTxt.Text,
                DebitInvoiceSeriesTxt.Text,
                DisNoteSeriesTxt.Text,
                ReceiptSeriesTxt.Text,
                SupplierReceiptSeriesTxt.Text
            });
            int cnt = 0;

            for (int i = 0; i < NewMyProf.Count; i++)
            {
                if (NewMyProf[i] != MyProf[i])
                {
                    cnt++;
                }
            }
            if (cnt == 0)
            {
                MessageBox.Show("Δεν έχετε πραγματοποιήσει κάποια αλλαγή στα στοιχεία.");
            }
            else
            {
                string errorMessages = "";
                if (NameTxt.Text == "" || OccupationTxt.Text == "" || AfmTxt.Text == "" || AddressTxt.Text == "" || TkTxt.Text == "" || Tax_officeTxt.Text == "" || VatTxt.Text == "" || Phone1Txt.Text == "" || InvoiceSeriesTxt.Text == "" || DebitInvoiceSeriesTxt.Text == "" || DisNoteSeriesTxt.Text == "" || ReceiptSeriesTxt.Text == "" || SupplierReceiptSeriesTxt.Text == "")
                {
                    errorMessages = "- Θα πρέπει να συμπληρώσετε όλα τα απαραίτητα πεδία.\n";
                }
                else
                {
                    errorMessages += chk.CheckAfm(AfmTxt.Text);
                    errorMessages += chk.CheckTk(TkTxt.Text);
                    errorMessages += chk.CheckPhone(Phone1Txt.Text);
                    errorMessages += chk.CheckVat(VatTxt.Text);
                    if (Phone2Txt.Text != "")
                    {
                        errorMessages += chk.CheckPhone(Phone2Txt.Text);
                    }
                    if (EmailTxt.Text != "")
                    {
                        errorMessages += chk.CheckEmail(EmailTxt.Text);
                    }
                    if (MaxTotalCreditTxt.Text != "")
                    {
                        errorMessages += chk.CheckMaxCredit(MaxTotalCreditTxt.Text);
                    }
                    if (MaxTotalDebitTxt.Text != "")
                    {
                        errorMessages += chk.CheckMaxDebit(MaxTotalDebitTxt.Text);
                    }
                }
                if (errorMessages != "")
                {
                    MessageBox.Show(errorMessages);
                }
                else
                {
                    using (SqlConnection sqlcon = new SqlConnection(con.ConnectionString))
                    {
                        sqlcon.Open();

                        SqlCommand Cmd = sqlcon.CreateCommand();
                        Cmd.Connection = sqlcon;
                        if (MyProf[0] == "")
                        {
                            Cmd.CommandText = "insert into MyProfile (Name,Occupation,Address,Tk,Afm,Tax_office,Phone1,Phone2,Email,Vat,MaxTotalCredit,MaxTotalDebit,InvoiceSeries,DebitInvoiceSeries,DisNoteSeries,ReceiptSeries,SupplierReceiptSeries) values (@name,@occup, @addr, @tk, @afm, @to,@phon1,@phon2,@mail,@vat, @maxcredit,@maxdebit,@invser,@dinvser,@disnser,@recser,@suprecser)";
                        }
                        else
                        {
                            Cmd.CommandText = "update MyProfile set Name=@name, Occupation=@occup, Address = @addr, Tk = @tk, Afm = @afm, Tax_office = @to,  Phone1= @phon1,  Phone2= @phon2,  Email= @mail,  Vat= @vat,  MaxTotalCredit= @maxcredit,  MaxTotalDebit= @maxdebit, InvoiceSeries=@invser, DebitInvoiceSeries=@dinvser, DisNoteSeries=@disnser, ReceiptSeries=@recser, SupplierReceiptSeries=@suprecser";
                        }
                        Cmd.Parameters.AddWithValue("@name", NameTxt.Text);
                        Cmd.Parameters.AddWithValue("@occup", OccupationTxt.Text);
                        Cmd.Parameters.AddWithValue("@addr", AddressTxt.Text);
                        Cmd.Parameters.AddWithValue("@tk", TkTxt.Text);
                        Cmd.Parameters.AddWithValue("@afm", AfmTxt.Text);
                        Cmd.Parameters.AddWithValue("@to", Tax_officeTxt.Text);
                        Cmd.Parameters.AddWithValue("@phon1", Phone1Txt.Text);
                        Cmd.Parameters.AddWithValue("@phon2", Phone2Txt.Text);
                        Cmd.Parameters.AddWithValue("@mail", EmailTxt.Text);
                        Cmd.Parameters.AddWithValue("@vat", VatTxt.Text);
                        Cmd.Parameters.AddWithValue("@maxcredit", ((MaxTotalCreditTxt.Text == "") ? "0" : MaxTotalCreditTxt.Text));
                        Cmd.Parameters.AddWithValue("@maxdebit", ((MaxTotalDebitTxt.Text == "") ? "0" : MaxTotalDebitTxt.Text));
                        Cmd.Parameters.AddWithValue("@invser", InvoiceSeriesTxt.Text);
                        Cmd.Parameters.AddWithValue("@dinvser", DebitInvoiceSeriesTxt.Text);
                        Cmd.Parameters.AddWithValue("@disnser", DisNoteSeriesTxt.Text);
                        Cmd.Parameters.AddWithValue("@recser", ReceiptSeriesTxt.Text);
                        Cmd.Parameters.AddWithValue("@suprecser", SupplierReceiptSeriesTxt.Text);
                        Cmd.ExecuteNonQuery();
                        MessageBox.Show("Οι αλλαγές πραγματοποιήθηκαν με επιτυχία.");
                        NameTxt.Enabled                  = false;
                        OccupationTxt.Enabled            = false;
                        AfmTxt.Enabled                   = false;
                        Tax_officeTxt.Enabled            = false;
                        AddressTxt.Enabled               = false;
                        TkTxt.Enabled                    = false;
                        Phone1Txt.Enabled                = false;
                        Phone2Txt.Enabled                = false;
                        EmailTxt.Enabled                 = false;
                        VatTxt.Enabled                   = false;
                        MaxTotalCreditTxt.Enabled        = false;
                        MaxTotalDebitTxt.Enabled         = false;
                        InvoiceSeriesTxt.Enabled         = false;
                        DebitInvoiceSeriesTxt.Enabled    = false;
                        DisNoteSeriesTxt.Enabled         = false;
                        ReceiptSeriesTxt.Enabled         = false;
                        SupplierReceiptSeriesTxt.Enabled = false;
                        SaveBtn.Visible                  = false;
                        CancelBtn.Visible                = false;
                        MyProf.Clear();
                        GetData();

                        sqlcon.Close();
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private void AddBtn_Click(object sender, EventArgs e)
        {
            string errorMessages = "";

            if (NameTxt.Text == "" || OccupationTxt.Text == "" || AfmTxt.Text == "" || AddressTxt.Text == "" || RegionTxt.Text == "" || TkTxt.Text == "" || PhoneTxt.Text == "" || Tax_officeTxt.Text == "")
            {
                errorMessages = "- Θα πρέπει να συμπληρώσετε όλα τα πεδία με αστερίσκο (*).\n";;
            }
            else
            {
                errorMessages += chk.CheckAfm(AfmTxt.Text);
                errorMessages += chk.CheckTk(TkTxt.Text);
                errorMessages += chk.CheckPhone(PhoneTxt.Text);
                if (Phone2Txt.Visible == true)
                {
                    errorMessages += chk.CheckPhone(Phone2Txt.Text);
                }
                if (DebitTxt.Text != "")
                {
                    errorMessages += chk.CheckDebit(DebitTxt.Text);
                }
                if (MaxDebitTxt.Text != "")
                {
                    errorMessages += chk.CheckMaxDebit(MaxDebitTxt.Text);
                }
                if (EmailTxt.Text != "")
                {
                    errorMessages += chk.CheckEmail(EmailTxt.Text);
                }
            }
            if (errorMessages != "")
            {
                MessageBox.Show(errorMessages);
            }
            else
            {
                using (SqlConnection sqlcon = new SqlConnection(con.ConnectionString))
                {
                    try
                    {
                        sqlcon.Open();
                        SqlDataAdapter SearchAdapt = new SqlDataAdapter("select * from Suppliers where Afm=@parameter", sqlcon);
                        SearchAdapt.SelectCommand.Parameters.AddWithValue(@"parameter", AfmTxt.Text);
                        DataTable dt = new DataTable();
                        SearchAdapt.Fill(dt);
                        if (dt.Rows.Count > 0)
                        {
                            MessageBox.Show("Υπάρχει ήδη καταχωρημένος προμηθευτής με το Α.Φ.Μ. που έχετε εισάγει.");
                        }
                        else
                        {
                            SqlTransaction InsTrans = sqlcon.BeginTransaction("InsertTransaction");
                            SqlCommand     InsCmd1  = sqlcon.CreateCommand();
                            InsCmd1.Connection  = sqlcon;
                            InsCmd1.Transaction = InsTrans;
                            try
                            {
                                InsCmd1.CommandText = "insert into Suppliers(Id, Name, Occupation, Address, Tk, Afm, Tax_office,Phone,Email, Debit,Region,Manager,Phone2) values((select dbo.nvl(Max(Id)+1,1000) from dbo.Suppliers), @name, @occup, @addr, @tk, @afm, @to,@phone,@mail, @debit, @reg, @man, @phone2)";
                                InsCmd1.Parameters.AddWithValue("@name", NameTxt.Text);
                                InsCmd1.Parameters.AddWithValue("@occup", OccupationTxt.Text);
                                InsCmd1.Parameters.AddWithValue("@addr", AddressTxt.Text);
                                InsCmd1.Parameters.AddWithValue("@tk", TkTxt.Text);
                                InsCmd1.Parameters.AddWithValue("@afm", AfmTxt.Text);
                                InsCmd1.Parameters.AddWithValue("@to", Tax_officeTxt.Text);
                                InsCmd1.Parameters.AddWithValue("@phone", PhoneTxt.Text);
                                InsCmd1.Parameters.AddWithValue("@mail", EmailTxt.Text);
                                InsCmd1.Parameters.AddWithValue("@debit", ((DebitTxt.Text == "") ? "0" : DebitTxt.Text));
                                InsCmd1.Parameters.AddWithValue("@reg", RegionTxt.Text);
                                InsCmd1.Parameters.AddWithValue("@man", ManagerTxt.Text);
                                InsCmd1.Parameters.AddWithValue("@phone2", Phone2Txt.Text);
                                InsCmd1.ExecuteNonQuery();
                                if (MaxDebitTxt.Text != "")
                                {
                                    InsCmd1.CommandText = "insert into SuppliersMaxDebit (Id,SupplierId,MaxDebit) values ((select dbo.nvl(Max(Id)+1,0) from SuppliersMaxDebit),(select dbo.nvl(Max(Id),1000) from dbo.Suppliers),@maxdebit)";
                                    InsCmd1.Parameters.AddWithValue("@maxdebit", MaxDebitTxt.Text);
                                    InsCmd1.ExecuteNonQuery();
                                }
                                InsTrans.Commit();
                                MessageBox.Show("Ο Προμηθευτής προστέθηκε με επιτυχία.");
                                ClearValues();
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.GetType() + ": " + ex.Message + "\n Commit Exception \n Παρουσιάστηκε κάποιο μη αναμενόμενο σφάλμα στην καταχώρηση του προμηθευτή. Παρακαλώ επικοινωνήστε με το διαχειριστή του συστήματος.");
                                try
                                {
                                    InsTrans.Rollback();
                                }
                                catch (Exception ex2)
                                {
                                    MessageBox.Show(ex2.GetType() + ": " + ex2.Message + "\n Rollback Exception \n Παρουσιάστηκε κάποιο μη αναμενόμενο σφάλμα στην καταχώρηση του προμηθευτή. Παρακαλώ επικοινωνήστε με το διαχειριστή του συστήματος.");
                                }
                            }
                        }
                        sqlcon.Close();
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Σφάλμα σύνδεσης. Παρακαλώ επικοινωνήστε με το διαχειριστή του συστήματος.");
                    }
                }
            }
        }