Exemplo n.º 1
0
 private void CommonPanel_Paint(object sender, PaintEventArgs e)
 {
     try
     {
         e.Graphics.FillRectangle(Brushes.White, 0, 0, CommonPanel.Width, CommonPanel.Height);
         int kx = CommonPanel.Width / 18;
         int ky = CommonPanel.Height / 7;
         for (int i = 0; i < FobidenElements.Items.Count; i++)
         {
             int   x  = kx * 4;
             int   y  = 2 + i * 10;
             Brush br = new SolidBrush(ElementTable.GetColorForType((ElementTypes)i));
             e.Graphics.FillRectangle(br, x - kx, y, kx - 2, 10);
             e.Graphics.DrawString(ElementTable.GetNameOfType((ElementTypes)i), DefaultFont, Brushes.Black, x, y);
         }
         for (int i = 0; i < ElementTable.Elements.Length; i++)
         {
             //SelectionAtomNum[ElementTable.Elements[i].Num] = SelectionTable[i];
             if (ElementTable.Elements[i].Row >= 9)
             {
                 continue;
             }
             int x = kx * (ElementTable.Elements[i].Col - 1);
             int y = ky * (ElementTable.Elements[i].Row - 1);
             SelectionRect[i] = new Rectangle(x, y, kx, ky);
             Brush br;
             Brush tbr;
             if (SelectionTable[i] == false)
             {
                 br  = new SolidBrush(ElementTable.GetColorForType(ElementTable.Elements[i].Type));
                 tbr = Brushes.Black;
             }
             else
             {
                 br  = Brushes.Blue;
                 tbr = Brushes.White;
             }
             if (FobidenElements.GetItemChecked((int)ElementTable.Elements[i].Type))
             {
                 br  = Brushes.White;
                 tbr = Brushes.LightGray;
             }
             e.Graphics.FillRectangle(br, x, y, kx, ky);
             e.Graphics.DrawString(ElementTable.Elements[i].Name, DefaultFont, tbr, x + 2, y + 2);
             if (ElementTable.Elements[i].Name[0] != '*')
             {
                 e.Graphics.DrawString(ElementTable.Elements[i].Num.ToString(), Lf, tbr, x + 1, y + ky / 2);
             }
             e.Graphics.DrawRectangle(Pens.Black, x, y, kx, ky);
         }
     }
     catch (Exception ex)
     {
         Log.OutNoMsg(ex);
     }
 }
Exemplo n.º 2
0
 bool ConvertLine(List <object> line)
 {
     line[0] = ElementTable.FindIndex((string)line[0]);
     line[1] = ElementTable.FindIndex((string)line[1]);
     if ((int)line[1] < 0)
     {
         return(false);
     }
     line[2] = serv.ParseDouble((string)line[2]);
     line[3] = serv.ParseDouble((string)line[3]);
     line[4] = serv.ParseDouble((string)line[4]);
     line[5] = serv.ParseDouble((string)line[5]);
     return(true);
 }
Exemplo n.º 3
0
 private void REPanel_Paint(object sender, PaintEventArgs e)
 {
     try
     {
         e.Graphics.FillRectangle(Brushes.White, 0, 0, REPanel.Width, REPanel.Height);
         int kx = REPanel.Width / 15;
         int ky = REPanel.Height / 2;
         for (int i = 0; i < ElementTable.Elements.Length; i++)
         {
             //SelectionAtomNum[ElementTable.Elements[i].Num] = SelectionTable[i];
             if (ElementTable.Elements[i].Row < 9)
             {
                 continue;
             }
             int x = kx * (ElementTable.Elements[i].Col - 1);
             int y = ky * (ElementTable.Elements[i].Row - 9);
             SelectionRect[i] = new Rectangle(x, y, kx, ky);
             Brush br;
             Brush tbr;
             if (SelectionTable[i] == false)
             {
                 br  = new SolidBrush(ElementTable.GetColorForType(ElementTable.Elements[i].Type));
                 tbr = Brushes.Black;
             }
             else
             {
                 br  = Brushes.Blue;
                 tbr = Brushes.White;
             }
             if (FobidenElements.GetItemChecked((int)ElementTable.Elements[i].Type))
             {
                 br  = Brushes.White;
                 tbr = Brushes.LightGray;
             }
             e.Graphics.FillRectangle(br, x, y, kx, ky);
             e.Graphics.DrawString(ElementTable.Elements[i].Name, DefaultFont, tbr, x + 4, y + 2);
             e.Graphics.DrawString(ElementTable.Elements[i].Num.ToString(), Lf, tbr, x + 1, y + ky / 2);
             e.Graphics.DrawRectangle(Pens.Black, x, y, kx, ky);
         }
     }
     catch (Exception ex)
     {
         Log.OutNoMsg(ex);
     }
 }
