예제 #1
0
파일: Seller.cs 프로젝트: dmitriy-0297/BD
        private void Insert_Click(object sender, EventArgs e)
        {
            //----------------------------------------------------------------------------
            dSet8 = new DataSet();
            string strSQL = "SELECT Name FROM Goods";

            dAdapter = new OleDbDataAdapter(strSQL, strConn);
            dAdapter.Fill(dSet8, "Goods");
            dTable = dSet.Tables["Goods"];
            bool flag = false;

            for (int i = 0; i <= dTable.Rows.Count - 1; i++)
            {
                if (NameGood.Text.ToString() == dTable.Rows[i][2].ToString().Trim())
                {
                    OleDbCommand insertSupplierCmd = new OleDbCommand("InsertPurchase", cn1);
                    insertSupplierCmd.CommandType = CommandType.StoredProcedure;
                    insertSupplierCmd.Parameters.Add("@Date", OleDbType.Date).Value             = PurchaseDate.Text.Trim();
                    insertSupplierCmd.Parameters.Add("@NameGoods", OleDbType.VarChar, 25).Value = NameGood.Text.Trim();
                    insertSupplierCmd.Parameters.Add("@Quantity", OleDbType.Integer).Value      = QuantityGoods.Text.Trim();
                    insertSupplierCmd.Parameters.Add("@Price", OleDbType.Double).Value          = PriceGoods.Text.Trim();
                    insertSupplierCmd.Parameters.Add("@FIO", OleDbType.VarChar, 30).Value       = FIO.Text.Trim();
                    insertSupplierCmd.Parameters.Add("@Phone", OleDbType.VarChar, 12).Value     = Phone.Text.Trim();
                    insertSupplierCmd.Parameters.Add("@PhoneCust", OleDbType.VarChar, 12).Value = PhoneCust.Text.Trim();
                    try
                    {
                        insertSupplierCmd.ExecuteNonQuery();
                        MessageBox.Show("Record successfully inserted!");
                        PhoneCust.Text     = " ";
                        PurchaseDate.Text  = " ";
                        NameGood.Text      = " ";
                        QuantityGoods.Text = " ";
                        PriceGoods.Text    = " ";
                        FIO.Text           = " ";
                        Phone.Text         = " ";
                    }
                    catch (OleDbException exc)
                    {
                        MessageBox.Show(exc.ToString());
                    }
                    flag = true;
                    break;
                }
                else if (i == dTable.Rows.Count - 1)
                {
                    if (flag == false)
                    {
                        FormErrorGoods secondform = new FormErrorGoods();
                        secondform.Show();
                        break;
                    }
                }
            }

            //------------------------------------------------------------------------------
        }
예제 #2
0
파일: Seller.cs 프로젝트: dmitriy-0297/BD
        private void button1_Click(object sender, EventArgs e)
        {
            dSet2 = new DataSet();
            string strSQL = "SELECT Name FROM Goods";

            dAdapter = new OleDbDataAdapter(strSQL, strConn);
            dAdapter.Fill(dSet2, "Goods");
            dTable = dSet.Tables["Goods"];
            bool flag = false;

            for (int i = 0; i <= dTable.Rows.Count - 1; i++)
            {
                if (NameGoods.Text.ToString() == dTable.Rows[i][2].ToString().Trim())
                {
                    FormErrorGoods secondform = new FormErrorGoods();
                    secondform.Show();
                    flag = true;
                    break;
                }
                else if (i == dTable.Rows.Count - 1)
                {
                    if (flag == false)
                    {
                        OleDbCommand insertProcurementCmd = new OleDbCommand("insertProcurement", cn1);
                        insertProcurementCmd.CommandType = CommandType.StoredProcedure;
                        insertProcurementCmd.Parameters.Add("@Data", OleDbType.Date).Value = Data.Text.Trim();
                        insertProcurementCmd.Parameters.Add("@SellerPhone", OleDbType.VarChar, 12).Value = SellerPhone.Text.Trim();
                        insertProcurementCmd.Parameters.Add("@NameGoods", OleDbType.VarChar, 15).Value   = NameGoods.Text.Trim();
                        insertProcurementCmd.Parameters.Add("@Quantity", OleDbType.Integer).Value        = Quantity.Text.Trim();
                        try
                        {
                            insertProcurementCmd.ExecuteNonQuery();
                            MessageBox.Show("Record successfully inserted!");
                            Data.Text        = " ";
                            SellerPhone.Text = " ";
                            NameGoods.Text   = " ";
                            Quantity.Text    = " ";
                        }
                        catch (OleDbException exc)
                        {
                            MessageBox.Show(exc.ToString());
                        }
                        break;
                    }
                }
            }
        }