private void SaveProfileMasterDetail() { ProfileDetail thisPD = new ProfileDetail(); thisPD.operationName = profileCB.Text; thisPD.dataFolder = dataFolderTxt.Text; if (string.IsNullOrEmpty(prefixTxt.Text)) { prefixTxt.Text = profileCB.Text; thisPD.prefix = profileCB.Text; } else { thisPD.prefix = prefixTxt.Text; } thisPD.sampleNo = noOfSampleCB.Text != "" ? Convert.ToInt32(noOfSampleCB.Text) : 0; thisPD.sampleDefinitionFile = sampleDefinitionFileTxt.Text; thisPD.commonSDF = sdfCommonCB.Checked; thisPD.calibrationFile = calibrationFileTxt.Text; thisPD.commonCalibrationFile = calibrarionCommonCB.Checked; thisPD.qtyUnit = sampleQtyUnitCB.Text; thisPD.commonQtyUnit = sampleQtyUnitCommonCB.Checked; thisPD.qty = sampleQtyTxt.Text != "" ? Convert.ToDouble(sampleQtyTxt.Text) : 0.000; thisPD.commonQty = sampleQtyCommonCB.Checked; thisPD.countingTime = countingTime.Text != "" ? Convert.ToInt32(countingTime.Text) : 0; thisPD.commonCountingTime = countingTimeCommonCB.Checked; thisPD.activityUnit = activityUnitCB.Text; thisPD.commonActivityUnit = activityUnitCommonCB.Checked; thisPD.libraryFile = libraryFileTxt.Text; thisPD.commonLibrary = libraryCommonCB.Checked; thisPD.disableDecayCorrection = decayCorrectionCB.Checked; thisPD.commonDecayCorrection = decayCorrectionCommonCB.Checked; //if (decayCorrectionCommonCB.Checked && !decayCorrectionCB.Checked) //{ // thisPD.commonDecayCorrection = false; // decayCorrectionCommonCB.Checked = false; //} // //thisPD.decayCorrectionDate = decayCorrectionDTPicker.Value.ToString(); //thisPD.commonDecayDate = decayDateCommonCB.Checked; thisPD.sampleDetailList = SaveProfileSamplesDetail(); //each sample GlobalFunc.toggleProfileDetail = thisPD; string json = js.Serialize(thisPD); File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"ProfileDetail\" + thisPD.operationName + ".json", json); MessageBox.Show("Save " + profileCB.Text + " successful"); GlobalFunc.LoadProfileDetail(); //load each profile json }
public static void LoadProfileDetail() { JavaScriptSerializer js = new JavaScriptSerializer(); GlobalFunc.profileDetailList = new List <ProfileDetail>(); for (int i = 0; i < GlobalFunc.profile.operationName.Count; i++) { if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"ProfileDetail\" + GlobalFunc.profile.operationName[i] + ".json")) { ProfileDetail profileDetail = (ProfileDetail)js.Deserialize <ProfileDetail>(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"ProfileDetail\" + GlobalFunc.profile.operationName[i] + ".json")); GlobalFunc.profileDetailList.Add(profileDetail); } else { #region default profile ProfileDetail profileDetail = new ProfileDetail(); profileDetail.operationName = GlobalFunc.profile.operationName[i]; profileDetail.CreateDate = DateTime.Now.ToString(); profileDetail.sampleDetailList = new List <SampleDetail>(); profileDetail.dataFolder = ""; profileDetail.prefix = ""; profileDetail.sampleNo = 0; profileDetail.sampleDefinitionFile = ""; profileDetail.calibrationFile = ""; profileDetail.commonCalibrationFile = true; profileDetail.qtyUnit = ""; profileDetail.commonQtyUnit = true; profileDetail.qty = 0; profileDetail.commonQty = true; profileDetail.countingTime = 0; profileDetail.commonCountingTime = true; profileDetail.activityUnit = ""; profileDetail.commonActivityUnit = true; profileDetail.libraryFile = ""; profileDetail.disableDecayCorrection = true; //profileDetail.decayCorrectionDate = DateTime.Now.ToString(); GlobalFunc.profileDetailList.Add(profileDetail); #endregion } } }