예제 #1
0
 private void openToolStripMenuItem_Click(object sender, EventArgs e)
 {
     toolStripStatusLabel1.Text = "Opening file...";
     try
     {
         openFileDialog1.Filter   = "JSON File|*.json";
         openFileDialog1.Title    = "Open File";
         openFileDialog1.FileName = "";
         DialogResult result = openFileDialog1.ShowDialog();
         if (result == DialogResult.OK)
         {
             fileStream   = new FileStream(openFileDialog1.FileName, FileMode.Open);
             streamReader = new StreamReader(fileStream);
             try
             {
                 string line,
                        json = "";
                 while ((line = streamReader.ReadLine()) != null)
                 {
                     json += line;
                 }
                 Interval[] arr = JsonConvert.DeserializeObject <Interval[]>(json);
                 S = new Series();
                 for (int i = 0; i < arr.Length; i++)
                 {
                     if (arr[i].A.IndexOf(',') == -1 && arr[i].B.IndexOf(',') == -1)
                     {
                         int          a = Convert.ToInt32(arr[i].A);
                         int          b = Convert.ToInt32(arr[i].B);
                         IntegerRange T = new IntegerRange(a, b);
                         S.Add(T.Retu());
                     }
                     else
                     {
                         double    a = Convert.ToDouble(arr[i].A);
                         double    b = Convert.ToDouble(arr[i].B);
                         RealRange T = new RealRange(a, b);
                         S.Add(T.Retu());
                     }
                     UpdLast();
                 }
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             streamReader.Close();
             fileStream.Close();
             toolStripStatusLabel1.Text = "Open file: " + openFileDialog1.FileName;
         }
         else
         {
             toolStripStatusLabel1.Text = "Opening canceled";
         }
     }
     catch (Exception) { }
 }
예제 #2
0
        private void integerFunc(double a, double aa, double b, double bb)
        {
            try
            {
                string sign = comboBox1.Text;
                if (sign == "/")
                {
                    realFunc(a, aa, b, bb);
                    return;
                }
                int a1         = Convert.ToInt32(a),
                    a2         = Convert.ToInt32(aa),
                    b1         = Convert.ToInt32(b),
                    b2         = Convert.ToInt32(bb);
                IntegerRange A = new IntegerRange(a1, a2);
                IntegerRange B = new IntegerRange(b1, b2);
                switch (sign)
                {
                case "+":
                    C = (IntegerRange)A.Add(B);
                    break;

                case "-":
                    C = (IntegerRange)A.Sub(B);
                    break;

                case "*":
                    C = (IntegerRange)A.Mul(B);
                    break;

                case "/":
                    C = (IntegerRange)A.Div(B);
                    break;

                default:
                    C = (IntegerRange)A.Add(B);
                    break;
                }
                string str1 = C.ToString().Split(':')[0].ToString(),
                       str2 = C.ToString().Split(':')[1].ToString();
                textBox6.Text = str1;
                textBox5.Text = str2;
                toolStripStatusLabel1.Text   = "Result:  " + str1 + " ... " + str2;
                addToolStripMenuItem.Enabled = true;
            }
            catch (OverflowException)
            {
                throw;
            }
            catch (FormatException)
            {
                throw;
            }
        }