Exemplo n.º 4
0
        public bool InitByText(string init_text)
        {
            bool ret = true;

            SrcText = init_text;
            int    i        = 0;
            string error    = "";
            string e_name   = "";
            string sig      = "";
            string val      = "";
            int    st_count = 0;
            string name     = null;

            StLibStandart cur_st = null;

            while (i < init_text.Length)
            {
                string warn = null;
                string line = GetString(init_text, ref i);
                try
                {
                    int comment_index = line.IndexOf("#");
                    if (comment_index >= 0)
                    {
                        line = line.Substring(0, comment_index);
                    }
                    line = line.Trim();
                    if (line.Length == 0)
                    {
                        ResultText += " ";
                    }
                    else
                    {
                        if (line[0] == '-')
                        {
                            st_count++;
                            bool error_found = false;

                            /*for (int t = 0; t < line.Length;t++ )
                             *  if (line[t] != '-')
                             *  {
                             *      error_found = true;
                             *      break;
                             *  }*/
                            name = "";
                            for (int t = 0; t < line.Length; t++)
                            {
                                if (line[t] == '#')
                                {
                                    break;
                                }
                                if (line[t] == '-')
                                {
                                    continue;
                                }
                                name += line[t];
                            }
                            name = name.Trim();
                            if (name.Length == 0)
                            {
                                name = BaseName + st_count;
                            }
                            if (error_found == false)
                            {
                                cur_st = new StLibStandart();
                                St.Add(cur_st);
                                ResultText += Common.MLS.Get(MLSConst, "-Начало стандарта ") + name;
                            }
                            else
                            {
                                ResultText += Common.MLS.Get(MLSConst, "Ошибка!!! В строке начала нового стандарта присутствуют символы отличные от '-'");
                                ret         = false;
                                cur_st      = new StLibStandart();
                                St.Add(cur_st);
                            }
                        }
                        else
                        {
                            if (cur_st == null)
                            {
                                ResultText += Common.MLS.Get(MLSConst, "Ошибка!!! С помощью '-' укажите начало нового стандарта перед заданием концентрации");
                                ret         = false;
                                cur_st      = new StLibStandart();
                                St.Add(cur_st);
                            }
                            string nline = "";
                            int    j     = 0;
                            for (; j < line.Length; j++)
                            {
                                if (char.IsLetterOrDigit(line[j]) ||
                                    line[j] == '.' ||
                                    line[j] == ',' ||
                                    line[j] == '=' ||
                                    line[j] == '~' ||
                                    line[j] == '?')
                                {
                                    nline += line[j];
                                }
                            }
                            e_name = "";
                            sig    = "";
                            val    = "";
                            line   = nline;
                            for (j = 0; j < line.Length; j++)
                            {
                                if (char.IsLetter(line[j]) || line[j] == ' ')
                                {
                                    e_name += line[j];
                                }
                                else
                                {
                                    break;
                                }
                            }
                            bool is_duble = false;
                            int  e_index  = ElementTable.FindIndex(e_name);
                            if (e_index < 0)
                            {
                                ResultText += Common.MLS.Get(MLSConst, "Не существующее имя элемента: ") + e_name;
                                ret         = false;
                                is_duble    = true;
                            }
                            for (int k = 0; k < cur_st.Count; k++)
                            {
                                if (cur_st[k].ElementIndex == e_index)//if (e_name.Equals(cur_st[k].Element))
                                {
                                    ResultText += Common.MLS.Get(MLSConst, "Дубликат элемента: ") + e_name;
                                    ret         = false;
                                    is_duble    = true;
                                    break;
                                }
                            }
                            if (is_duble == false)
                            {
                                if (j < line.Length && (line[j] == '=' || line[j] == '~'))
                                {
                                    sig += line[j];
                                    j++;
                                }
                                for (; j < line.Length; j++)
                                {
                                    if (char.IsDigit(line[j]) || line[j] == '.' ||
                                        line[j] == ',' || line[j] == '?')
                                    {
                                        val += line[j];
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                if (j < line.Length)
                                {
                                    if (line[j] != '#')
                                    {
                                        warn = Common.MLS.Get(MLSConst, "Некорректное завершение строки: ") +
                                               "'" + line.Substring(j) + "'" +
                                               Common.MLS.Get(MLSConst, " Для комментария используйте #.");
                                        ret = false;
                                    }
                                }
                                ResultText += e_name;
                                StLibElement el = new StLibElement();
                                el.StandartName = name;
                                el.ElementIndex = e_index;//e_name;
                                if (sig.Length == 0 ||
                                    val.Length == 0)
                                {
                                    ResultText += Common.MLS.Get(MLSConst, "-основа");
                                    el.IsBase   = true;
                                }
                                else
                                {
                                    if (sig[0] == '=')
                                    {
                                        el.IsAproxim = false;
                                        if (val[0] != '?')
                                        {
                                            el.Con      = serv.ParseDouble(val);
                                            ResultText += " = " + el.Con + Common.MLS.Get(MLSConst, " (точно)");
                                        }
                                        else
                                        {
                                            el.Con      = -1;
                                            ResultText += Common.MLS.Get(MLSConst, " - не регламентируется");
                                        }
                                    }
                                    else
                                    {
                                        el.IsAproxim = true;
                                        if (val[0] != '?')
                                        {
                                            el.Con      = serv.ParseDouble(val);
                                            ResultText += " ~ " + el.Con + Common.MLS.Get(MLSConst, " (приблизительно)");
                                        }
                                        else
                                        {
                                            el.Con      = -1;
                                            ResultText += Common.MLS.Get(MLSConst, " - может присутствовать");
                                        }
                                    }
                                }
                                cur_st.Add(el);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.OutNoMsg(ex);
                    ResultText += Common.MLS.Get(MLSConst, "Ошибка!!! ") + error + ". '" + e_name + "''" + sig + "''" + val + "'";
                    ret         = false;
                }
                if (warn != null)
                {
                    ResultText += Common.MLS.Get(MLSConst, " Предупреждение:") + warn;
                }
                ResultText += ((char)0xD);
                ResultText += ((char)0xA);
            }
            try
            {
                ResultText += Common.MLS.Get(MLSConst, "--------- Конец файла ---------") + serv.Endl;
                ResultText += Common.MLS.Get(MLSConst, "Всего распознано:") + Count + Common.MLS.Get(MLSConst, " стандартов.") + serv.Endl;
                double[] max_cons = null;
                if (Count > 0)
                {
                    max_cons = new double[this[0].Count];
                    for (int mc = 0; mc < max_cons.Length; mc++)
                    {
                        max_cons[mc] = -double.MaxValue;
                    }
                    for (int st = 0; st < Count; st++)
                    {
                        for (i = 0; i < this[st].Count; i++)
                        {
                            try
                            {
                                if (this[st][i].Con > max_cons[i])
                                {
                                    max_cons[i] = this[st][i].Con;
                                }
                            }
                            catch
                            {
                                ResultText += Common.MLS.Get(MLSConst, "Oшибка. В стандарте:") + (st + 1) + " нехватает элементов." + serv.Endl;
                                ret         = false;
                            }
                        }
                    }
                }
                for (int st = 0; st < Count; st++)
                {
                    double sum = 0;
                    double sko = 0;
                    for (i = 0; i < this[st].Count; i++)
                    {
                        if (this[st][i].Con > 0)
                        {
                            sum += this[st][i].Con;
                            double dlt;
                            try
                            {
                                dlt = this[st][i].Con - max_cons[i];
                            }
                            catch (Exception ex)
                            {
                                dlt         = 0;
                                ret         = false;
                                ResultText += Common.MLS.Get(MLSConst, "Ошибка вычисления суммы на стандарте " + (st + 1) + " элемент " + (i + 1));
                            }
                            if (max_cons[i] > 0)
                            {
                                dlt *= 100 / max_cons[i];
                            }
                            else
                            {
                                dlt = 0;
                            }
                            sko += dlt * dlt;
                        }
                    }
                    sko = Math.Sqrt(sko / this[st].Count);
                    if (sum <= 100)
                    {
                        ResultText += Common.MLS.Get(MLSConst, "Сумма концентраций по ") + (st + 1) + Common.MLS.Get(MLSConst, " стандарту ") + Math.Round(sum, 5) + "%";
                    }
                    else
                    {
                        ResultText += Common.MLS.Get(MLSConst, "Предупруждение!!!! Сумма концентраций по ") + (st + 1) + Common.MLS.Get(MLSConst, " стандарту больше 100%: ") + Math.Round(sum, 1) + "%";
                        ret         = false;
                    }
                    ResultText += Common.MLS.Get(MLSConst, " СКО от максимума ") + Math.Round(sko, 1) + "%" + serv.Endl;
                }
            }
            catch (Exception ex)
            {
                ResultText += Common.MLS.Get(MLSConst, "Ошибка вычисления суммы...");
                Log.Out(ex);
            }
            return(ret);
        }