示例#1
0
        private void zapisDoBazy()
        {
            var MyIni = new INIFile("WektorSettings.ini");

            server   = MyIni.Read("server", "Okna");
            database = MyIni.Read("database", "Okna");
            uid      = MyIni.Read("login", "Okna");
            password = Decrypt(MyIni.Read("pass", "Okna"));

            string          MyConnectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD="******";";
            MySqlConnection connection         = new MySqlConnection(MyConnectionString);

            foreach (DataGridViewRow row in metroGrid1.Rows)
            {
                try
                {
                    MySqlCommand cmd = new MySqlCommand();
                    cmd = connection.CreateCommand();
                    cmd.Parameters.AddWithValue("@nr", numerek.Text);
                    cmd.Parameters.AddWithValue("@indeks", row.Cells[0].Value.ToString());
                    cmd.Parameters.AddWithValue("@nazwa", row.Cells[1].Value.ToString());
                    cmd.Parameters.AddWithValue("@rabat", row.Cells[3].Value.ToString());
                    cmd.Parameters.AddWithValue("@narzut", row.Cells[8].Value.ToString());
                    cmd.Parameters.AddWithValue("@cena", row.Cells[4].Value.ToString());
                    cmd.Parameters.AddWithValue("@ilosc", row.Cells[5].Value.ToString());
                    decimal netto = Decimal.Parse(row.Cells[4].Value.ToString().Replace("zł", ""));
                    decimal ilosc = Decimal.Parse(row.Cells[5].Value.ToString());
                    decimal vat   = Decimal.Parse("1,23");
                    decimal wartN = Math.Round(netto * ilosc);
                    decimal wartB = Math.Round(wartN * vat);
                    decimal wartV = Math.Round(wartB - wartN);
                    cmd.Parameters.AddWithValue("@wartN", wartN);
                    cmd.Parameters.AddWithValue("@wartB", wartB);
                    cmd.Parameters.AddWithValue("@wartV", wartV);
                    cmd.CommandText = "INSERT IGNORE INTO temp (indeks,nazwa,rabat,narzut,cena,wartn,wart_v,wartb,ilosc,wycena_nr) VALUES (@indeks,@nazwa,@rabat,@narzut,@cena,@wartN,@wartV,@wartB,@ilosc,@nr)";
                    connection.Open();
                    cmd.ExecuteNonQuery();
                    connection.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
示例#2
0
        private void db_connection()
        {
            try
            {
                var MyIni = new INIFile("WektorSettings.ini");
                server   = MyIni.Read("server", "Okna");
                database = MyIni.Read("database", "Okna");
                uid      = MyIni.Read("login", "Okna");
                password = Decrypt(MyIni.Read("pass", "Okna"));

                connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD="******";" + "Convert Zero Datetime = True;";
                connect          = new MySqlConnection(connectionString);
                connect.Open();
            }
            catch (MySqlException e)
            {
                throw;
            }
        }
示例#3
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (password.Text == "" || password2.Text == "")
            {
                MessageBox.Show("Wprowadź hasło");
                password.Focus();
                return;
            }
            if (password.Text != password2.Text)
            {
                MessageBox.Show("Hasła nie są takie same");
                password2.Focus();
                return;
            }

            var MyIni = new INIFile("WektorSettings.ini");

            server   = MyIni.Read("server", "Okna");
            database = MyIni.Read("database", "Okna");
            uid      = MyIni.Read("login", "Okna");
            pass     = Decrypt(MyIni.Read("pass", "Okna"));

            string connectionString;

            connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD="******";" + "Convert Zero Datetime = True;";
            MySqlConnection conn = new MySqlConnection(connectionString);

            try
            {
                var command = conn.CreateCommand();
                command.CommandText = "INSERT INTO uzytkownicy (username, password,allowed) VALUES ('" + loginName.Text + "','" + password.Text + "','1')";
                conn.Open();
                command.ExecuteNonQuery();

                MessageBox.Show("Zapisanie danych było udane");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                //MessageBox.Show("Zapisanie danych nie było udane");
            }
        }
示例#4
0
        private void add_product_Load(object sender, EventArgs e)
        {
            szukajka.DisplayMember = "Text";
            szukajka.ValueMember   = "Value";
            var items = new[]
            {
                new { Text = "Indeks", Value = "reference" },
                new { Text = "Nazwa", Value = "nazwa" }
            };

            szukajka.DataSource    = items;
            szukajka.SelectedIndex = 0;

            var MyIni = new INIFile("WektorSettings.ini");

            server   = MyIni.Read("server", "Okna");
            database = MyIni.Read("database", "Okna");
            uid      = MyIni.Read("login", "Okna");
            password = Decrypt(MyIni.Read("pass", "Okna"));
            string connectionString;

            connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD="******";";
            connection       = new MySqlConnection(connectionString);

            if (OpenConnection() == true)
            {
                mySqlDataAdapter = new MySqlDataAdapter("SELECT reference, nazwa, cena, rabat FROM cenniki", connection);
                //DataSet DS = new DataSet();
                mySqlDataAdapter.Fill(ds);
                bindingSource1.DataSource       = ds.Tables[0];
                dataGridView1.DataSource        = bindingSource1;
                bindingNavigator1.BindingSource = bindingSource1;
                CloseConnection();
            }
            ds.Tables[0].Columns[0].ColumnName = "Indeks";
            ds.Tables[0].Columns[1].ColumnName = "Nazwa";
            dataGridView1.Columns[1].Width     = 325;
            dataGridView1.Columns[2].DefaultCellStyle.Format = "c";
        }
示例#5
0
        private void Form1_Load(object sender, EventArgs e)
        {
            AutoUpdater.Start("http://wektor.czest.pl/version.xml");
            System.Timers.Timer timer = new System.Timers.Timer
            {
                Interval            = 2 * 60 * 1000,
                SynchronizingObject = this
            };
            timer.Elapsed += delegate
            {
                AutoUpdater.Start("http://wektor.czest.pl/version.xml");
            };
            timer.Start();

            var MyIni = new INIFile("WektorSettings.ini");

            logged.Text = MyIni.Read("user", "logged");

            try
            {
                db_connection();
                MySqlCommand cmd = new MySqlCommand();
                cmd.CommandText = "Select * from uzytkownicy where username=@user";
                cmd.Parameters.AddWithValue("@user", logged.Text);
                cmd.Connection = connect;
                MySqlDataReader login = cmd.ExecuteReader();

                while (login.Read())
                {
                    string l = login.GetString("admin");

                    if (l == "0")
                    {
                        narzędziaAdministratorToolStripMenuItem.Visible = false;
                        rysujOknotestToolStripMenuItem.Visible          = false;
                        fbFakturyToolStripMenuItem.Visible = false;
                    }
                    else
                    {
                        narzędziaAdministratorToolStripMenuItem.Visible = true;
                        rysujOknotestToolStripMenuItem.Visible          = true;
                        fORM1ToolStripMenuItem.Visible     = true;
                        fbFakturyToolStripMenuItem.Visible = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#6
0
        public void PerformRefresh(object sender, EventArgs e)
        {
            //zapisujemy pozycję
            var MyIni = new INIFile("WektorSettings.ini");
            int index = dataGridView1.CurrentRow.Index;

            MyIni.Write("poz", index.ToString(), "poz");
            //przeładowywujemy tabelę
            zamowienia_Load(e, e);
            //odczytujemy pozycję
            var poz = Convert.ToInt32(MyIni.Read("poz", "poz"));

            dataGridView1.FirstDisplayedScrollingRowIndex = poz;
            dataGridView1.Rows[0].Selected   = false;
            dataGridView1.Rows[poz].Selected = true;
            MyIni.DeleteSection("poz");
        }
示例#7
0
        public void wyceny_Load(object sender, EventArgs e)
        {
            var MyIni = new INIFile("WektorSettings.ini");

            server   = MyIni.Read("server", "Okna");
            database = MyIni.Read("database", "Okna");
            uid      = MyIni.Read("login", "Okna");
            password = Decrypt(MyIni.Read("pass", "Okna"));
            var zera  = MyIni.Read("zera", "wyceny");
            var przed = MyIni.Read("przed", "wyceny");

            connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD="******";" + "Convert Zero Datetime = True;";
            MySqlConnection obj_Conn = new MySqlConnection();

            obj_Conn.ConnectionString = connectionString;

            obj_Conn.Open();
            string zalogowany = Form1.logged.Text;

            if (zalogowany == "admin")
            {
                MySqlCommand obj_Cmd = new MySqlCommand("SELECT nrw as nra,numer,lpad(nrw," + zera + ",0) as nrw,data,b.id as idk,b.nazwa as klient,kwota," +
                                                        "case " +
                                                        "when realizacja = '0' then 'Nie' " +
                                                        "when realizacja = '1' then 'Tak' " +
                                                        "END AS gotowe " +
                                                        "FROM wyceny a " +
                                                        "LEFT JOIN klienci b ON (a.klient = b.id) WHERE a.zamow = '0'", obj_Conn);

                MySqlDataReader obj_Reader = obj_Cmd.ExecuteReader();

                dt.Columns.Add("Lp");
                dt.Columns.Add("Numer");
                dt.Columns.Add("Klient");
                dt.Columns.Add("Wartość brutto");
                dt.Columns.Add("Z dnia");
                dt.Columns.Add("Zrealizowano");
                dt.Columns.Add("Data realizacji");
                dt.Columns.Add("id_klient");

                while (obj_Reader.Read())
                {
                    DataRow row   = dt.NewRow();
                    int     index = dt.Rows.Count + 1;
                    var     data  = Convert.ToDateTime(obj_Reader["data"]);
                    var     real  = obj_Reader["gotowe"];
                    row["Lp"]             = index;
                    row["Numer"]          = obj_Reader["numer"];
                    row["Klient"]         = obj_Reader["klient"];
                    row["Wartość brutto"] = string.Format("{0:c}", obj_Reader["kwota"]);
                    row["Z dnia"]         = data.ToString("dd") + "/" + data.ToString("MM") + "/" + data.ToString("yyyy");
                    row["Zrealizowano"]   = real;
                    if (real.ToString() == "Nie")
                    {
                        row["Data realizacji"] = "";
                    }
                    else
                    {
                        row["Data realizacji"] = data;
                    }
                    row[7] = obj_Reader["idk"];
                    dt.Rows.Add(row);
                }
                dataGridView1.DataSource = dt;
            }
            else
            {
                string       klient  = Form1.logged.Text;
                MySqlCommand obj_Cmd = new MySqlCommand("SELECT nrw as nra,numer,lpad(nrw," + zera + ",0) as nrw,data,b.id as idk,b.nazwa as klient,kwota,wycena_user," +
                                                        "case " +
                                                        "when realizacja = '0' then 'Nie' " +
                                                        "when realizacja = '1' then 'Tak' " +
                                                        "END AS gotowe " +
                                                        "FROM wyceny a " +
                                                        "LEFT JOIN klienci b ON (a.klient = b.id) WHERE a.zamow = '0' and user_id = (SELECT id FROM uzytkownicy WHERE username = '******')", obj_Conn);

                MySqlDataReader obj_Reader = obj_Cmd.ExecuteReader();

                dt.Columns.Add("Lp");
                dt.Columns.Add("Numer");
                dt.Columns.Add("Klient");
                dt.Columns.Add("Wartość brutto");
                dt.Columns.Add("Z dnia");
                dt.Columns.Add("Zrealizowano");
                dt.Columns.Add("Data realizacji");
                dt.Columns.Add("id_klient");
                dt.Columns.Add("wycena_user");

                while (obj_Reader.Read())
                {
                    DataRow row   = dt.NewRow();
                    int     index = dt.Rows.Count + 1;
                    var     data  = Convert.ToDateTime(obj_Reader["data"]);
                    var     real  = obj_Reader["gotowe"];
                    row["Lp"]             = index;
                    row["Numer"]          = obj_Reader["numer"];
                    row["Klient"]         = obj_Reader["klient"];
                    row["Wartość brutto"] = string.Format("{0:c}", obj_Reader["kwota"]);
                    row["Z dnia"]         = data.ToString("dd") + "/" + data.ToString("MM") + "/" + data.ToString("yyyy");
                    row["Zrealizowano"]   = real;
                    if (real.ToString() == "Nie")
                    {
                        row["Data realizacji"] = "";
                    }
                    else
                    {
                        row["Data realizacji"] = data;
                    }
                    row[7] = obj_Reader["idk"];
                    row[8] = obj_Reader["wycena_user"];
                    dt.Rows.Add(row);
                }
                dataGridView1.DataSource = dt;
            }

            dataGridView1.Columns[1].Width        = 200;
            dataGridView1.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dataGridView1.Columns[7].Visible      = false;
            dataGridView1.Columns[8].Visible      = false;
        }
示例#8
0
        private void detailBTN_Click(object sender, EventArgs e)
        {
            try
            {
                var MyIni = new INIFile("WektorSettings.ini");
                server           = MyIni.Read("server", "Okna");
                database         = MyIni.Read("database", "Okna");
                uid              = MyIni.Read("login", "Okna");
                password         = Decrypt(MyIni.Read("pass", "Okna"));
                connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD="******";";
                using (var connection = new MySqlConnection(connectionString))
                {
                    var data   = DateTime.Now;
                    var dat    = data.ToString("yyyy-MM-dd HH:mm:ss");
                    var wart   = dataGridView1.SelectedCells[3].Value.ToString().Replace(",", ".");
                    var klient = dataGridView1.SelectedCells[7].Value.ToString();
                    var id     = dataGridView1.SelectedCells[0].Value.ToString();
                    var query1 = "INSERT INTO zamowienia SET klient_id = '" + klient + "',wartosc = '" + wart + "',data = '" + dat + "',status='1',pay='1';";
                    var query2 = "SELECT a.id_product,b.reference,a.ilosc,a.cena,a.rabat FROM wyceny_detail a" +
                                 " LEFT JOIN cenniki b ON(a.id_product = b.id)" +
                                 " WHERE a.id ='" + id + "';";

                    connection.Open();

                    using (var command1 = new MySqlCommand(query1, connection))
                    {
                        command1.ExecuteNonQuery();
                        using (var com2 = new MySqlCommand(query2, connection))
                        {
                            DataTable tb = new DataTable();
                            tb.Columns.Add("id");
                            tb.Columns.Add("indeks");
                            tb.Columns.Add("ilosc");
                            tb.Columns.Add("cena");
                            tb.Columns.Add("rabat");

                            using (MySqlDataReader rdr = com2.ExecuteReader())
                            {
                                while (rdr.Read())
                                {
                                    DataRow row = tb.NewRow();
                                    row[0] = rdr[0];
                                    row[1] = rdr[1];
                                    row[2] = rdr[2];
                                    row[3] = rdr[3].ToString().Replace(",", ".");
                                    row[4] = rdr[4].ToString().Replace(",", ".");
                                    tb.Rows.Add(row);
                                }
                            }
                            foreach (DataRow r in tb.Rows)
                            {
                                com2.CommandText = "INSERT INTO zam SET order_id = (SELECT max(zamowienie_id) FROM zamowienia),id = '" + r[0] + "',product_id='" + r[1] + "'," +
                                                   "quantity='" + r[2] + "',cena='" + r[3] + "',rabat='" + r[4] + "';";
                                com2.ExecuteNonQuery();
                            }
                            MessageBox.Show("Zamówienie utworzono pomyślnie!");
                        }
                    }

                    connection.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#9
0
        private void zamowienia_Load(object sender, EventArgs e)
        {
            var MyIni = new INIFile("WektorSettings.ini");

            server           = MyIni.Read("server", "Okna");
            database         = MyIni.Read("database", "Okna");
            uid              = MyIni.Read("login", "Okna");
            password         = Decrypt(MyIni.Read("pass", "Okna"));
            connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD="******";" + "Convert Zero Datetime = True;";
            MySqlConnection obj_Conn = new MySqlConnection();

            obj_Conn.ConnectionString = connectionString;

            obj_Conn.Open();
            MySqlCommand obj_Cmd = new MySqlCommand("SELECT zamowienie_id as nrw,c.id as id_k,c.nazwa as klient,wartosc," +
                                                    "a.data as data,b.name as stat,a.pay as pay,a.uwagi as uwagi,a.data_r as data_r,d.numer as fvnr,a.przyjol as przyjol " +
                                                    "FROM zamowienia a " +
                                                    "LEFT JOIN status b ON(a.status = b.id)" +
                                                    "LEFT JOIN klienci c ON(a.klient_id = c.id) " +
                                                    "LEFT JOIN fakt d ON(a.zamowienie_id = d.zam)" +
                                                    "GROUP BY nrw ORDER BY nrw ASC", obj_Conn);

            MySqlDataReader obj_Reader = obj_Cmd.ExecuteReader();
            DataTable       dt         = new DataTable();

            dt.Columns.Add("Lp");
            dt.Columns.Add("Numer");
            dt.Columns.Add("Klient");
            dt.Columns.Add("Wartość netto");
            dt.Columns.Add("Z dnia");
            dt.Columns.Add("Ostatnia zmiana");
            dt.Columns.Add("Status");
            dt.Columns.Add("Uwagi");
            dt.Columns.Add("Przyjmujący");
            dt.Columns.Add("id");
            dt.Columns.Add("idk");
            dt.Columns.Add("idz");
            dt.Columns.Add("Faktura");

            while (obj_Reader.Read())
            {
                DataRow row  = dt.NewRow();
                var     data = Convert.ToDateTime(obj_Reader["data"]);
                var     rea  = Convert.ToDateTime(obj_Reader["data_r"]);
                var     user = Environment.UserName;
                row["Lp"]              = dt.Rows.Count + 1;
                row["Numer"]           = "zam/" + obj_Reader["nrw"] + "/" + data.ToString("MM") + "/" + data.ToString("yyyy");
                row["Klient"]          = obj_Reader["klient"];
                row["Wartość netto"]   = string.Format("{0:c}", obj_Reader["wartosc"]);
                row["Z dnia"]          = data.ToString("dd/MM/yyyy");
                row["Status"]          = obj_Reader["stat"];
                row["Uwagi"]           = obj_Reader["uwagi"];
                row["Ostatnia zmiana"] = rea.ToString("dd") + "/" + rea.ToString("MM") + "/" + rea.ToString("yyyy");
                row["Przyjmujący"]     = obj_Reader["przyjol"];
                row["id"]              = obj_Reader["nrw"];
                row["idk"]             = obj_Reader["id_k"];
                row["idz"]             = obj_Reader["nrw"];
                row["Faktura"]         = obj_Reader["fvnr"];
                dt.Rows.Add(row);
            }
            obj_Conn.Close();
            dataGridView1.DataSource              = dt;
            dataGridView1.Columns[0].Width        = 50;
            dataGridView1.Columns[1].Width        = 150;
            dataGridView1.Columns[2].Width        = 200;
            dataGridView1.Columns[4].Width        = 80;
            dataGridView1.Columns[5].Width        = 80;
            dataGridView1.Columns[6].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
            dataGridView1.Columns[7].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dataGridView1.Columns[8].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
            dataGridView1.Columns[9].Visible      = false;
            dataGridView1.Columns[10].Visible     = false;
            dataGridView1.Columns[11].Visible     = false;
        }
示例#10
0
        private void wystawFV_Click(object sender, EventArgs e)
        {
            if (dataGridView1.CurrentRow.Cells[6].Value.ToString() != "Zrealizowane")
            {
                MessageBox.Show("Nie można wystawić faktury jeśli zamówienie nie jest zrealizowane", "Info", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                bool t = SprawdzamFakture();
                if (t)
                {
                    var zamNR = dataGridView1.SelectedCells[11].Value.ToString();
                    var MyIni = new INIFile("WektorSettings.ini");
                    server   = MyIni.Read("server", "Okna");
                    database = MyIni.Read("database", "Okna");
                    uid      = MyIni.Read("login", "Okna");
                    password = Decrypt(MyIni.Read("pass", "Okna"));
                    var przed   = MyIni.Read("przed", "faktury");
                    var zera    = MyIni.Read("zera", "faktury");
                    var data    = DateTime.Now;
                    var dM      = string.Format("{0:MM}", data);
                    var dY      = string.Format("{0:yyyy}", data);
                    var miesiac = data.ToString("MM");
                    var rok     = data.ToString("yyyy");
                    var wyst    = data.ToString("yyyy-MM-dd HH:mm:ss");
                    var numer_z = dataGridView1.SelectedCells[1].Value.ToString();
                    connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD="******";Allow User Variables=True";
                    try
                    {
                        var klient = dataGridView1.SelectedCells[10].Value.ToString();
                        var id     = dataGridView1.SelectedCells[11].Value.ToString();
                        var query1 = "SET @idzam = " + zamNR + ";" +
                                     "INSERT INTO fakt SET nr = '', zam = (@idzam)";
                        var query2 = "SET @ids = (SELECT MAX(id) FROM fakt);" +
                                     "SET @name = (SELECT MAX(LPAD(id," + zera + ",0)) FROM fakt);" +
                                     "SET @miesiac = " + miesiac + ";" +
                                     "SET @rok = " + rok + ";" +
                                     "SET @data = '" + wyst + "';" +
                                     "SET @zam = '" + numer_z + "';" +
                                     " UPDATE fakt SET nr = (@ids),klient='" + klient + "',numer=CONCAT('" + przed + "/',@name,'/','" + dM + "/','" + dY + "'),pay='1',data=(@data),zam_nr=(@zam) WHERE id = @ids;";
                        var query3 = "SELECT id,quantity,cena FROM zam WHERE order_id = '" + id + "';";
                        using (var connection = new MySqlConnection(connectionString))
                        {
                            connection.Open();

                            using (var cmd = new MySqlCommand(query1, connection))
                            {
                                cmd.ExecuteNonQuery();
                            }
                            using (var cmd2 = new MySqlCommand(query2, connection))
                            {
                                cmd2.ExecuteNonQuery();
                            }
                            using (var cmd3 = new MySqlCommand(query3, connection))
                            {
                                DataTable tb = new DataTable();
                                tb.Columns.Add("1");
                                tb.Columns.Add("2");
                                tb.Columns.Add("3");
                                using (MySqlDataReader rdr = cmd3.ExecuteReader())
                                {
                                    while (rdr.Read())
                                    {
                                        DataRow row = tb.NewRow();
                                        row[0] = rdr[0];
                                        row[1] = rdr[1];
                                        row[2] = rdr[2];
                                        tb.Rows.Add(row);
                                    }
                                }
                                foreach (DataRow r in tb.Rows)
                                {
                                    cmd3.CommandText = "INSERT INTO fakt_det SET id_fakt=(SELECT MAX(nr) FROM fakt),id_product=" + r[0] + ",jm='1',ilosc='" + r[1] + "',netto='" + r[2].ToString().Replace(",", ".") + "',vat='1'";
                                    cmd3.ExecuteNonQuery();
                                }
                                var result = MessageBox.Show("Faktura została utworzona pomyślnie", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                if (result == DialogResult.OK)
                                {
                                    PerformRefresh(e, e);
                                }
                            }
                            connection.Close();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                else
                {
                    MessageBox.Show("Faktura do tego zamówienia została już wystawiona!", "Informacja", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
示例#11
0
        public void wycena_Load(object sender, EventArgs e)
        {
            //pobiera numer wyceny
            var MyIni = new INIFile("WektorSettings.ini");

            server   = MyIni.Read("server", "Okna");
            database = MyIni.Read("database", "Okna");
            uid      = MyIni.Read("login", "Okna");
            password = Decrypt(MyIni.Read("pass", "Okna"));

            var connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD="******";";

            using (var connection = new MySqlConnection(connectionString))
            {
                connection.Open();
                string klient = Form1.logged.Text;
                var    query  = $"{$"SELECT lpad(max(wycena+1),"}{MyIni.Read("zera","wyceny")},0) as numer,wycena,id FROM uzytkownicy WHERE id = (SELECT id FROM uzytkownicy WHERE username = '******')";
                using (var command = new MySqlCommand(query, connection))
                {
                    using (var reader = command.ExecuteReader())
                    {
                        //wycena numer
                        while (reader.Read())
                        {
                            if (MyIni.Read("przed", "wyceny") == "")
                            {
                                numer_wyceny    = "wyc/" + reader.GetString("numer") + "/" + DateTime.Now.ToString("MM") + "/" + DateTime.Today.Year;
                                wycena_nr.Text  = numer_wyceny;
                                numberBAZA.Text = reader.GetString("wycena");
                                userID.Text     = reader.GetString("id");
                            }
                            else
                            {
                                numer_wyceny    = "" + MyIni.Read("przed", "wyceny") + "/" + reader.GetString("numer") + "/" + DateTime.Now.ToString("MM") + "/" + DateTime.Today.Year;
                                wycena_nr.Text  = numer_wyceny;
                                numberBAZA.Text = reader.GetString("wycena");
                                userID.Text     = reader.GetString("id");
                            }
                            numerek.Text = reader.GetString("numer");
                        }
                    }
                }
            }


            metroGrid1.Columns[1].Width = 325;
            metroGrid1.Columns[2].DefaultCellStyle.Format = "c";
            decimal kwota  = Convert.ToDecimal(suma());
            int     zlote  = (int)kwota;
            int     grosze = (int)(100 * kwota) % 100;

            slownie.Text = String.Format("{0} {1} {2} {3}",
                                         Formatowanie.LiczbaSlownie(zlote),
                                         Formatowanie.WalutaSlownie(zlote, "złote"),
                                         Formatowanie.LiczbaSlownie(grosze),
                                         Formatowanie.WalutaSlownie(grosze, "grosze"));

            if (klientTXT.Text == "")
            {
                userBTN.Text = "Wybierz klienta";
            }
            else
            {
                userBTN.Text = "Zmień klienta";
            }

            //this.reportViewer1.RefreshReport();
        }
示例#12
0
        private void saveBTN_Click(object sender, EventArgs e)
        {
            //sprawdzamy czy klient został wybrany
            if (klientTXT.Text == "")
            {
                var result = MessageBox.Show("Przed zapisem musisz wybrać klient!");
                if (result == DialogResult.OK)
                {
                    formsy.klients form = new formsy.klients(this);
                    form.Show();
                }
            }
            else
            {
                //zapis do bazy danych
                var MyIni = new INIFile("WektorSettings.ini");
                server   = MyIni.Read("server", "Okna");
                database = MyIni.Read("database", "Okna");
                uid      = MyIni.Read("login", "Okna");
                password = Decrypt(MyIni.Read("pass", "Okna"));

                string          MyConnectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD="******";";
                MySqlConnection connection         = new MySqlConnection(MyConnectionString);

                foreach (DataGridViewRow row in metroGrid1.Rows)
                {
                    try
                    {
                        int          id_user = Convert.ToInt32(userID.Text);
                        string       klient  = Form1.logged.Text;
                        int          nr      = Convert.ToInt32(numberBAZA.Text);
                        int          numer   = nr + 1;
                        string       str     = numer.ToString();
                        MySqlCommand cmd     = new MySqlCommand();
                        cmd = connection.CreateCommand();
                        if (row.IsNewRow)
                        {
                            continue;
                        }
                        cmd.Parameters.AddWithValue("@id", numerek.Text);
                        cmd.Parameters.AddWithValue("@indeks", row.Cells[0].Value);
                        cmd.Parameters.AddWithValue("@rabat", row.Cells[3].Value.ToString().Replace("%", "").Replace(",", "."));
                        cmd.Parameters.AddWithValue("@ilosc", row.Cells[5].Value);
                        cmd.Parameters.AddWithValue("@cena", row.Cells[4].Value.ToString().Replace("zł", "").Replace(",", "."));
                        cmd.Parameters.AddWithValue("@data", DateTime.Now);
                        cmd.Parameters.AddWithValue("@kwota", sumaTXT.Text.Replace("zł", "").Replace(",", "."));
                        cmd.CommandText = $"INSERT IGNORE INTO wyceny (nrw,user_id,wycena_user,numer,klient,kwota,data) VALUES (@id,'{id_user}','{nr}','{wycena_nr.Text}',(SELECT id FROM klienci WHERE nazwa = '{klientTXT.Text}'),@kwota,@data); " +
                                          $"INSERT INTO wyceny_detail (id,user_id,wycena_user,id_product,id_klient,rabat,ilosc,cena) VALUES (@id,'{id_user}','{nr}',(SELECT id FROM cenniki WHERE reference = @indeks),(SELECT id FROM klienci WHERE nazwa ='{klientTXT.Text}'),@rabat,@ilosc,@cena);" +
                                          $"UPDATE uzytkownicy SET wycena = '{str}' WHERE username = '******';";
                        connection.Open();
                        cmd.ExecuteNonQuery();
                        connection.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                var result = MessageBox.Show("Wycena została zapisana pod numerem " + wycena_nr.Text);
                if (result == DialogResult.OK)
                {
                    Close();
                }
            }
        }