Exemple #1
0
 private int CalcCell(string Op, int i, int j)
 {
     i++; j++;
     Op = Op.ToUpper();
     Op = Op.Replace("X", i.ToString());
     Op = Op.Replace("Y", j.ToString());
     Op = "(" + Op + ")*1";
     if (!MathsEvaluator.TryParse(Op, out decimal Res))
     {
         throw new Exception("Operation not valid");
     }
     return(Convert.ToInt16(Res - 1));
 }
        private void buttonEnter_Click(object sender, EventArgs e)
        {
            decimal d;

            if (MathsEvaluator.TryParse(textbox1.Text, out d))
            {
                textbox1.Text = d.ToString();
            }
            else
            {
                textbox1.Text = "0";
            }
        }
 void TryAllOper()
 {
     foreach (Role R in Program.Roles)
     {
         if (string.IsNullOrEmpty(R.Column))
         {
             throw new Exception("Empty value not allowed\r\n at Column " + R.Name);
         }
         if (string.IsNullOrEmpty(R.Row))
         {
             throw new Exception("Empty value not allowed\r\n at Row " + R.Name);
         }
         if (!MathsEvaluator.TryParse(((R.Column).Replace("X", "0").Replace("Y", "0")), out decimal tmpTb_SX))
         {
             throw new Exception("Operation not valid " + "(At Role \"" + R.Name + "\"");
         }
         if (!MathsEvaluator.TryParse(((R.Row).Replace("X", "0").Replace("Y", "0")), out decimal tmpTb_SY))
         {
             throw new Exception("Operation not valid " + "(At Role \"" + R.Name + "\"");
         }
     }
 }
