Preparation Specifications for Common Codes (3) - The Assignment of Objects and Save December 9, 2004
3. The assignment of the object and the assignment of the saved object, follows three steps, 1. Data check, 2. Attribute assignment, 3. When the property is assigned, you must first ensure that a statement assigns a value of an attribute, if There is a transformation to use a function to ensure this. Then, for the relationship between an object, the object needs to be saved, and the function is used, and the object is saved separately, and do not mix together. The examples are as follows: 1. Main function private void bt_save_click (object sender, system.eventargs e) {if (! VerifyData ()) Return;
SavePerson ();
Response.Redirect ("wfrfdlist.aspx");} 2. Data check private bool verifydata () {string smsg = ""; if (tb_no.text.trim () == "" "{SMSG =" must set employee Job number"; }
IF (this.tbcardno.text.trim () == "" ") {SMSG =" must set the employee card number ";
IF (this.tb_name.text.trim () == "" "SMSG =" Employee's name cannot be empty ";
IF (DDDEPARTMENT.SELECTEDVALUE == null || ddDepartment.SelectedValue == "") SMSG = "Inaudo department can't be empty";
IF (ddposition.selectedValue == null || ddposition.selectedValue == "") SMSG = "The position cannot be empty";
IF (ddpost.selectedValue == null || ddpost.selectedValue == "") SMSG = "The position cannot be empty";
IF (this.ddpositionLevel .SelectedValue == Null || DDPOStionledLevel.SelectedValue == "") SMSG = "The level can not be empty"; if (tb_salary.text == "") SMSG = "Salard cannot be empty";
IF (SMSG.LENGTH> 0) {WebsiteHelper.showalertMessage (SMSG); Return False;} Return true;} 3. Assignment assignment 3A. A object itself saves private int salesPerson () {CPERSON PERSON = getPerson (); Person .Name = this.tb_name.text; person.Tbenglishname = this.tbenglishname .text; saveduty (person.reportforduty, person); person.State = 5; person.save (); chelper.flushSession (); return 0;} . 3b associated objects stored private CReportForDuty SaveDuty (CReportForDuty report, CPerson person) {if (report == null) report = new CReportForDuty (); report.StartTime = this.sy_start.DateValue; report.TrainingMothes = System.Int16.Parse (this.ddMonth.SelectedItem.Value); report.ProbationershipSalary = GetProbationershipSalary (); report.Person = person; report.State = 1; report.EndTime = report.StartTime.AddMonths (report.TrainingMothes); report.RFDTime = DateTime .Now; report.employee = this.saveemployee (Report.employee, Person);
report.ProbationershipAccession = this.SaveAccession (report.ProbationershipAccession, report.Employee); report.Employee.CurrentAccession = report.ProbationershipAccession; report.ProbationershipPost = this.SaveAppointPost (report.ProbationershipPost, report.Employee); report.Employee .CurrentPost = Report.probationershipPost; Report.employee .save ();
Report.save (); RETURN Report;} 3c. Data Conversion Private Decimal getProbationershipSalary () {Try {Return Decimal.Parse (this.tb_salary.text);} catCh {return 0.0m;}} 4. Save Due to the background E / R MAPPING, here Save is just a simple call save () method.