//Constructor of this viewModel public ContractorManagementViewModel() { //1. Its going to connect to DAL and bring in the results of all Contractors //2. We create objects of type contractor and then add that object to our collection DAL dal = new DAL(); DataTable dt = dal.Read("Select * from bit_contractor, bit_user_logon where bit_user_logon.account_Type='CONTRACTOR' AND bit_user_logon.account_Ref= bit_contractor.contractor_Id and (STATUS='ACTIVE' OR STATUS IS NULL)"); foreach (DataRow dr in dt.Rows) { Contractor contractor = new Contractor(dr); ContractorCollection.Add(contractor); } if (ContractorCollection.Count == 0) { // ReadOnlyContractor = Boolean.Parse("FALSE"); Contractor contractor = new Contractor(); ContractorCollection.Add(contractor); SelectedContractor = contractor; } else { // ReadOnlyContractor = Boolean.Parse("TRUE"); } LoadFieldNameCombo(); IsEnabledRoster = true; IsEnabledSkill = true; IsEnabledSuburb = true; IsEnabledAdd = true; IsEnabledSave = true; IsEnabledDelete = true; }
private void SearchContractor() { DAL dal = new DAL(); ContractorCollection.Clear(); if (SelectedContractorCols.Equals("User_Id")) { //ContractorSearchString = "CN" + ContractorSearchString; SelectedContractorCols = "bit_user_logon.userName"; } DataTable dt = dal.Read("Select bit_contractor.*,bit_user_logon.userName from bit_contractor , bit_user_logon where bit_user_logon.account_Type='CONTRACTOR' AND bit_user_logon.account_Ref= bit_contractor.contractor_Id and (STATUS='ACTIVE' OR STATUS IS NULL) and " + SelectedContractorCols + " like '%" + ContractorSearchString + "%'"); int i = 0; int index = 0; Contractor contractorFirstRecord = new Contractor(); foreach (DataRow dr in dt.Rows) { index = i; if (index == 0) { contractorFirstRecord = new Contractor(dr); } Contractor contractor = new Contractor(dr); ContractorCollection.Add(contractor); i++; } if (ContractorCollection.Count == 0) { // ReadOnlyContractor = Boolean.Parse("FALSE"); Contractor contractor = new Contractor(); ContractorCollection.Add(contractor); SelectedContractor = contractor; } else { // ReadOnlyContractor = Boolean.Parse("TRUE"); } SelectedContractor = contractorFirstRecord; // MessageBox.Show(SelectedClientCols + ClientSearchString); }
private void DeleteContractor() { try { if (MessageBox.Show("Are you sure you want to PERMANENTLY delete the Contractor's details?", "Delete Contractor?", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { SelectedContractor.Delete(); ContractorCollection.Remove(SelectedContractor); MessageBox.Show("Thank you! The Contractor's details have been deleted!", "Delete Contractor?", MessageBoxButton.OK, MessageBoxImage.Information); } else { return; } } catch (Exception ex) { MessageBox.Show("An Error Occured, The Contractor Details have not been deleted. Please Contact your System Administrator.", "Delete Contractor?" + ex.Message); } }
private void AddContractor() { if (!Regex.Match(SelectedContractor.MobileNumber, "^0[0-9]{9}$").Success) { MessageBox.Show("Enter valid phone number.", "Phone Number", MessageBoxButton.OK, MessageBoxImage.Error); return; } // SelectedContractor.Insert(); Contractor contractor = new Contractor(); ContractorCollection.Add(contractor); SelectedContractor = contractor; IsEnabledRoster = false; IsEnabledSkill = false; IsEnabledSuburb = false; IsEnabledAdd = false; IsEnabledSave = true; IsEnabledDelete = false; MessageBox.Show("Click Save button after entering the new Contractor details.", "Add Contractor", MessageBoxButton.OK, MessageBoxImage.Warning); }