Exemple #4
0
        private void NextStepChanged(object sender, EventArgs e)
        {
            dataGridView1.ClearSelection();
            //chk start point
            if (MyExcelLib.Convert.GetColumnIndex2(Tb_SX.Text) < 1)//Start X
            {
                goto Error;
            }
            if (MyExcelLib.Convert.GetRowIndex(Tb_SY.Text) < 1)//start Y
            {
                goto Error;
            }

            for (int i = 0; i < dataGridView1.ColumnCount; i++)
            {
                for (int j = 0; j < dataGridView1.RowCount; j++)
                {
                    dataGridView1.Rows[j].Cells[i].Style = Program.Selectedstyle;
                }
            }

            try
            {
                string tmp;
                string tmpTb_SX = MyExcelLib.Convert.GetColumnIndex2(Tb_SX.Text).ToString();
                string tmpTb_SY = MyExcelLib.Convert.GetRowIndex(Tb_SY.Text).ToString();

                tmp = Tb_N_SX.Text.ToUpper();
                tmp = tmp.Replace("X", tmpTb_SX);
                tmp = tmp.Replace("Y", tmpTb_SY);
                tmp = "(" + tmp + ")*1";
                if (!MathsEvaluator.TryParse(tmp, out decimal N_SX))
                {
                    throw new Exception("Operation not valid");
                }

                tmp = Tb_N_SY.Text.ToUpper();
                tmp = tmp.Replace("X", tmpTb_SX);
                tmp = tmp.Replace("Y", tmpTb_SY);
                tmp = "(" + tmp + ")*1";
                if (!MathsEvaluator.TryParse(tmp, out decimal N_SY))
                {
                    throw new Exception("Operation not valid");
                }

                tmp = Tb_N_NX.Text.ToUpper();
                tmp = tmp.Replace("X", tmpTb_SX);
                tmp = tmp.Replace("Y", tmpTb_SY);
                tmp = "(" + tmp + ")*1";
                if (!MathsEvaluator.TryParse(tmp, out decimal N_NX))
                {
                    throw new Exception("Operation not valid");
                }

                tmp = Tb_N_NY.Text.ToUpper();
                tmp = tmp.Replace("X", tmpTb_SX);
                tmp = tmp.Replace("Y", tmpTb_SY);
                tmp = "(" + tmp + ")*1";
                if (!MathsEvaluator.TryParse(tmp, out decimal N_NY))
                {
                    throw new Exception("Operation not valid");
                }
                //point(A ->tb_SX ,1 ->TB-SY)


                //dataGridView1.Rows[MyExcelLib.Convert.GetRowIndex(Tb_SY.Text) - 1].Cells[MyExcelLib.Convert.GetColumnIndex(Tb_SX.Text) - 1].Style = Startstyle;
                dataGridView1[MyExcelLib.Convert.GetColumnIndex2(Tb_SX.Text) - 1, Convert.ToInt16(Tb_SY.Text) - 1].Style = Program.Startstyle;

                //dataGridView1[Convert.ToInt16(N_SX - 1), MyExcelLib.Convert.GetRowIndex(N_SY.ToString()) - 1].Style = NextSstyle;
                dataGridView1[Convert.ToInt16(N_SX) - 1, Convert.ToInt16(N_SY) - 1].Style = Program.NextSstyle;

                //dataGridView1[Convert.ToInt16(N_NX - 1), MyExcelLib.Convert.GetRowIndex(N_NY.ToString()) - 1].Style = NextNstyle;
                dataGridView1[Convert.ToInt16(N_NX) - 1, Convert.ToInt16(N_NY) - 1].Style = Program.NextNstyle;
                StoreMem();
            }
            catch (Exception ex)
            {
                MessageBox.Show("error at select start point and next of it:\r\n" + ex.Message);
                if (Program.Debug)
                {
                    MessageBox.Show(ex.ToString());
                }
            }

            return;

Error:
            MessageBox.Show("Felld input rong !!", "Error (4)");
        }
        private void StartAndSeletedCells()
        {
            dataGridView2.ClearSelection();
            string tmp;
            string tmpTb_SX = MyExcelLib.Convert.GetColumnIndex2(Program.Mem_SX).ToString();
            string tmpTb_SY = MyExcelLib.Convert.GetRowIndex(Program.Mem_SY).ToString();

            //All
            for (int i = 0; i < dataGridView2.ColumnCount; i++)
            {
                for (int j = 0; j < dataGridView2.RowCount; j++)
                {
                    dataGridView2.Rows[j].Cells[i].Style = Program.Outstyle;
                }
            }
            //selected cells
            for (int j = MyExcelLib.Convert.GetRowIndex(Program.Mem_SY) - 1; j < MyExcelLib.Convert.GetRowIndex(Program.Mem_EY); j++)
            {
                for (int i = MyExcelLib.Convert.GetColumnIndex2(Program.Mem_SX) - 1; i < MyExcelLib.Convert.GetColumnIndex2(Program.Mem_EX); i++)
                {
                    dataGridView2.Rows[j].Cells[i].Style = Program.Selectedstyle;
                }
            }
            try
            {
                tmp = Program.Mem_N_SX.ToUpper();
                tmp = tmp.Replace("X", tmpTb_SX);
                tmp = tmp.Replace("Y", tmpTb_SY);
                tmp = "(" + tmp + ")*1";
                if (!MathsEvaluator.TryParse(tmp, out decimal N_SX))
                {
                    throw new Exception("Operation not valid");
                }

                tmp = Program.Mem_N_SY.ToUpper();
                tmp = tmp.Replace("X", tmpTb_SX);
                tmp = tmp.Replace("Y", tmpTb_SY);
                tmp = "(" + tmp + ")*1";
                if (!MathsEvaluator.TryParse(tmp, out decimal N_SY))
                {
                    throw new Exception("Operation not valid");
                }

                tmp = Program.Mem_N_NX.ToUpper();
                tmp = tmp.Replace("X", tmpTb_SX);
                tmp = tmp.Replace("Y", tmpTb_SY);
                tmp = "(" + tmp + ")*1";
                if (!MathsEvaluator.TryParse(tmp, out decimal N_NX))
                {
                    throw new Exception("Operation not valid");
                }

                tmp = Program.Mem_N_NY.ToUpper();
                tmp = tmp.Replace("X", tmpTb_SX);
                tmp = tmp.Replace("Y", tmpTb_SY);
                tmp = "(" + tmp + ")*1";
                if (!MathsEvaluator.TryParse(tmp, out decimal N_NY))
                {
                    throw new Exception("Operation not valid");
                }

                dataGridView2[MyExcelLib.Convert.GetColumnIndex2(Program.Mem_SX) - 1, Convert.ToInt16(Program.Mem_SY) - 1].Style = Program.Startstyle;

                dataGridView2[Convert.ToInt16(N_SX) - 1, Convert.ToInt16(N_SY) - 1].Style = Program.NextSstyle;

                dataGridView2[Convert.ToInt16(N_NX) - 1, Convert.ToInt16(N_NY) - 1].Style = Program.NextNstyle;
            }
            catch (Exception ex)
            {
                MessageBox.Show("error at select start point and next of it:\r\n" + ex.Message, "Error (2.1)");
                if (Program.Debug)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }