예제 #1
0
 private async void SaveBTN_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrWhiteSpace(FileNameTB.Text))
     {
         _currentFile.Name = FileNameTB.Text;
         if (await _processingService.SaveFile(_currentFile))
         {
             IsFileSaved = true;
             this.Close();
             FileNameTB.Clear();
         }
         else
         {
             MessageBox.Show("File with the same name already exists!", "Error");
         }
     }
     else
     {
         MessageBox.Show("File name is empty!", "Error");
     }
 }
예제 #2
0
        private void LoadDataFile(string origreflfilename)
        {
            try
            {
                if (!ReflData.Instance.SetReflData(origreflfilename, !errorsAreInVarianceToolStripMenuItem.Checked))
                {
                    throw new Exception("Could not load file");
                }

                FileNameTB.Text = origreflfilename;
                settingsfile    = origreflfilename + "settings.xml";
                reflgraphobject.SetAllFonts("Garamond", 20, 18);
                reflgraphobject.SubSLD         = SubSLDTB.ToDouble();
                reflgraphobject.SupSLD         = SupSLDTB.ToDouble();
                reflgraphobject.GetHighQOffset = ReflData.Instance.GetNumberDataPoints;
                reflgraphobject.GetLowQOffset  = 0;
                reflgraphobject.SetGraphType(forceRQ4GraphingToolStripMenuItem.Checked, fresnelcb.Checked);
                //Load the modeled files if they are available
                if (File.Exists(settingsfile) && !m_bloadfromcommandline)
                {
                    if (MessageBox.Show("Do you want to load the previous run?", "Resume?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        rhographobject.Clear();
                        reflgraphobject.Clear();

                        if (!LoadSettings())
                        {
                            return;
                        }


                        string tempfile = ReflData.Instance.GetWorkingDirectory + "\\rho.dat";

                        if (File.Exists(tempfile))
                        {
                            LoadZ(tempfile);
                            rhographobject.SubSLD = double.Parse(SubSLDTB.Text);
                            rhographobject.UseSLD = UseSLDToolStripMenuItem.Checked;

                            if (UseSLDToolStripMenuItem.Checked)
                            {
                                rhographobject.SetAxisTitles("Z", "SLD");
                                rhographobject.Title = "Model Independent SLD Fit";
                            }
                            else
                            {
                                rhographobject.SetAxisTitles("Z", "Normalized Electron Density");
                                rhographobject.Title = "Model Independent Electron Density Fit";
                            }
                            rhographobject.LoadFiletoGraph(tempfile.ToString(), rhomodelname, "Model Independent Electron Density Fit", Color.Tomato, SymbolType.None, 0, true);
                        }

                        tempfile = ReflData.Instance.GetWorkingDirectory + "\\rf.dat";

                        if (File.Exists(tempfile))
                        {
                            reflgraphobject.SubSLD = double.Parse(SubSLDTB.Text);
                            reflgraphobject.SupSLD = double.Parse(SupSLDTB.Text);
                            reflgraphobject.SetGraphType(forceRQ4GraphingToolStripMenuItem.Checked, fresnelcb.Checked);
                            reflgraphobject.GetLowQOffset  = int.Parse(critedgeoffTB.Text);
                            reflgraphobject.GetHighQOffset = ReflData.Instance.GetNumberDataPoints - int.Parse(HQoffsetTB.Text);
                            //Load the data file to the graph
                            reflgraphobject.LoadDatawithErrorstoGraph("Reflectivity Data", Color.Black, SymbolType.Circle, 5, ReflData.Instance.GetQData, ReflData.Instance.GetReflData);
                            reflgraphobject.LoadFiletoGraph(tempfile.ToString(), modelreflname, "Model Independent Reflectivity", Color.Tomato, SymbolType.Square, 2, true);
                        }

                        GraphCollection.Instance.MainReflGraph = reflgraphobject;
                        GraphCollection.Instance.MainRhoGraph  = rhographobject;

                        UpdateReportParameters();
                    }
                    else
                    {
                        //Clear the report
                        ReportGenerator.Instance.ClearAll();

                        //Load the data file to the graph
                        reflgraphobject.LoadDatawithErrorstoGraph("Reflectivity Data", Color.Black, SymbolType.Circle, 5, ReflData.Instance.GetQData, ReflData.Instance.GetReflData);

                        FileInfo info = new FileInfo(settingsfile);

                        if (File.Exists(info.DirectoryName + "\\pop.dat"))
                        {
                            //Create a backup folder if we don't have one
                            if (!System.IO.Directory.Exists(info.DirectoryName + "\\FitBackUp"))
                            {
                                System.IO.Directory.CreateDirectory(info.DirectoryName + "\\FitBackUp");
                            }

                            int index = 0;
                            for (; ;)
                            {
                                if (!System.IO.Directory.Exists(info.DirectoryName + "\\FitBackUp\\Fit" + index.ToString()))
                                {
                                    System.IO.Directory.CreateDirectory(info.DirectoryName + "\\FitBackUp\\Fit" + index.ToString());
                                    break;
                                }
                                index++;
                            }
                            string fileloc = info.DirectoryName + "\\FitBackUp\\Fit" + index.ToString();


                            File.Move(info.DirectoryName + "\\pop.dat", fileloc + "\\pop.dat");
                            File.Move(settingsfile, fileloc + "\\" + info.Name);

                            if (File.Exists(info.DirectoryName + "\\rf.dat"))
                            {
                                File.Move(info.DirectoryName + "\\rf.dat", fileloc + "\\rf.dat");
                            }

                            if (File.Exists(info.DirectoryName + "\\rho.dat"))
                            {
                                File.Move(info.DirectoryName + "\\rho.dat", fileloc + "\\rho.dat");
                            }

                            if (File.Exists(info.DirectoryName + "\\reflfile.dat"))
                            {
                                File.Move(info.DirectoryName + "\\reflfile.dat", fileloc + "\\reflfile.dat");
                            }

                            if (File.Exists(info.DirectoryName + "\\reflrhofit.dat"))
                            {
                                File.Move(info.DirectoryName + "\\reflrhofit.dat", fileloc + "\\reflrhofit.dat");
                            }
                        }
                    }
                }
                else
                {
                    //Load the data file to the graph
                    reflgraphobject.LoadDatawithErrorstoGraph("Reflectivity Data", Color.Black, SymbolType.Circle, 5, ReflData.Instance.GetQData, ReflData.Instance.GetReflData);
                }

                DisableInterface(false);
                Cancelbutton.Enabled = false;
                reflgraphobject.SetBounds();

                SubAbs.Enabled = SupAbsTB.Enabled = SurfAbs.Enabled = UseAbsCB.Checked;
            }
            catch (Exception ex)
            {
                origreflfilename = string.Empty;
                FileNameTB.Clear();
                DisableInterface(true);
                MessageBox.Show(ex.Message);
            }
        }