示例#1
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();
        }
示例#2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtNewUserName.Text != string.Empty && txtNewPinCode.Text != string.Empty && txtConfirmNewPinCode.Text != string.Empty)
            {
                try
                {
                    GateWay   gateWayObject   = new GateWay();
                    DataTable dataTableObject = new DataTable();

                    customerObject.userName = txtNewUserName.Text;
                    customerObject.pinCode  = txtNewPinCode.Text;
                    if (txtNewPinCode.Text != txtConfirmNewPinCode.Text)
                    {
                        throw new Exception("Confirm PinCode does not match.");
                    }

                    dataTableObject = gateWayObject.SelectData("select * from customer");
                    bool found = false;
                    for (int i = 0; i < dataTableObject.Rows.Count; i++)  // check if the user name already exist
                    {
                        if (dataTableObject.Rows[i]["user_name"].ToString() == customerObject.userName)
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        MessageBox.Show("This user name already exist.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        string updateString = "update customer set user_name='" + customerObject.userName + "',pin_code='" + customerObject.pinCode + "' where account_no='" + customerObject.acc_no + "'";
                        if (gateWayObject.updateData(updateString))
                        {
                            MessageBox.Show("UserName and PinCode is updated.");
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Field should not be empty.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            btnClear_Click(this, new EventArgs());
        }
示例#3
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();
        }
示例#4
0
        private void FormMainMenu_Load(object sender, EventArgs e)
        {
            VisibleFalse();
            balanceGroupBox.Location         = new Point(150, 169);
            transferGroupBox.Location        = new Point(150, 169);
            depositCashGroupBox.Location     = new Point(150, 169);
            withdrawCashGroupBox.Location    = new Point(150, 169);
            transferHistoryGroupBox.Location = new Point(150, 169);

            lblName.Text = customerObject.name;
            string sqlSrring = "select customer.c_name, transfer_history.ammount from customer, transfer_history where acc_to='" + customerObject.acc_no + "' and notification = 1 and acc_from=account_no";

            dataTableObject = gateWayObject.SelectData(sqlSrring);
            if (dataTableObject.Rows.Count > 0)
            {
                lblNotification.Text    = dataTableObject.Rows.Count.ToString() + " Notification(s).";
                lblNotification.Visible = true;
            }
        }
示例#5
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);
            }
        }
示例#6
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);
            }
        }
