Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (RBSelect.Checked)
            {
                DataForBD.idCustomer = Convert.ToInt32(dt.Rows[CBCustomer.SelectedIndex][0]);
            }
            else if (RBNew.Checked)
            {
                // поиск макс (присвоение id)
                DataForBD.idCustomer = 1;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (Convert.ToInt32(dt.Rows[i][0]) > DataForBD.idCustomer)
                    {
                        DataForBD.idCustomer = Convert.ToInt32(dt.Rows[i][0]);
                    }
                }
                DataForBD.idCustomer++;

                DataForBD.famil     = TBFamil.Text;
                DataForBD.name      = TBName.Text;
                DataForBD.otchestvo = TBOtch.Text;
                DataForBD.numTel    = TBTel.Text;
                DataForBD.mail      = TBmail.Text;
            }

            //dt.Rows[0][0];
            //dataGridView1.DataSource = dt;

            // вставка заказчика
            if (RBNew.Checked)
            {
                mbd.controlquery("insert into 'customer' (id_customer, Famil ,Name , otchestvo , num_tel, mail )" +
                                 "values (" + DataForBD.idCustomer.ToString() + ", '" + DataForBD.famil + "' ,'" + DataForBD.name +
                                 "','" + DataForBD.otchestvo + "', " + DataForBD.numTel + " , '" + DataForBD.mail + "' )");
            }

            // вставка в заказ стр мат

            /*foreach (var n in DataForBD.listZakazStroyMat)
             * {
             *  mbd.controlquery("insert into StroyMaterialZakaz values ( " + Convert.ToString(n) + ");");
             * }
             */

            mbd.controlquery("insert into StroyMaterialZakaz values ( " + DataForBD.idZakaz + "" + DataForBD.idOboi + ");");
            mbd.controlquery("insert into StroyMaterialZakaz values ( " + DataForBD.idZakaz + "" + DataForBD.idPlitka + ");");

            // вставка в фурнит

            foreach (var n in DataForBD.listZakazMebTeh)
            {
                mbd.controlquery("insert into FurnituraZakaz  values ( " + Convert.ToString(n) + ");");
            }

            //вставка в заказ

            //присвоение id заказа


            mbd.controlquery("insert into Zakaz  values (" + DataForBD.idZakaz.ToString() + ", " + DataForBD.length.ToString()
                             + " ," + DataForBD.width.ToString() + " ," + DataForBD.height.ToString() + " ," + DataForBD.idCustomer.ToString()
                             + " ," + DataForBD.mounth.ToString() + " ," + DataForBD.summa.ToString() + ")");

            Reports rep = new Reports();

            rep.blank(DataForBD.idZakaz);
            mbd.controlquery("update zakaz set summa = " + Convert.ToString(DataForBD.summa) + " where id_zakaz = " + Convert.ToString(DataForBD.idZakaz));

            MessageBox.Show("OK");
        }