//////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// // Control for create deposit private void SelectCustomerDeposit() { DataTable _data = null; // Select customer by identity number. This is priority order. if (txt_identity_number_deposit.Text != "") { _data = PassbookModel.SelectCustomerByIdentityNumber(txt_identity_number_deposit.Text); } // Select customer by phone number else if (txt_phone_number_deposit.Text != "") { _data = PassbookModel.SelectCustomerByPhoneNumber(txt_phone_number_deposit.Text); } else { MessageBox.Show(IMessage.MSG_REQUIRE_ID, IMessage.CPT_NOTICE); return; } if (_data.Rows.Count == 0) { MessageBox.Show(IMessage.MSG_ACCOUNT_NOT_FOUND, IMessage.CPT_NOTICE); return; } // Extract data object[] _customer = _data.Rows[0].ItemArray; lbl_customer_id_deposit.Text = _customer[TblColumn.A_ID].ToString(); txt_name_deposit.Text = _customer[TblColumn.A_NAME].ToString(); txt_identity_number_deposit.Text = _customer[TblColumn.A_IDENTITY_NUMBER].ToString(); txt_address_deposit.Text = _customer[TblColumn.A_ADDRESS].ToString(); txt_phone_number_deposit.Text = _customer[TblColumn.A_PHONE_NUMBER].ToString(); DataTable _data1 = PassbookModel.SelectPassbooksByCustomerId(lbl_customer_id_deposit.Text); if (_data1.Rows.Count == 0) { MessageBox.Show(IMessage.MSG_NO_PASSBOOK, IMessage.CPT_NOTICE); return; } for (int i = 0; i < _data1.Rows.Count; i++) { object[] _passbook = _data1.Rows[i].ItemArray; string _cashFormatted = string.Format("{0:#,##0}", Processor.ConvertToDouble(_passbook[TblColumn.P_CASH].ToString())); cbb_passbook_deposit.Items.Add(_passbook[TblColumn.P_ID].ToString() + ": " + _passbook[TblColumn.P_NAME].ToString() + " - " + _cashFormatted + " VND"); } cbb_passbook_deposit.SelectedIndex = 0; txt_name_deposit.Enabled = false; txt_identity_number_deposit.Enabled = false; txt_address_deposit.Enabled = false; txt_phone_number_deposit.Enabled = false; btn_check_deposit.Enabled = false; btn_create_deposit.Enabled = true; }
private void InitializeAccount() { DataTable _data = PassbookModel.SelectStaffByEmail(Params.CURRENT_SESSION[Params.CURRENT_EMAIL].ToString()); if (_data.Rows.Count == 0) { MessageBox.Show(IMessage.MSG_SOMETHING_WENT_WRONG, IMessage.CPT_NOTICE); return; } object[] _account = _data.Rows[0].ItemArray; lbl_id_account.Text = _account[TblColumn.S_ID].ToString(); txt_email_account.Text = _account[TblColumn.S_EMAIL].ToString(); txt_name_account.Text = _account[TblColumn.S_NAME].ToString(); txt_identity_number_account.Text = _account[TblColumn.S_IDENTITY_NUMBER].ToString(); txt_phone_number_account.Text = _account[TblColumn.S_PHONE_NUMBER].ToString(); txt_email_account.Enabled = false; txt_name_account.Enabled = true; txt_identity_number_account.Enabled = false; txt_phone_number_account.Enabled = true; if ((m_roles & Roles.ROLE_MANAGER) == Roles.ROLE_MANAGER) { tab_cash_edit.Parent = tab_control_edit; tab_period_edit.Parent = tab_control_edit; } else { tab_cash_edit.Parent = null; tab_period_edit.Parent = null; } }
private void btn_submit_open_Click(object sender, EventArgs e) { if (txt_name_open.Text == "" || txt_identity_number_open.Text == "" || txt_address_open.Text == "" || txt_phone_number_open.Text == "") { MessageBox.Show(IMessage.MSG_REQUIRED_ALL, IMessage.CPT_NOTICE); return; } DataTable _data = PassbookModel.SelectCustomerByIdentityNumber(txt_identity_number_open.Text); if (_data.Rows.Count != 0) { MessageBox.Show(IMessage.MSG_ACCOUNT_EXISTED, IMessage.CPT_NOTICE); return; } if (PassbookModel.InsertCustomer(txt_name_open.Text, txt_identity_number_open.Text, txt_address_open.Text, txt_phone_number_open.Text) == false) { MessageBox.Show(IMessage.MSG_FAILED_CREATE_CUSTOMER, IMessage.CPT_NOTICE); return; } MessageBox.Show(IMessage.MSG_SUCCESS_CREATE_ACCOUNT, IMessage.CPT_CREATE_CUSTOMER); _data = PassbookModel.SelectCustomerByIdentityNumber(txt_identity_number_open.Text); object[] _customer = _data.Rows[0].ItemArray; lbl_customer_id_open.Text = _customer[TblColumn.A_ID].ToString(); // Initialize cbb_period_open DataTable _data2 = PassbookModel.SelectAllPeriod(); for (int i = 0; i < _data2.Rows.Count; i++) { object[] _period = _data2.Rows[i].ItemArray; cbb_period_open.Items.Add(_period[TblColumn.T_ID].ToString() + ": " + _period[TblColumn.T_NAME].ToString()); } cbb_period_open.SelectedIndex = 0; // UX Enhancer. txt_name_open.Enabled = false; txt_identity_number_open.Enabled = false; txt_address_open.Enabled = false; txt_phone_number_open.Enabled = false; btn_check_open.Enabled = false; btn_submit_open.Enabled = false; btn_create_open.Enabled = true; }
private void btn_change_password_account_Click(object sender, EventArgs e) { if (txt_current_password_account.Text == "" || txt_new_password.Text == "" || txt_new_password_confirm.Text == "") { MessageBox.Show(IMessage.MSG_REQUIRED_ALL, IMessage.CPT_NOTICE); return; } using (MD5 md5Hash = MD5.Create()) { string passwordHash = Processor.GetMd5Hash(md5Hash, txt_current_password_account.Text); if (!Processor.VerifyMd5Hash(md5Hash, txt_current_password_account.Text, passwordHash)) { MessageBox.Show(IMessage.MSG_SOMETHING_WENT_WRONG, IMessage.CPT_NOTICE); return; } if (passwordHash != Params.CURRENT_SESSION[Params.CURRENT_PASSWORD].ToString()) { MessageBox.Show(IMessage.MSG_WRONG_CURRENT_PASSWORD, IMessage.CPT_NOTICE); return; } } if (txt_new_password.Text != txt_new_password_confirm.Text) { MessageBox.Show(IMessage.MSG_PASSWORD_MISMATCHED, IMessage.CPT_NOTICE); return; } using (MD5 md5Hash = MD5.Create()) { string passwordHash = Processor.GetMd5Hash(md5Hash, txt_new_password.Text); if (!Processor.VerifyMd5Hash(md5Hash, txt_new_password.Text, passwordHash)) { MessageBox.Show(IMessage.MSG_SOMETHING_WENT_WRONG, IMessage.CPT_NOTICE); return; } if (PassbookModel.UpdatePasswordByStaffId(lbl_id_account.Text, passwordHash) == false) { MessageBox.Show(IMessage.MSG_CANNOT_UPDATE_PASSWORD, IMessage.CPT_NOTICE); return; } MessageBox.Show(IMessage.MSG_SUCCESS_UPDATE_PASSWORD, IMessage.CPT_NOTICE); } }
private void Login() { if (txt_email_login.Text == "" || txt_password_login.Text == "") { MessageBox.Show(IMessage.MSG_REQUIRED_ALL, IMessage.CPT_NOTICE); return; } using (MD5 md5Hash = MD5.Create()) { string passwordHash = Processor.GetMd5Hash(md5Hash, txt_password_login.Text); if (!Processor.VerifyMd5Hash(md5Hash, txt_password_login.Text, passwordHash)) { MessageBox.Show(IMessage.MSG_SOMETHING_WENT_WRONG, IMessage.CPT_NOTICE); return; } DataTable _data = PassbookModel.SelectStaffByEmailAndPassword(txt_email_login.Text, passwordHash); if (_data.Rows.Count == 0) { MessageBox.Show(IMessage.MSG_INCORRECT_EMAIL_PASSWORD, IMessage.CPT_NOTICE); return; } object[] _staff = _data.Rows[0].ItemArray; Params.CURRENT_SESSION.Add(_staff[TblColumn.S_ID]); Params.CURRENT_SESSION.Add(_staff[TblColumn.S_EMAIL]); Params.CURRENT_SESSION.Add(_staff[TblColumn.S_PASSWORD]); Params.CURRENT_SESSION.Add(_staff[TblColumn.S_NAME]); Params.CURRENT_SESSION.Add(_staff[TblColumn.S_ROLES]); if (check_remember_me.Checked == true) { Params.PARAMS[Params.USERNAME] = txt_email_login.Text; Params.PARAMS[Params.PASSWORD] = txt_password_login.Text; } else { Params.PARAMS[Params.USERNAME] = ""; Params.PARAMS[Params.PASSWORD] = ""; } Processor.WriteParams(Processor.PARAMS_FILE); Hide(); DialogResult = DialogResult.OK; } }
private void GetPeriod() { cbb_period_edit_period.Items.Clear(); DataTable _data = PassbookModel.SelectAllPeriod(); if (_data.Rows.Count != 0) { for (int i = 0; i < _data.Rows.Count; i++) { object[] _period = _data.Rows[i].ItemArray; cbb_period_edit_period.Items.Add(_period[TblColumn.T_NAME].ToString()); } } }
//////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// // Control for create lookup private void btn_refresh_lookup_Click(object sender, EventArgs e) { list_lookup.Items.Clear(); DataTable _data = PassbookModel.SelectAllPassbooks(); for (int i = 0; i < _data.Rows.Count; i++) { object[] _passbook = _data.Rows[i].ItemArray; ListViewItem _item = new ListViewItem((i + 1).ToString()); // Set Passbook ID _item.SubItems.Add(_passbook[TblColumn.P_ID].ToString()); // Set Period DataTable _data1 = PassbookModel.SelectPeriodById(_passbook[TblColumn.P_PERIOD_ID].ToString()); if (_data1.Rows.Count == 0) { MessageBox.Show(IMessage.MSG_SOMETHING_WENT_WRONG, IMessage.CPT_NOTICE); return; } object[] _period = _data1.Rows[0].ItemArray; _item.SubItems.Add(_period[TblColumn.T_NAME].ToString()); // Set Customer DataTable _data2 = PassbookModel.SelectCustomerById(_passbook[TblColumn.P_CUSTOMER_ID].ToString()); if (_data2.Rows.Count == 0) { MessageBox.Show(IMessage.MSG_SOMETHING_WENT_WRONG, IMessage.CPT_NOTICE); return; } object[] _customer = _data2.Rows[0].ItemArray; _item.SubItems.Add(_customer[TblColumn.A_NAME].ToString()); // Set balance string _cashFormatted = string.Format("{0:#,##0}", Processor.ConvertToDouble(_passbook[TblColumn.P_CASH].ToString())); _item.SubItems.Add(_cashFormatted + " VND"); list_lookup.Items.Add(_item); } }
//////////////////////////////////////////////////////////////////// // Control for edit cash /// <summary> /// /// </summary> private void btn_apply_edit_cast_Click(object sender, EventArgs e) { if ((m_roles & Roles.ROLE_MANAGER) != Roles.ROLE_MANAGER) { MessageBox.Show(IMessage.MSG_PERMISSION_DENY, IMessage.CPT_NOTICE); return; } if (txt_min_cash.Text != "") { double _cash = Processor.ConvertToDouble(txt_min_cash.Text); if (_cash == Processor.UNIDENTIFIED) { MessageBox.Show(IMessage.MSG_WRONG_INPUT, IMessage.CPT_NOTICE); return; } if (_cash < S_MIN_CASH) { MessageBox.Show(IMessage.MSG_TOO_FEW_CASH, IMessage.CPT_NOTICE); return; } PassbookModel.UpdateMinCash(txt_min_cash.Text); MessageBox.Show("Success update min cash to " + txt_min_cash.Text); } if (txt_min_income.Text != "") { double _income = Processor.ConvertToDouble(txt_min_income.Text); if (_income == Processor.UNIDENTIFIED) { MessageBox.Show(IMessage.MSG_WRONG_INPUT, IMessage.CPT_NOTICE); return; } if (_income < S_MIN_INCOME) { MessageBox.Show(IMessage.MSG_TOO_FEW_CASH, IMessage.CPT_NOTICE); return; } PassbookModel.UpdateMinIncome(txt_min_income.Text); MessageBox.Show("Success update min income to " + txt_min_income.Text); } }
//////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// // Control for create monthly report private void LoadPeriodMonthly() { DataTable _data = PassbookModel.SelectAllPeriod(); cbb_period_monthly.Items.Clear(); for (int i = 0; i < _data.Rows.Count; i++) { object[] _period1 = _data.Rows[i].ItemArray; cbb_period_monthly.Items.Add(_period1[TblColumn.T_NAME].ToString()); } cbb_period_monthly.SelectedIndex = 0; list_monthly.Items.Clear(); }
private void cbb_period_edit_period_SelectedIndexChanged(object sender, EventArgs e) { DataTable _data = PassbookModel.SelectPeriodByName(cbb_period_edit_period.Text); if (_data.Rows.Count == 0) { MessageBox.Show(IMessage.MSG_PERIOD_NOT_EXIST, IMessage.CPT_NOTICE); return; } object[] _period = _data.Rows[0].ItemArray; lbl_id_edit_period.Text = _period[TblColumn.T_ID].ToString(); txt_name_edit_period.Text = _period[TblColumn.T_NAME].ToString(); txt_rate_edit_period.Text = _period[TblColumn.T_RATE].ToString(); txt_period_edit_period.Text = _period[TblColumn.T_PERIOD].ToString(); }
private void btn_create_open_Click(object sender, EventArgs e) { if (txt_name_open.Text == "" || txt_identity_number_open.Text == "" || txt_address_open.Text == "" || txt_phone_number_open.Text == "" || txt_cash_open.Text == "" || cbb_period_open.Text == "" || txt_passbook_name_open.Text == "" || cbb_staff_open.Text == "") { MessageBox.Show(IMessage.MSG_REQUIRED_ALL, IMessage.CPT_NOTICE); return; } // Validate input double _cash = Processor.ConvertToDouble(txt_cash_open.Text); if (_cash == Processor.UNIDENTIFIED) { MessageBox.Show(IMessage.MSG_WRONG_INPUT, IMessage.CPT_NOTICE); return; } if (_cash < Processor.ConvertToDouble(Params.PARAMS[Params.MIN_CASH].ToString())) { MessageBox.Show(IMessage.MSG_TOO_FEW_CASH, IMessage.CPT_NOTICE); return; } string _periodId = cbb_period_open.Text.Split(':')[0]; string _staffId = cbb_staff_open.Text.Split(':')[0]; DateTime _dateTime = calendar_open.SelectionEnd.Date; string _status = "open-" + _dateTime.ToString(); if (PassbookModel.InsertPassbook(txt_passbook_name_open.Text, _periodId, lbl_customer_id_open.Text, _staffId, txt_cash_open.Text, _dateTime.ToString(), _status) == false) { MessageBox.Show(IMessage.MSG_FAILED_CREATE_PASSBOOK, IMessage.CPT_NOTICE); return; } MessageBox.Show(IMessage.MSG_SUCCESS_CREATE_PASSBOOK, IMessage.CPT_CREATE_PASSBOOK); }
private void btn_apply_edit_customer_Click(object sender, EventArgs e) { if (txt_name_customer.Text == "" || txt_identity_number_customer.Text == "" || txt_address_customer.Text == "" || txt_phone_number_customer.Text == "") { MessageBox.Show(IMessage.MSG_REQUIRED_ALL, IMessage.CPT_NOTICE); return; } if (PassbookModel.UpdateCustomer(lbl_customer_id_customer.Text, txt_name_customer.Text, txt_identity_number_customer.Text, txt_address_customer.Text, txt_phone_number_customer.Text) == false) { MessageBox.Show(IMessage.MSG_FAILED_EDIT_ACCOUNT, IMessage.CPT_NOTICE); return; } MessageBox.Show(IMessage.MSG_SUCCESS_EDIT_ACCOUNT, IMessage.CPT_NOTICE); }
//////////////////////////////////////////////////////////////////// // Control for edit account /// <summary> /// /// </summary> private void btn_edit_account_Click(object sender, EventArgs e) { if (txt_email_account.Text == "" || txt_name_account.Text == "" || txt_identity_number_account.Text == "" || txt_phone_number_account.Text == "") { MessageBox.Show(IMessage.MSG_REQUIRED_ALL, IMessage.CPT_NOTICE); return; } if (PassbookModel.UpdateStaff(lbl_id_account.Text, txt_name_account.Text, txt_email_account.Text, txt_identity_number_account.Text, txt_phone_number_account.Text) == false) { MessageBox.Show(IMessage.MSG_FAILED_EDIT_ACCOUNT, IMessage.CPT_NOTICE); return; } MessageBox.Show(IMessage.MSG_SUCCESS_EDIT_ACCOUNT, IMessage.CPT_NOTICE); }
private void cbb_passbook_withdrawal_SelectedIndexChanged(object sender, EventArgs e) { string _passbookId = cbb_passbook_withdrawal.Text.Split(':')[0]; DataTable _data = PassbookModel.SelectPassbookById(_passbookId); if (_data.Rows.Count == 0) { MessageBox.Show(IMessage.MSG_SOMETHING_WENT_WRONG, IMessage.CPT_NOTICE); return; } object[] _passbook = _data.Rows[0].ItemArray; if (_passbook[TblColumn.P_PERIOD_ID].ToString() == "1") { txt_cash_withdrawal.Enabled = true; } else { txt_cash_withdrawal.Enabled = false; } }
//////////////////////////////////////////////////////////////////// // Control for edit customer /// <summary> /// /// </summary> /// private void SelectCustomer() { DataTable _data = null; // Select customer by identity number. This is priority order. if (txt_identity_number_customer.Text != "") { _data = PassbookModel.SelectCustomerByIdentityNumber(txt_identity_number_customer.Text); } // Select customer by phone number else if (txt_phone_number_customer.Text != "") { _data = PassbookModel.SelectCustomerByPhoneNumber(txt_phone_number_customer.Text); } else { MessageBox.Show(IMessage.MSG_REQUIRE_ID, IMessage.CPT_NOTICE); return; } if (_data.Rows.Count == 0) { MessageBox.Show(IMessage.MSG_ACCOUNT_NOT_FOUND, IMessage.CPT_NOTICE); return; } // Extract info object[] _customer = _data.Rows[0].ItemArray; lbl_customer_id_customer.Text = _customer[TblColumn.A_ID].ToString(); txt_name_customer.Text = _customer[TblColumn.A_NAME].ToString(); txt_identity_number_customer.Text = _customer[TblColumn.A_IDENTITY_NUMBER].ToString(); txt_address_customer.Text = _customer[TblColumn.A_ADDRESS].ToString(); txt_phone_number_customer.Text = _customer[TblColumn.A_PHONE_NUMBER].ToString(); txt_identity_number_customer.Enabled = false; }
private void LoadStaffList() { DataTable _data = PassbookModel.SelectAllStaff(); if (_data.Rows.Count == 0) { MessageBox.Show(IMessage.MSG_NO_STAFF, IMessage.CPT_NOTICE); return; } for (int i = 0; i < _data.Rows.Count; i++) { object[] _staff = _data.Rows[i].ItemArray; cbb_staff_open.Items.Add(_staff[TblColumn.S_ID].ToString() + ": " + _staff[TblColumn.S_NAME].ToString()); cbb_staff_deposit.Items.Add(_staff[TblColumn.S_ID].ToString() + ": " + _staff[TblColumn.S_NAME].ToString()); cbb_staff_withdrawal.Items.Add(_staff[TblColumn.S_ID].ToString() + ": " + _staff[TblColumn.S_NAME].ToString()); } int _staffId = Convert.ToInt32(Params.CURRENT_SESSION[Params.CURRENT_ID].ToString()) - 1; cbb_staff_open.SelectedIndex = _staffId; cbb_staff_deposit.SelectedIndex = _staffId; cbb_staff_withdrawal.SelectedIndex = _staffId; }
private void btn_create_deposit_Click(object sender, EventArgs e) { if (txt_name_deposit.Text == "" || txt_identity_number_deposit.Text == "" || txt_address_deposit.Text == "" || txt_phone_number_deposit.Text == "" || txt_cash_deposit.Text == "" || cbb_passbook_deposit.Text == "" || cbb_staff_deposit.Text == "") { MessageBox.Show(IMessage.MSG_REQUIRED_ALL, IMessage.CPT_NOTICE); return; } // Validate input double _income = Processor.ConvertToDouble(txt_cash_deposit.Text); if (_income == Processor.UNIDENTIFIED) { MessageBox.Show(IMessage.MSG_WRONG_INPUT, IMessage.CPT_NOTICE); return; } if (_income < Processor.ConvertToDouble(Params.PARAMS[Params.MIN_INCOME].ToString())) { MessageBox.Show(IMessage.MSG_TOO_FEW_CASH, IMessage.CPT_NOTICE); return; } // Submit income DateTime _dateTime = calendar_deposit.SelectionEnd.Date; string _passbookId = cbb_passbook_deposit.Text.Split(':')[0]; string _staffId = cbb_staff_deposit.Text.Split(':')[0]; if (PassbookModel.InsertIncome(_passbookId, _staffId, txt_cash_deposit.Text, _dateTime.ToString()) == false) { MessageBox.Show(IMessage.MSG_SOMETHING_WENT_WRONG, IMessage.CPT_NOTICE); return; } /////////////////////////////////////////////////////////////////// // Update passbook info DataTable _data = PassbookModel.SelectPassbookById(_passbookId); object[] _passbook = _data.Rows[0].ItemArray; // Reopen passbook if (Processor.Compare(_passbook[TblColumn.P_CASH].ToString(), "0") == 0) { List <string> _status = _passbook[TblColumn.P_STATUS].ToString().Split('|').ToList(); _status.Add("open-" + _dateTime.ToString()); PassbookModel.UpdateStatusByPassbookId(_passbookId, string.Join("|", _status)); } // Update cash string _cash = Processor.Add(txt_cash_deposit.Text, _passbook[TblColumn.P_CASH].ToString()); PassbookModel.UpdateCashByPassbookId(_passbookId, _cash); MessageBox.Show(IMessage.MSG_SUCCESS_CREATE_DEPOSIT, IMessage.CPT_CREATE_DEPOSIT); }
private void btn_create_withdrawal_Click(object sender, EventArgs e) { if (txt_name_withdrawal.Text == "" || txt_identity_number_withdrawal.Text == "" || txt_address_withdrawal.Text == "" || txt_phone_number_withdrawal.Text == "" || cbb_passbook_withdrawal.Text == "" || cbb_staff_withdrawal.Text == "") { MessageBox.Show(IMessage.MSG_REQUIRED_ALL, IMessage.CPT_NOTICE); return; } string _passbookId = cbb_passbook_withdrawal.Text.Split(':')[0]; DataTable _data = PassbookModel.SelectPassbookById(_passbookId); if (_data.Rows.Count == 0) { MessageBox.Show(IMessage.MSG_SOMETHING_WENT_WRONG, IMessage.CPT_NOTICE); return; } object[] _passbook = _data.Rows[0].ItemArray; DateTime _current = calendar_withdrawal.SelectionEnd.Date; DateTime _opened = DateTime.Parse(_passbook[TblColumn.P_DATE_TIME].ToString()); string _periodId = _passbook[TblColumn.P_PERIOD_ID].ToString(); DataTable _data1 = PassbookModel.SelectPeriodById(_periodId); if (_data1.Rows.Count == 0) { MessageBox.Show(IMessage.MSG_SOMETHING_WENT_WRONG, IMessage.CPT_NOTICE); return; } object[] _period = _data1.Rows[0].ItemArray; if (Processor.Compare((_current - _opened).Days.ToString(), _period[TblColumn.T_PERIOD].ToString()) < 0) { MessageBox.Show(IMessage.MSG_NOT_REACH_PERIOD, IMessage.CPT_NOTICE); return; } string _rate = Processor.Div(_period[TblColumn.T_RATE].ToString(), "100"); string _cash = _passbook[TblColumn.P_CASH].ToString(); string _withdrawal = "0"; string _profit = "0"; if (_periodId == "1") { if (txt_cash_withdrawal.Text == "") { MessageBox.Show(IMessage.MSG_REQUIRED_ALL, IMessage.CPT_NOTICE); return; } // Validate input double _outcome = Processor.ConvertToDouble(txt_cash_withdrawal.Text); if (_outcome == Processor.UNIDENTIFIED) { MessageBox.Show(IMessage.MSG_WRONG_INPUT, IMessage.CPT_NOTICE); return; } if (_outcome > Processor.ConvertToDouble(_cash)) { MessageBox.Show(IMessage.MSG_NOT_ENOUGH_MONEY, IMessage.CPT_NOTICE); return; } _withdrawal = txt_cash_withdrawal.Text; _profit = Processor.Multi(Processor.Multi(_cash, _rate), Processor.Div((_current - _opened).Days.ToString(), "30")); _cash = Processor.Sub(_cash, _withdrawal); } else { _withdrawal = _cash; _profit = Processor.Multi(Processor.Multi(_cash, _rate), Processor.Div(_period[TblColumn.T_PERIOD].ToString(), "30")); _cash = "0"; } string _staffId = cbb_staff_withdrawal.Text.Split(':')[0]; // Create withdrawal if (PassbookModel.InsertOutcome(_passbookId, _staffId, _withdrawal, _current.ToString()) == false) { MessageBox.Show(IMessage.MSG_SOMETHING_WENT_WRONG, IMessage.CPT_NOTICE); return; } // Close passbook if (Processor.Compare(_cash, "0") == 0) { List <string> _status = _passbook[TblColumn.P_STATUS].ToString().Split('|').ToList(); _status.Add("close-" + _current.ToString()); PassbookModel.UpdateStatusByPassbookId(_passbookId, string.Join("|", _status)); } // Update info PassbookModel.UpdateCashByPassbookId(_passbookId, _cash); PassbookModel.UpdateLastUpdateTimeByPassbookId(_passbookId, _current.ToString()); MessageBox.Show("Success. Cash: " + _withdrawal + ", Profit: " + _profit, "Create Withdrawal"); }
private void btn_apply_edit_period_Click(object sender, EventArgs e) { if ((m_roles & Roles.ROLE_MANAGER) != Roles.ROLE_MANAGER) { MessageBox.Show(IMessage.MSG_PERMISSION_DENY, IMessage.CPT_NOTICE); return; } switch (m_control) { case ControlBtn.CONTROL_ADD: { if (txt_name_edit_period.Text == "" || txt_rate_edit_period.Text == "" || txt_period_edit_period.Text == "") { MessageBox.Show(IMessage.MSG_REQUIRED_ALL, IMessage.CPT_NOTICE); return; } DataTable _data = PassbookModel.SelectPeriodByName(txt_name_edit_period.Text); if (_data.Rows.Count != 0) { MessageBox.Show(IMessage.MSG_PERIOD_ALREADY_EXIST, IMessage.CPT_NOTICE); return; } if (PassbookModel.InsertPeriod(txt_name_edit_period.Text, txt_rate_edit_period.Text, txt_period_edit_period.Text) == false) { MessageBox.Show(IMessage.MSG_SOMETHING_WENT_WRONG, IMessage.CPT_NOTICE); return; } MessageBox.Show(IMessage.MSG_SUCCESS_ADD_PERIOD, IMessage.CPT_CREATE_PERIOD); } break; case ControlBtn.CONTROL_EDIT: { if (txt_name_edit_period.Text == "" || txt_rate_edit_period.Text == "" || txt_period_edit_period.Text == "") { MessageBox.Show(IMessage.MSG_REQUIRED_ALL, IMessage.CPT_NOTICE); return; } if (PassbookModel.UpdatePeriod(lbl_id_edit_period.Text, txt_name_edit_period.Text, txt_rate_edit_period.Text, txt_period_edit_period.Text) == false) { MessageBox.Show(IMessage.MSG_SOMETHING_WENT_WRONG, IMessage.CPT_NOTICE); return; } MessageBox.Show(IMessage.MSG_SUCCESS_EDIT_PERIOD, IMessage.CPT_EDIT_PERIOD); } break; case ControlBtn.CONTROL_REMOVE: { if (cbb_period_edit_period.Text == "") { MessageBox.Show(IMessage.MSG_PERIOD_NOT_EXIST, IMessage.CPT_NOTICE); return; } DataTable _data = PassbookModel.SelectPeriodByName(cbb_period_edit_period.Text); if (_data.Rows.Count == 0) { MessageBox.Show(IMessage.MSG_SOMETHING_WENT_WRONG, IMessage.CPT_NOTICE); return; } object[] _period = _data.Rows[0].ItemArray; string _periodId = _period[TblColumn.T_ID].ToString(); if (_periodId == "1") { MessageBox.Show(IMessage.MSG_FAILED_DELETE_PERIOD, IMessage.CPT_NOTICE); return; } if (PassbookModel.DeletePeriodById(_periodId) == false) { MessageBox.Show(IMessage.MSG_SOMETHING_WENT_WRONG, IMessage.CPT_NOTICE); return; } MessageBox.Show(IMessage.MSG_SUCCESS_DELETE_PERIOD, IMessage.CPT_DELETE_PERIOD); } break; default: break; } }
private void btn_show_monthly_Click(object sender, EventArgs e) { if (cbb_period_monthly.Text == "") { MessageBox.Show(IMessage.MSG_REQUIRE_PERIOD, IMessage.CPT_NOTICE); return; } DateTime _dateTime = date_monthly.Value; DataTable _data1 = PassbookModel.SelectPeriodByName(cbb_period_monthly.Text); if (_data1.Rows.Count == 0) { MessageBox.Show(IMessage.MSG_SOMETHING_WENT_WRONG, IMessage.CPT_NOTICE); return; } object[] _period = _data1.Rows[0].ItemArray; string _periodId = _period[TblColumn.T_ID].ToString(); list_monthly.Items.Clear(); int _daysCount = Processor.CountDay(_dateTime.Month, _dateTime.Year); for (int i = 0; i < _daysCount; i++) { ListViewItem _item = new ListViewItem((i + 1).ToString()); // Set date string _date = (i + 1) + "/" + _dateTime.Month + "/" + _dateTime.Year; _item.SubItems.Add(_date); DateTime _current = DateTime.ParseExact(_date, "d/M/yyyy", CultureInfo.InvariantCulture); // Set income/outcome value int _income = 0; int _outcome = 0; DataTable _data2 = PassbookModel.SelectAllPassbooks(); for (int j = 0; j < _data2.Rows.Count; j++) { object[] _passbook = _data2.Rows[j].ItemArray; if (_passbook[TblColumn.P_PERIOD_ID].ToString() == _periodId) { List <string> _status = _passbook[TblColumn.P_STATUS].ToString().Split('|').ToList(); foreach (string __status in _status) { string[] _params = __status.Split('-'); DateTime _statusDate = DateTime.Parse(_params[1]); if (_current.Year == _statusDate.Year && _current.Date.DayOfYear == _statusDate.Date.DayOfYear) { if (_params[0] == "open") { _income++; } else { _outcome++; } } } } } if (_income > 0) { _item.SubItems.Add(_income.ToString(), Color.DarkCyan, Color.Transparent, list_monthly.Font); } else { _item.SubItems.Add(_income.ToString()); } if (_outcome > 0) { _item.SubItems.Add(_outcome.ToString(), Color.DarkCyan, Color.Transparent, list_monthly.Font); } else { _item.SubItems.Add(_outcome.ToString()); } // Set total value if (_income - _outcome != 0) { _item.SubItems.Add((_income - _outcome).ToString(), Color.Red, Color.Transparent, list_monthly.Font); } else { _item.SubItems.Add((_income - _outcome).ToString()); } list_monthly.Items.Add(_item); } }
//////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// // Control for create passbook /// <summary> /// /// </summary> /// private void SelectCustomerOpen() { DataTable _data = null; // Select customer by identity number. This is priority order. if (txt_identity_number_open.Text != "") { _data = PassbookModel.SelectCustomerByIdentityNumber(txt_identity_number_open.Text); } // Select customer by phone number else if (txt_phone_number_open.Text != "") { _data = PassbookModel.SelectCustomerByPhoneNumber(txt_phone_number_open.Text); } else { MessageBox.Show(IMessage.MSG_REQUIRE_ID, IMessage.CPT_NOTICE); return; } if (_data.Rows.Count == 0) { MessageBox.Show(IMessage.MSG_ACCOUNT_NOT_FOUND, IMessage.CPT_NOTICE); return; } // Extract info object[] _customer = _data.Rows[0].ItemArray; lbl_customer_id_open.Text = _customer[TblColumn.A_ID].ToString(); txt_name_open.Text = _customer[TblColumn.A_NAME].ToString(); txt_identity_number_open.Text = _customer[TblColumn.A_IDENTITY_NUMBER].ToString(); txt_address_open.Text = _customer[TblColumn.A_ADDRESS].ToString(); txt_phone_number_open.Text = _customer[TblColumn.A_PHONE_NUMBER].ToString(); // Initialize cbb_period_open DataTable _data2 = PassbookModel.SelectAllPeriod(); if (_data2.Rows.Count == 0) { MessageBox.Show(IMessage.MSG_SOMETHING_WENT_WRONG, IMessage.CPT_NOTICE); return; } for (int i = 0; i < _data2.Rows.Count; i++) { object[] _period = _data2.Rows[i].ItemArray; cbb_period_open.Items.Add(_period[TblColumn.T_NAME].ToString()); } cbb_period_open.SelectedIndex = 0; // UX Enhancer txt_name_open.Enabled = false; txt_identity_number_open.Enabled = false; txt_address_open.Enabled = false; txt_phone_number_open.Enabled = false; btn_check_open.Enabled = false; btn_submit_open.Enabled = false; btn_create_open.Enabled = true; }
//////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// // Control for create daily report private void btn_refresh_daily_Click(object sender, EventArgs e) { DateTime _dateTime = date_daily.Value; list_daily.Items.Clear(); DataTable _data = PassbookModel.SelectAllPeriod(); for (int i = 0; i < _data.Rows.Count; i++) { ListViewItem _item = new ListViewItem((i + 1).ToString()); // Set period name object[] _period = _data.Rows[i].ItemArray; _item.SubItems.Add(_period[TblColumn.T_NAME].ToString()); // Set income value string _income = "0"; DataTable _data1 = PassbookModel.SelectAllIncomesByPeriodId(_period[TblColumn.T_ID].ToString()); for (int j = 0; j < _data1.Rows.Count; j++) { object[] _row = _data1.Rows[j].ItemArray; DateTime _current = DateTime.Parse(_row[TblColumn.D_DATE_TIME].ToString()); if (_dateTime.DayOfYear == _current.DayOfYear) { _income = Processor.Add(_income, _row[TblColumn.D_CASH].ToString()); } } string _incomeFormatted = string.Format("{0:#,##0}", Processor.ConvertToDouble(_income)); _item.SubItems.Add(_incomeFormatted + " VND"); // Set outcome value string _outcome = "0"; DataTable _data2 = PassbookModel.SelectAllOutcomesByPeriodId(_period[TblColumn.T_ID].ToString()); for (int j = 0; j < _data2.Rows.Count; j++) { object[] _row = _data2.Rows[j].ItemArray; DateTime _current = DateTime.Parse(_row[TblColumn.W_DATE_TIME].ToString()); if (_dateTime.DayOfYear == _current.DayOfYear) { _outcome = Processor.Add(_outcome, _row[TblColumn.W_CASH].ToString()); } } string _outcomeFormatted = string.Format("{0:#,##0}", Processor.ConvertToDouble(_outcome)); _item.SubItems.Add(_outcomeFormatted + " VND"); // Set total value string _totalFormatted = string.Format("{0:#,##0}", Processor.ConvertToDouble(Processor.Sub(_income, _outcome))); _item.SubItems.Add(_totalFormatted + " VND"); list_daily.Items.Add(_item); } }