示例#7
0
        private void History_Load(object sender, EventArgs e)
        {
            myDataGridView.Columns.Clear();
            switch (select)
            {
            case "deposit":
            {
                myDataGridView.Size = new Size(345, 380);

                DataGridViewTextBoxColumn dateColl = new DataGridViewTextBoxColumn();
                dateColl.Width            = 150;
                dateColl.HeaderText       = "Deposit Date";
                dateColl.DataPropertyName = "date";           // coll name from the database table
                DataGridViewCell dateCell = new DataGridViewTextBoxCell();
                dateColl.CellTemplate = dateCell;
                myDataGridView.Columns.Add(dateColl);

                DataGridViewTextBoxColumn amountColl = new DataGridViewTextBoxColumn();
                amountColl.Width            = 150;
                amountColl.HeaderText       = "Amount";
                amountColl.DataPropertyName = "ammount";
                DataGridViewCell amountCell = new DataGridViewTextBoxCell();
                amountColl.CellTemplate = amountCell;
                myDataGridView.Columns.Add(amountColl);

                this.Controls.Add(myDataGridView);
                this.Width = myDataGridView.Width + 30;
                this.Text  = "Deposit History";

                bindingSource.DataSource  = gateWayObject.SelectData("select date, ammount from diposit_history where account_no='" + customerObject.acc_no + "' order by date asc");
                myDataGridView.DataSource = bindingSource;
            }
            break;

            case "withdraw":
            {
                myDataGridView.Size = new Size(345, 380);

                DataGridViewTextBoxColumn dateColl = new DataGridViewTextBoxColumn();
                dateColl.Width            = 150;
                dateColl.HeaderText       = "Withdraw Date";
                dateColl.DataPropertyName = "date";           // coll name from the database table
                DataGridViewCell dateCell = new DataGridViewTextBoxCell();
                dateColl.CellTemplate = dateCell;
                myDataGridView.Columns.Add(dateColl);

                DataGridViewTextBoxColumn amountColl = new DataGridViewTextBoxColumn();
                amountColl.Width            = 150;
                amountColl.HeaderText       = "Amount";
                amountColl.DataPropertyName = "ammount";
                DataGridViewCell amountCell = new DataGridViewTextBoxCell();
                amountColl.CellTemplate = amountCell;
                myDataGridView.Columns.Add(amountColl);

                this.Controls.Add(myDataGridView);
                this.Width = myDataGridView.Width + 30;
                this.Text  = "Withdraw History";

                bindingSource.DataSource  = gateWayObject.SelectData("select date, ammount from withdraw_history where account_no='" + customerObject.acc_no + "' order by date asc");
                myDataGridView.DataSource = bindingSource;
            }
            break;

            case "transfer":
            {
                myDataGridView.Size = new Size(750, 380);

                DataGridViewTextBoxColumn accFromColl = new DataGridViewTextBoxColumn();
                accFromColl.Width            = 100;
                accFromColl.HeaderText       = "Acc From";
                accFromColl.DataPropertyName = "acc_from";           // coll name from the database table
                DataGridViewCell accFromCell = new DataGridViewTextBoxCell();
                accFromColl.CellTemplate = accFromCell;
                myDataGridView.Columns.Add(accFromColl);

                DataGridViewTextBoxColumn name1Coll = new DataGridViewTextBoxColumn();
                name1Coll.Width            = 150;
                name1Coll.HeaderText       = "Name";
                name1Coll.DataPropertyName = "name1";
                DataGridViewCell name1Cell = new DataGridViewTextBoxCell();
                name1Coll.CellTemplate = name1Cell;
                myDataGridView.Columns.Add(name1Coll);

                DataGridViewTextBoxColumn accToColl = new DataGridViewTextBoxColumn();
                accToColl.Width            = 100;
                accToColl.HeaderText       = "Acc To";
                accToColl.DataPropertyName = "acc_to";
                DataGridViewCell accToCell = new DataGridViewTextBoxCell();
                accToColl.CellTemplate = accToCell;
                myDataGridView.Columns.Add(accToColl);

                DataGridViewTextBoxColumn name2Coll = new DataGridViewTextBoxColumn();
                name2Coll.Width            = 150;
                name2Coll.HeaderText       = "Name";
                name2Coll.DataPropertyName = "name2";
                DataGridViewCell name2Cell = new DataGridViewTextBoxCell();
                name2Coll.CellTemplate = name2Cell;
                myDataGridView.Columns.Add(name2Coll);

                DataGridViewTextBoxColumn amountColl = new DataGridViewTextBoxColumn();
                amountColl.Width            = 100;
                amountColl.HeaderText       = "Amount";
                amountColl.DataPropertyName = "ammount";
                DataGridViewCell amountCell = new DataGridViewTextBoxCell();
                amountColl.CellTemplate = amountCell;
                myDataGridView.Columns.Add(amountColl);

                DataGridViewTextBoxColumn dateColl = new DataGridViewTextBoxColumn();
                dateColl.Width            = 107;
                dateColl.HeaderText       = "Transfer Date";
                dateColl.DataPropertyName = "date";           // coll name from the database table
                DataGridViewCell dateCell = new DataGridViewTextBoxCell();
                dateColl.CellTemplate = dateCell;
                myDataGridView.Columns.Add(dateColl);

                this.Controls.Add(myDataGridView);
                this.Width = myDataGridView.Width + 30;
                this.Text  = "Transfer History";

                string sqlString = "select distinct date, acc_from, name1, acc_to, c_name as name2, ammount from";
                sqlString += "(select distinct date, acc_from, c_name as name1, acc_to, ammount from transfer_history, customer where (acc_from='" + customerObject.acc_no + "' or acc_to='" + customerObject.acc_no + "') and customer.account_no=transfer_history.acc_from)";
                sqlString += "a, customer where a.acc_to=customer.account_no order by date";

                bindingSource.DataSource  = gateWayObject.SelectData(sqlString);
                myDataGridView.DataSource = bindingSource;
            }
            break;

            default:
                break;
            }
        }