示例#1
0
        private void buttonDepositDepositCash_Click(object sender, EventArgs e)
        {
            try
            {
                customerObject.balance += Convert.ToDecimal(textBoxDepositCash.Text);
                GateWay gateWayObject = new GateWay();
                string  updateString  = "update customer set balance=" + customerObject.balance + " where account_no='" + customerObject.acc_no + "'";

                string insertString           = @"INSERT INTO [diposit_history] (account_no, date, ammount) VALUES (@account_no, @date, @ammount)";
                List <SqlParameter> parameter = new List <SqlParameter>();
                parameter.Add(new SqlParameter("@account_no", customerObject.acc_no));
                parameter.Add(new SqlParameter("@date", (DateTime.Now).ToString()));
                parameter.Add(new SqlParameter("@ammount", Convert.ToDecimal(textBoxDepositCash.Text)));

                if (gateWayObject.updateData(updateString) && gateWayObject.InsertData(insertString, parameter))
                {
                    MessageBox.Show("Deposit Successfull.\nNew balance" + customerObject.balance);
                }
                else
                {
                    MessageBox.Show("Error in Deposit.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (FormatException ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            textBoxDepositCash.Clear();
        }
示例#2
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);
            }
        }
示例#3
0
        private void buttonTransfer_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtGuestAcc.Text != string.Empty && txtTransferAmount.Text != string.Empty)
                {
                    GateWay   gateWayObject   = new GateWay();
                    DataTable dataTableObject = new DataTable();
                    string    sqlString       = "select account_no from customer where account_no='" + txtGuestAcc.Text + "'"; // determine whether the account is exist.

                    dataTableObject = gateWayObject.SelectData(sqlString);
                    //DataRow dr = dataTableObject.Rows[0];
                    if (dataTableObject.Rows.Count == 1 && txtGuestAcc.Text != customerObject.acc_no)
                    {
                        customerObject.balance -= Convert.ToDecimal(txtTransferAmount.Text);

                        string updateCustomerString = "update customer set balance=" + customerObject.balance + " where account_no='" + customerObject.acc_no + "'";
                        string updateGusetString    = "update customer set balance=balance+" + txtTransferAmount.Text + " where account_no='" + txtGuestAcc.Text + "'";

                        //insert into transfer_history table
                        string insertString           = @"INSERT INTO [transfer_history] (date, acc_from, acc_to, ammount, notification) VALUES (@date, @acc_from, @acc_to, @ammount, @notification)";
                        List <SqlParameter> parameter = new List <SqlParameter>();

                        parameter.Add(new SqlParameter("@date", (DateTime.Now).ToString()));
                        parameter.Add(new SqlParameter("@acc_from", customerObject.acc_no));
                        parameter.Add(new SqlParameter("@acc_to", txtGuestAcc.Text));
                        parameter.Add(new SqlParameter("@ammount", Convert.ToDecimal(txtTransferAmount.Text)));
                        parameter.Add(new SqlParameter("@notification", 1));

                        if (gateWayObject.updateData(updateCustomerString) && gateWayObject.updateData(updateGusetString) && gateWayObject.InsertData(insertString, parameter))
                        {
                            MessageBox.Show("Transfer Successfull.\nNew balance" + customerObject.balance);
                        }
                        else
                        {
                            MessageBox.Show("Error in Transfer.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Invalid account number.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("Account number or Amount should not be empty.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (FormatException ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            txtGuestAcc.Clear();
            txtTransferAmount.Clear();
        }