//yee test private void SetBindingSource() { var datateethbinding = (from t1 in db.trn_teeth_hdrs where t1.tpr_id == TprID select t1).FirstOrDefault(); if (datateethbinding != null) { TeethbindingSource1.DataSource = (from t1 in db.trn_teeth_hdrs where t1.tpr_id == TprID select t1).FirstOrDefault(); trn_teeth_hdr objtrnteethhdr = (trn_teeth_hdr)TeethbindingSource1.Current; Program.SetValueRadioGroup(GBGumfoState, objtrnteethhdr.tth_gum_of_state); Program.SetValueRadioGroup(GBbedTooth, objtrnteethhdr.tth_bad_tooth); Program.SetValueRadioGroup(GBThimbleofState, objtrnteethhdr.tth_thimble_of_state); trnteethdtlsBindingSource.DataSource = objtrnteethhdr.trn_teeth_dtls; ResetTeethbutton(); } else { TeethbindingSource1.DataSource = db.trn_teeth_hdrs; TeethbindingSource1.AddNew(); } }
private void Save(char strType) { Boolean saveIsCompleted = false; if (TeethbindingSource1.DataSource != null) { DateTime datenow = Program.GetServerDateTime(); try { trn_teeth_hdr objteethHdr = (trn_teeth_hdr)TeethbindingSource1.Current; objteethHdr.tth_type = strType; objteethHdr.tth_gum_of_state = Program.GetValueRadioTochar(GBGumfoState); objteethHdr.tth_bad_tooth = Program.GetValueRadio(GBbedTooth); objteethHdr.tth_thimble_of_state = Program.GetValueRadioTochar(GBThimbleofState); objteethHdr.tth_create_by = Program.CurrentUser.mut_username; objteethHdr.tth_create_date = datenow; objteethHdr.tth_update_by = objteethHdr.tth_create_by; objteethHdr.tth_update_date = objteethHdr.tth_create_date; objteethHdr.tpr_id = TprID; var objdeltrnteethdocresult = (from t1 in db.trn_teeth_doc_results where t1.tth_id == objteethHdr.tth_id select t1).ToList(); if (objdeltrnteethdocresult.Count != 0) { db.trn_teeth_doc_results.DeleteAllOnSubmit(objdeltrnteethdocresult); db.SubmitChanges(); } foreach (object itemChecked in chList.CheckedItems) { // เพิ่มรายการใหม่ trn_teeth_doc_result objnew = new trn_teeth_doc_result(); objnew.tdr_create_by = Program.CurrentUser.mut_username; objnew.tdr_create_date = datenow; objnew.tdr_update_date = datenow; objnew.tdr_update_by = objnew.tdr_create_by; objnew.tth_id = objteethHdr.tth_id; objnew.trn_teeth_hdr = objteethHdr; objnew.mdr_id = Convert.ToInt32(Program.GetCheckedListBoxValue(itemChecked, chList)); db.trn_teeth_doc_results.InsertOnSubmit(objnew); } trnteethdtlsBindingSource.EndEdit(); TeethbindingSource1.EndEdit(); db.SubmitChanges(); saveIsCompleted = true; } catch (Exception ex) { Program.MessageError("=>Save Teeth==>Try Submitchanges() :" + ex.Message); } if (saveIsCompleted == true) { lblMsg.Text = "Save data completed."; timer1.Enabled = true; } } //return saveIsCompleted; }