/// <summary> /// sample code to update a loaded service employee /// </summary> private void btnUpdate_Click(object sender, EventArgs e) { if (myScreen == null) { MessageBox.Show("You must load an employee before updating!"); return; } try { //pull our smEmp entry from the grid on window to get any changes ctDynamicsSL.fieldService.serviceDispatch.maintenance.serviceEmployeeMaintenance.smEmp[] tmpArray = (ctDynamicsSL.fieldService.serviceDispatch.maintenance.serviceEmployeeMaintenance.smEmp[])gvsmEmp.DataSource; //set the updated data to our screen object myScreen.mysmEmp = tmpArray[0]; //test the data with the VALIDATEONLY call var validate = mySEMService.editScreen("VALIDATEONLY", myScreen); if (validate.errorMessage.Trim() != "") { //failed validation, error out MessageBox.Show(validate.errorMessage); return; } else { //passed validation, lets UPDATE the entry var result = mySEMService.editScreen("UPDATE", myScreen); if (result.errorMessage.Trim() != "") { //failed for some reason MessageBox.Show(result.errorMessage); return; } else { //UPDATE complete, lets reload the current data to the window myScreen = result; tbScreen.Text = ctStandardLib.ctHelper.serializeObject(myScreen).Replace("><", ">" + Environment.NewLine + "<"); tmpArray = new ctDynamicsSL.fieldService.serviceDispatch.maintenance.serviceEmployeeMaintenance.smEmp[1]; tmpArray[0] = myScreen.mysmEmp; gvsmEmp.DataSource = tmpArray; MessageBox.Show("Update Complete!"); } } } catch (Exception ex) { MessageBox.Show("Unexpected error in Update: " + ex.Message); } }
/// <summary> /// Loads a service employee screen object /// </summary> private void btnLoad_Click(object sender, EventArgs e) { try { myScreen = mySEMService.getScreenByEmployee(tbEmployeeID.Text.Trim()); if (myScreen.errorMessage != "") { MessageBox.Show("Error: " + myScreen.errorMessage); return; } ctDynamicsSL.fieldService.serviceDispatch.maintenance.serviceEmployeeMaintenance.smEmp[] tmpArray = new ctDynamicsSL.fieldService.serviceDispatch.maintenance.serviceEmployeeMaintenance.smEmp[1]; tmpArray[0] = myScreen.mysmEmp; gvsmEmp.DataSource = tmpArray; btnUpdate.Enabled = true; tbScreen.Text = ctStandardLib.ctHelper.serializeObject(myScreen).Replace("><", ">" + Environment.NewLine + "<"); } catch (Exception ex) { MessageBox.Show("Unexpected error in Load: " + ex.Message); } }
/// <summary> /// Sample code to generate a new service employee smEmp entry /// required fields marked as so /// lookups for all fields also listed /// </summary> private void btnNew_Click(object sender, EventArgs e) { try { String tmpEmployeeID = tbEmployeeID.Text.Trim(); if (tmpEmployeeID == "") {//employeeID required, generating one tmpEmployeeID = myCommonService.getNextCounterAsString("SMEMPLOYEEID"); } //create a blank smEmp object var newEntry = new ctDynamicsSL.fieldService.serviceDispatch.maintenance.serviceEmployeeMaintenance.smEmp(); newEntry.EmployeeId = tmpEmployeeID; //required newEntry.CpnyID = System.Configuration.ConfigurationManager.AppSettings["CPNYID"]; //required //load any defaults that are dependent on cpnyID set above newEntry = mySEMService.getNewsmEmp(newEntry); //loads defaults newEntry.EmployeeFirstName = "Testing"; //required newEntry.EmployeeLastName = "Guy"; //required //not required fields; but if set they must be valid newEntry.employeeaddress1 = "1 Test Rd."; newEntry.EmployeeCity = "Beverly Hills"; try { newEntry.EmployeeBranchID = mySEMService.getBranchesByID("")[0].BranchId; } catch { } try { newEntry.EmployeePayRollId = mySEMService.getPayrollIDsByID("")[0].EmpId; } catch { } try { newEntry.InvtSiteID = mySEMService.getSitesByID("")[0].SiteId; } catch { } try { newEntry.EmployeeState = mySEMService.getStatesByID("")[0].StateProvId; } catch { } try { newEntry.TemplateID = mySEMService.getTemplatesByID("")[0].TemplateId; } catch { } try { newEntry.EmployeeZip = mySEMService.getZipCodesByID("")[0].ZipId; } catch { } try { newEntry.EmployeeType = mySEMService.getEmployeeClassesByID("")[0].Empclassid; } catch { } //populate a screen object with our new entry myScreen = new ctDynamicsSL.fieldService.serviceDispatch.maintenance.serviceEmployeeMaintenance.screen(); myScreen.mysmEmp = newEntry; //make a call to validate the screen var validate = mySEMService.editScreen("VALIDATEONLY", myScreen); if (validate.errorMessage.Trim() != "") { //if errorMessage is blank, then validation failed MessageBox.Show(validate.errorMessage); return; } else { //passed validation, lets save the new entry with ADD var result = mySEMService.editScreen("ADD", myScreen); if (result.errorMessage.Trim() != "") { //Error saving! MessageBox.Show(result.errorMessage); return; } else { //no errors in saving, lets save the results to the screen myScreen = result; tbScreen.Text = ctStandardLib.ctHelper.serializeObject(myScreen).Replace("><", ">" + Environment.NewLine + "<"); ctDynamicsSL.fieldService.serviceDispatch.maintenance.serviceEmployeeMaintenance.smEmp[] tmpArray = new ctDynamicsSL.fieldService.serviceDispatch.maintenance.serviceEmployeeMaintenance.smEmp[1]; tmpArray[0] = myScreen.mysmEmp; gvsmEmp.DataSource = tmpArray; tbEmployeeID.Text = myScreen.mysmEmp.EmployeeId; MessageBox.Show("New Complete!"); } } } catch (Exception ex) { MessageBox.Show("Unexpected error in New:: " + ex.Message); } }