示例#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 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();
        }
示例#3
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());
        }
示例#4
0
        private void lblNotification_Click(object sender, EventArgs e)
        {
            VisibleFalse();
            lblDescription.Location = new Point(200, 200);
            lblDescription.Text     = "";
            for (int i = 0; i < dataTableObject.Rows.Count; i++)
            {
                lblDescription.Text += dataTableObject.Rows[i]["c_name"].ToString() + " sends you TK " + dataTableObject.Rows[i]["ammount"].ToString() + "\n";
            }
            lblDescription.Visible  = true;
            lblNotification.Visible = false;
            string sqlString = "update transfer_history set notification = 0 where acc_to='" + customerObject.acc_no + "' and notification = 1";

            if (!gateWayObject.updateData(sqlString))
            {
                MessageBox.Show("Notiication update error.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }