예제 #1
0
        private void buttonOkPinCode_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtUserName.Text != string.Empty && textBoxPinPinCode.Text != string.Empty)
                {
                    GateWay   gateWayObject   = new GateWay();
                    DataTable dataTableObject = new DataTable();
                    Customer  customerObject  = new Customer();
                    dataTableObject = gateWayObject.SelectData("Select * from customer where customer.pin_code='" + textBoxPinPinCode.Text + "' and customer.user_name='" + txtUserName.Text + "'");
                    if (dataTableObject.Rows.Count == 1)
                    {
                        DataRow dr = dataTableObject.Rows[0];
                        customerObject.name     = dr["c_name"].ToString();
                        customerObject.userName = dr["user_name"].ToString();
                        customerObject.address  = dr["address"].ToString();
                        customerObject.phone    = dr["phone"].ToString();
                        customerObject.pinCode  = dr["pin_code"].ToString();
                        customerObject.acc_no   = dr["account_no"].ToString();
                        customerObject.balance  = Convert.ToDecimal(dr["balance"]);

                        txtUserName.Clear();
                        textBoxPinPinCode.Clear();
                        FormMainMenu window = new FormMainMenu(customerObject);
                        window.ShowDialog();
                    }
                    else
                    {
                        MessageBox.Show("Invalid UserName or PinCode", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("UserName or PinCode should not be empty.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            txtUserName.Clear();
            textBoxPinPinCode.Clear();
        }
예제 #2
0
        private void FormAddNewUsers_Load(object sender, EventArgs e)
        {
            try
            {
                GateWay gateWayObject = new GateWay();
                bindingSource.DataSource = gateWayObject.SelectData("Select * from customer;");
                dataGridView1.DataSource = bindingSource;

                dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;
                dataGridView1.EditMode         = DataGridViewEditMode.EditProgrammatically;
            }
            catch (SqlException)
            {
                MessageBox.Show("Error in DataBase connection.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #3
0
        private void buttonAddAddNewUsers_Click(object sender, EventArgs e)
        {
            try
            {
                var emptyBoxes = from Control currentControl in Controls
                                 where currentControl is TextBox && string.IsNullOrEmpty(currentControl.Text)
                                 orderby currentControl.TabIndex
                                 select currentControl;
                if (emptyBoxes.Count() > 0)
                {
                    MessageBox.Show("Please fill in all fields.", "Missing", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    List <SqlParameter> parameter       = new List <SqlParameter>();
                    GateWay             gateWayObject   = new GateWay();
                    DataTable           dataTableObject = new DataTable();
                    Customer            customerObject  = new Customer();

                    customerObject.name     = textBoxAddName.Text;
                    customerObject.userName = txtUserName.Text;
                    customerObject.address  = textBoxAddAddress.Text;
                    customerObject.phone    = textBoxAddPhone.Text;
                    customerObject.pinCode  = textBoxAddPin.Text;
                    customerObject.acc_no   = textBoxAccountNo.Text;
                    customerObject.balance  = Convert.ToDecimal(textBoxAddBalance.Text);

                    dataTableObject = gateWayObject.SelectData("Select * from customer");
                    bool found = false;
                    for (int i = 0; i < dataTableObject.Rows.Count; i++)                               //check if the account no already exists
                    {
                        if (dataTableObject.Rows[i]["account_no"].ToString() == customerObject.acc_no) //check if the account no already exists
                        {
                            found = true;
                            break;
                        }
                    }

                    if (found)
                    {
                        MessageBox.Show("Account with this account number already exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        string insertString = @"INSERT INTO [customer] (c_name, user_name, address, phone, pin_code, account_no, balance) VALUES (@c_name, @user_name, @address, @phone, @pin_code, @account_no, @balance)";

                        parameter.Add(new SqlParameter("@c_name", customerObject.name));
                        parameter.Add(new SqlParameter("@user_name", customerObject.userName));
                        parameter.Add(new SqlParameter("@address", customerObject.address));
                        parameter.Add(new SqlParameter("@phone", customerObject.phone));
                        parameter.Add(new SqlParameter("@pin_code", customerObject.pinCode));
                        parameter.Add(new SqlParameter("@account_no", customerObject.acc_no));
                        parameter.Add(new SqlParameter("@balance", customerObject.balance));

                        gateWayObject.InsertData(insertString, parameter); // insert into customer table
                        FormAddNewUsers_Load(this, new EventArgs());       //update data grid view
                        //dataGridView1.Refresh();
                        btnClear_Click(this, new EventArgs());             // clear all text box
                    }
                }
            }
            catch (FormatException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }