Exemplo n.º 1
0
        void AddRecord()
        {
            // will adda record with an SQL INSERT. Need to check to make sure the CustomerID does not already exist in the table, as it is a unique Primary Key
            SQLConnectionToBERP sqlConnectionToBERP  = new SQLConnectionToBERP();
            SqlDataAdapter      sqlDataAdaptorToBERP = new SqlDataAdapter("select CustomerID from Customer where CustomerID = '" + textBoxCustomerID.Text + "' ", sqlConnectionToBERP.ActiveCon());
            DataTable           dataTable            = new DataTable();

            sqlDataAdaptorToBERP.Fill(dataTable);
            if (dataTable.Rows.Count == 1)
            {
                // the CustomerID already exists. Show message box and DO NOT insert into table
                MessageBox.Show("CustomerID " + textBoxCustomerID.Text + " already exists", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            else
            {
                // the CustomerID does not already exist. OK to insert into table
                SqlCommand sqlCommandToBERP = new SqlCommand(@"
                INSERT INTO Customer
                    ([CustomerID]
                    ,[CustomerName]
                    ,[BillToID]
                    ,[CreditTermsID]
                    ,[CSRID]
                    ,[SalespersonID]
                    ,[Address1]
                    ,[Address2]
                    ,[Address3]
                    ,[City]
                    ,[State]
                    ,[Zip]
                    ,[PhoneNumber]
                    ,[Active]
                    ,[SalesCategoryIDDefault]
                    ,[PhoneNumber]
                    ,[Active]
                    ,[SalesCategoryIDDefault])
                VALUES
                    ('" + textBoxCustomerID.Text.ToString() + "','"
                                                             + textBoxCustomerName.Text.ToString() + "','"
                                                             + textBoxBillToID.Text.ToString() + "','"
                                                             + textBoxCreditTermsID.Text.ToString() + "','"
                                                             + textBoxCSRID.Text.ToString() + "','"
                                                             + textBoxSalespersonID.Text.ToString() + "','"
                                                             + textBoxAddress1.Text.ToString() + "','"
                                                             + textBoxAddress2.Text.ToString() + "','"
                                                             + textBoxAddress3.Text.ToString() + "','"
                                                             + textBoxCity.Text.ToString() + "','"
                                                             + textBoxState.Text.ToString() + "','"
                                                             + textBoxZip.Text.ToString() + "','"
                                                             + textBoxCreditLimit.Text + "','"
                                                             + textBoxPhoneNumber.Text.ToString() + "','"
                                                             + textBoxActive.Text.ToString() + "','"
                                                             + textBoxSalesCategoryID.Text.ToString() +
                                                             "')"
                                                             , sqlConnectionToBERP.ActiveCon());
                sqlCommandToBERP.ExecuteNonQuery();
                clearFields();
            }
        }
Exemplo n.º 2
0
        private void btn_Login_Click(object sender, EventArgs e)
        {
            SQLConnectionToBERP sqlConnectionToBERP  = new SQLConnectionToBERP();
            SqlDataAdapter      sqlDataAdaptorToBERP = new SqlDataAdapter("select * from Users where UserID = '" + textBox_Username.Text + "' and Password = '******' ", sqlConnectionToBERP.ActiveCon());
            DataTable           dataTable            = new DataTable();

            sqlDataAdaptorToBERP.Fill(dataTable);

            if (dataTable.Rows.Count == 1)
            {
                formBERP berp = new formBERP();
                this.Hide();
                berp.Show();
            }
            else
            {
                MessageBox.Show("Invalid Username/Password", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }