Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            //fill something in
            if (String.IsNullOrEmpty(tboxFieldName.Text))
            {
                tboxFieldName.Text = "XX";
            }

            //append date time to name
            mf.currentFieldDirectory = tboxFieldName.Text.Trim() +
                                       String.Format("{0}", DateTime.Now.ToString(" MMMdd", CultureInfo.InvariantCulture));
            try
            {
                //get the directory and make sure it exists, create if not
                string dirField = mf.fieldsDirectory + mf.currentFieldDirectory + "\\";

                //make sure directory exists, or create it for first save
                string directoryName = Path.GetDirectoryName(dirField);

                if ((!string.IsNullOrEmpty(directoryName)) && (Directory.Exists(directoryName)))
                {
                    MessageBox.Show("Choose a different name", "Directory Exists", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return;
                }
                else
                {
                    //reset the offsets
                    mf.pn.utmEast  = (int)mf.pn.actualEasting;
                    mf.pn.utmNorth = (int)mf.pn.actualNorthing;

                    mf.worldGrid.CreateWorldGrid(0, 0);

                    //make sure directory exists, or create it
                    if ((!string.IsNullOrEmpty(directoryName)) && (!Directory.Exists(directoryName)))
                    {
                        Directory.CreateDirectory(directoryName);
                    }

                    //create the field file header info
                    mf.FileCreateField();
                    //mf.FileCreateContour();
                    mf.FileSaveFlags();
                    mf.FileSaveABLine();
                }
            }
            catch (Exception ex)
            {
                mf.WriteErrorLog("Creating new field " + ex);

                MessageBox.Show("Error", ex.ToString());
                mf.currentFieldDirectory = "";
            }

            DialogResult = DialogResult.OK;
            Close();
        }
Exemplo n.º 2
0
        //checks the checksum against the string
        public bool ValidateChecksum(string Sentence)
        {
            int sum = 0;

            try
            {
                char[] sentenceChars = Sentence.ToCharArray();
                // All character xor:ed results in the trailing hex checksum
                // The checksum calc starts after '$' and ends before '*'
                int inx;
                for (inx = 1; ; inx++)
                {
                    if (inx >= sentenceChars.Length) // No checksum found
                    {
                        return(false);
                    }
                    var tmp = sentenceChars[inx];
                    // Indicates end of data and start of checksum
                    if (tmp == '*')
                    {
                        break;
                    }
                    sum ^= tmp;    // Build checksum
                }
                // Calculated checksum converted to a 2 digit hex string
                string sumStr = String.Format("{0:X2}", sum);

                // Compare to checksum in sentence
                return(sumStr.Equals(Sentence.Substring(inx + 1, 2)));
            }
            catch (Exception e)
            {
                mf.WriteErrorLog("Validate Checksum" + e);
                return(false);
            }
        }
Exemplo n.º 3
0
        private void FormABLine_Load(object sender, EventArgs e)
        {
            //different start based on AB line already set or not
            if (mf.ABLine.isABLineSet)
            {
                //AB line is on screen and set
                btnAPoint.Enabled    = false;
                btnBPoint.Enabled    = true;
                upDnHeading          = Math.Round(glm.toDegrees(mf.ABLine.abHeading), 1);
                nudTramRepeats.Value = mf.ABLine.tramPassEvery;
                nudBasedOnPass.Value = mf.ABLine.passBasedOn;
                tboxHeading.Text     = upDnHeading.ToString(CultureInfo.InvariantCulture);
            }
            else
            {
                //no AB line
                btnAPoint.Enabled = true;
                btnBPoint.Enabled = false;
                //btnABLineOk.Enabled = false;
                upDnHeading             = Math.Round(glm.toDegrees(mf.fixHeading), 1);
                nudTramRepeats.Value    = 0;
                nudBasedOnPass.Value    = 0;
                mf.ABLine.tramPassEvery = 0;
                mf.ABLine.passBasedOn   = 0;
            }
            //make sure at least a blank AB Line file exists
            string dirABLines    = mf.ablinesDirectory;
            string directoryName = Path.GetDirectoryName(dirABLines).ToString(CultureInfo.InvariantCulture);

            if ((directoryName.Length > 0) && (!Directory.Exists(directoryName)))
            {
                Directory.CreateDirectory(directoryName);
            }
            filename = directoryName + "\\ABLines.txt";
            if (!File.Exists(filename))
            {
                using (StreamWriter writer = new StreamWriter(filename))
                {
                    writer.WriteLine("ABLine N S,0,0,0");
                    writer.WriteLine("ABLine E W,90,0,0");
                }
            }

            //get the file of previous AB Lines
            if ((directoryName.Length > 0) && (!Directory.Exists(directoryName)))
            {
                Directory.CreateDirectory(directoryName);
            }

            filename = directoryName + "\\ABLines.txt";

            if (!File.Exists(filename))
            {
                mf.TimedMessageBox(2000, "File Error", "Missing AB Line File, Critical Error");
            }
            else
            {
                using (StreamReader reader = new StreamReader(filename))
                {
                    try
                    {
                        string       line;
                        ListViewItem itm;

                        //read all the lines
                        while (!reader.EndOfStream)
                        {
                            line = reader.ReadLine();
                            string[] words = line.Split(',');
                            //listboxLines.Items.Add(line);
                            itm = new ListViewItem(words);
                            lvLines.Items.Add(itm);

                            //coords.easting = double.Parse(words[0], CultureInfo.InvariantCulture);
                            //coords.northing = double.Parse(words[1], CultureInfo.InvariantCulture);
                            //youFileList.Add(coords);
                        }
                    }
                    catch (Exception er)
                    {
                        var form = new FormTimedMessage(4000, "ABLine File is Corrupt", "Please delete it!!!");
                        form.Show();
                        mf.WriteErrorLog("FieldOpen, Loading ABLine, Corrupt ABLine File" + er);
                    }
                }

                // go to bottom of list - if there is a bottom
                if (lvLines.Items.Count > 0)
                {
                    lvLines.Items[lvLines.Items.Count - 1].EnsureVisible();
                }
            }
        }