Example #1
0
        private bool Dp_OnChangeTitle(Service.DataParam dataParam, string oldTitle, string newTitle)
        {
            bool error = false;

            if (SparkWindow == null)
            {
                return(false);
            }
            foreach (Service.Input input in InputSettingWindow.inputs)
            {
                if (error == true)
                {
                    break;
                }
                foreach (Service.DataParam param in ((Service.InputCommon)input).ListDataParams)
                {
                    if (param.Title == newTitle)
                    {
                        error = true;
                        break;
                    }
                }
            }
            if (error)
            {
                new Service.MessageView("Имя параметра: " + newTitle + " уже занято!", "Ошибка", Service.MessageViewMode.Error).ShowDialog();
                dataParam.Title = oldTitle;
            }
            return(!error);
        }
Example #2
0
        private void DataGrid_CurrentCellChanged(object sender, System.EventArgs e)
        {
            DataGrid dataGrid = (DataGrid)sender;

            if (dataGrid.CurrentItem != null)
            {
                SelectedParam = (Service.DataParam)((DataGrid)sender).CurrentItem;
            }
        }
Example #3
0
 private void RemoveParam_Click(object sender, RoutedEventArgs e)
 {
     if (SelectedParam == null)
     {
         return;
     }
     ListDataParams.Remove(SelectedParam);
     SelectedParam = null;
 }
Example #4
0
 private void AddParam_Click(object sender, RoutedEventArgs e)
 {
     Service.DataParam addedParam = new Service.DataParam();
     if (new SelectDataParamOutput(SparkWindow.setting.GetListInputParams(), addedParam).ShowDialog() == true)
     {
         Service.DataParamOutput addParam = new Service.DataParamOutput()
         {
             ID             = addedParam.ID,
             Title          = addedParam.Title,
             ParamUnitTitle = addedParam.ParamUnit.Title
         };
         AddParam(ListDataParams.Count, addParam);
     }
 }
Example #5
0
        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBox cb = (ComboBox)sender;

            if (cb.SelectedItem != null)
            {
                Service.DataParam param = (Service.DataParam)cb.DataContext;
                param.ListParamsUnits = ((Service.ParamType)cb.SelectedItem).ListUnits;
                if ((param.ParamUnit == null) && (param.ListParamsUnits.Count > 0))
                {
                    param.ParamUnit = param.ListParamsUnits[0];
                }
            }
        }
Example #6
0
 private void ListBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
 {
     if (lbParams.SelectedItem == null)
     {
         btnOk.IsEnabled = false;
         addedParam      = null;
         return;
     }
     else
     {
         btnOk.IsEnabled      = true;
         addedParam.ID        = ((Service.DataParam)lbParams.SelectedItem).ID;
         addedParam.Title     = ((Service.DataParam)lbParams.SelectedItem).Title;
         addedParam.ParamUnit = new Service.ParamUnit {
             Title = ((Service.DataParam)lbParams.SelectedItem).ParamUnit.Title
         };
     }
 }
Example #7
0
 public void UpdateOutputsReferences()
 {
     foreach (Service.Input output in Outputs)
     {
         for (int i = 0; i < ((Service.InputCommon)output).ListDataParamsOut.Count;)
         {
             Service.DataParam param = GetParamByID(((Service.InputCommon)output).ListDataParamsOut[i].ID);
             if (param == null)
             {
                 ((Service.InputCommon)output).ListDataParamsOut.RemoveAt(i);
             }
             else
             {
                 ((Service.InputCommon)output).ListDataParamsOut[i].Title = param.Title;
                 i++;
             }
         }
     }
 }
Example #8
0
        private void InsertParam_Click(object sender, RoutedEventArgs e)
        {
            if (SelectedParam == null)
            {
                return;
            }
            int index = ListDataParams.IndexOf(SelectedParam);

            Service.DataParam addedParam = new Service.DataParam();
            if (new SelectDataParamOutput(SparkWindow.setting.GetListInputParams(), addedParam).ShowDialog() == true)
            {
                Service.DataParamOutput addParam = new Service.DataParamOutput()
                {
                    ID             = addedParam.ID,
                    Title          = addedParam.Title,
                    ParamUnitTitle = addedParam.ParamUnit.Title
                };
                AddParam(index, addParam);
            }
        }
Example #9
0
        public static Setting Setting(string data, SettingUnits settingUnits)
        {
            Setting setting = new Setting();

            string[] lines     = data.Split('\n');
            int      indexLine = 0;
            int      version   = lines[indexLine] != "" ? Convert.ToInt32(lines[indexLine]) : 0;

            indexLine++;
            int countInput  = Convert.ToInt32(lines[indexLine++]);
            int countOutput = Convert.ToInt32(lines[indexLine++]);
            int countWindow = Convert.ToInt32(lines[indexLine++]);

            setting.Title = lines[indexLine++];
            if (version >= 10509)
            {
                setting.Field = lines[indexLine++];
                setting.Bush  = lines[indexLine++];
                setting.Well  = lines[indexLine++];
            }
            if (version >= 10511)
            {
                setting.NKTmm = Convert.ToInt32(lines[indexLine++]);
            }
            if (version >= 10515)
            {
                setting.LengthPlan = Convert.ToDouble(lines[indexLine++]);
                setting.SpeedPlan  = Convert.ToDouble(lines[indexLine++]);
                setting.WaterPlan  = Convert.ToDouble(lines[indexLine++]);
            }

            #region Input
            for (int i = 0; i < countInput; i++)
            {
                string[] dataInput = lines[indexLine++].Split(new string[] { "#," }, StringSplitOptions.None);

                Service.Input input = (Service.Input)(Activator.CreateInstance("Service", "Service." + dataInput[0]).Unwrap());
                ((Service.InputCommon)input).Title     = dataInput[1];
                ((Service.InputCommon)input).IsUsed    = Convert.ToBoolean(dataInput[2]);
                ((Service.InputCommon)input).InputType = (Service.InputType)Enum.Parse(typeof(Service.InputType), dataInput[3]);
                if (input.GetType() == typeof(Service.InputSerial))
                {
                    ((Service.InputSerial)input).PortName       = dataInput[4];
                    ((Service.InputSerial)input).BaudRate       = Convert.ToInt32(dataInput[5]);
                    ((Service.InputSerial)input).DataBits       = Convert.ToInt32(dataInput[6]);
                    ((Service.InputSerial)input).Parity         = (Parity)Enum.Parse(typeof(Parity), dataInput[7]);
                    ((Service.InputSerial)input).StopBits       = (StopBits)Enum.Parse(typeof(StopBits), dataInput[8]);
                    ((Service.InputSerial)input).Handshake      = (Handshake)Enum.Parse(typeof(Handshake), dataInput[9]);
                    ((Service.InputSerial)input).ReadBufferSize = Convert.ToInt32(dataInput[10]);
                    ((Service.InputSerial)input).ReadTimeout    = Convert.ToInt32(dataInput[11]);
                    ((Service.InputSerial)input).Dtr            = Convert.ToBoolean(dataInput[12]);
                    ((Service.InputSerial)input).Rts            = Convert.ToBoolean(dataInput[13]);
                    ((Service.InputSerial)input).SymbolSplitter = dataInput[14];
                    ((Service.InputCommon)input).IDSlave        = Convert.ToInt32(dataInput[15]);
                }
                else
                {
                    ((Service.InputEthernet)input).IPSlave = dataInput[4];
                    ((Service.InputEthernet)input).Port    = Convert.ToInt32(dataInput[5]);
                    ((Service.InputCommon)input).IDSlave   = Convert.ToInt32(dataInput[6]);
                }
                int countParam = Convert.ToInt32(lines[indexLine++]);
                for (int j = 0; j < countParam; j++)
                {
                    string[]          dataParam = lines[indexLine++].Split(new string[] { "#," }, StringSplitOptions.None);
                    Service.DataParam param     = new Service.DataParam()
                    {
                        ID        = Convert.ToInt32(dataParam[0]),
                        Title     = dataParam[1],
                        ParamType = settingUnits.GetParamTypeByTitle(dataParam[2]),
                        SlaveID   = Convert.ToInt32(dataParam[4]),
                        Address   = Convert.ToDouble(dataParam[5]),
                        Type      = (Service.ModbusType)Enum.Parse(typeof(Service.ModbusType), dataParam[6]),
                        Command   = (Service.ModbusCommandInput)Enum.Parse(typeof(Service.ModbusCommandInput), dataParam[7]),
                        AlarmMin  = Convert.ToSingle(dataParam[8]),
                        AlarmMax  = Convert.ToSingle(dataParam[9]),
                        IsRight   = Convert.ToBoolean(dataParam[10]),
                        ColorLine = new SolidColorBrush((Color)ColorConverter.ConvertFromString(dataParam[11]))
                    };
                    param.ParamUnit = settingUnits.GetUnitByTitle(param.ParamType, dataParam[3]);
                    ((Service.InputCommon)input).ListDataParams.Add(param);
                }
                setting.Inputs.Add(input);
            }
            #endregion

            #region Outputs
            for (int i = 0; i < countOutput; i++)
            {
                string[]      dataInput = lines[indexLine++].Split(new string[] { "#," }, StringSplitOptions.None);
                Service.Input input     = (Service.Input)(Activator.CreateInstance("Service", "Service." + dataInput[0]).Unwrap());
                ((Service.InputCommon)input).Title     = dataInput[1];
                ((Service.InputCommon)input).IsUsed    = Convert.ToBoolean(dataInput[2]);
                ((Service.InputCommon)input).InputType = (Service.InputType)Enum.Parse(typeof(Service.InputType), dataInput[3]);
                if (input.GetType() == typeof(Service.InputSerial))
                {
                    ((Service.InputSerial)input).PortName       = dataInput[4];
                    ((Service.InputSerial)input).BaudRate       = Convert.ToInt32(dataInput[5]);
                    ((Service.InputSerial)input).DataBits       = Convert.ToInt32(dataInput[6]);
                    ((Service.InputSerial)input).Parity         = (Parity)Enum.Parse(typeof(Parity), dataInput[7]);
                    ((Service.InputSerial)input).StopBits       = (StopBits)Enum.Parse(typeof(StopBits), dataInput[8]);
                    ((Service.InputSerial)input).Handshake      = (Handshake)Enum.Parse(typeof(Handshake), dataInput[9]);
                    ((Service.InputSerial)input).ReadBufferSize = Convert.ToInt32(dataInput[10]);
                    ((Service.InputSerial)input).ReadTimeout    = Convert.ToInt32(dataInput[11]);
                    ((Service.InputSerial)input).Dtr            = Convert.ToBoolean(dataInput[12]);
                    ((Service.InputSerial)input).Rts            = Convert.ToBoolean(dataInput[13]);
                    ((Service.InputSerial)input).SymbolSplitter = dataInput[14];
                    ((Service.InputCommon)input).IDSlave        = Convert.ToInt32(dataInput[15]);
                }
                else
                {
                    ((Service.InputEthernet)input).IPSlave = dataInput[4];
                    ((Service.InputEthernet)input).Port    = Convert.ToInt32(dataInput[5]);
                    ((Service.InputCommon)input).IDSlave   = Convert.ToInt32(dataInput[6]);
                }
                int countParam = Convert.ToInt32(lines[indexLine++]);
                for (int j = 0; j < countParam; j++)
                {
                    string[] dataParam            = lines[indexLine++].Split(new string[] { "#," }, StringSplitOptions.None);
                    Service.DataParamOutput param = new Service.DataParamOutput()
                    {
                        ID      = Convert.ToInt32(dataParam[0]),
                        Title   = dataParam[1],
                        Address = Convert.ToDouble(dataParam[2]),
                    };
                    try {
                        param.ParamUnitTitle = dataParam[3];
                    } catch { }

                    ((Service.InputCommon)input).ListDataParamsOut.Add(param);
                }
                setting.Outputs.Add(input);
            }
            #endregion

            #region Windows
            for (int i = 0; i < countWindow; i++)
            {
                SparkControls.WindowIndicators window = new SparkControls.WindowIndicators();
                window.Title = lines[indexLine++];
                int countIndi = Convert.ToInt32(lines[indexLine++]);
                for (int j = 0; j < countIndi; j++)
                {
                    string[] dataIndi            = lines[indexLine++].Split(new string[] { "#," }, StringSplitOptions.None);
                    int      countDataParam      = Convert.ToInt32(dataIndi[0]);
                    SparkControls.Indicator indi = (SparkControls.Indicator)(Activator.CreateInstance("SparkControls", dataIndi[1]).Unwrap());
                    indi.Size     = new System.Windows.Size(Convert.ToDouble(dataIndi[2]), Convert.ToDouble(dataIndi[3]));
                    indi.Location = new System.Windows.Point(Convert.ToDouble(dataIndi[4]), Convert.ToDouble(dataIndi[5]));
                    indi.CountDot = Convert.ToInt32(dataIndi[6]);
                    if (indi.GetType() == typeof(SparkControls.IndiGraph))
                    {
                        ((SparkControls.IndiGraph)indi).GraphSetting.AxisSizeFont   = Convert.ToInt32(dataIndi[7]);
                        ((SparkControls.IndiGraph)indi).GraphSetting.LegendSizeFont = Convert.ToInt32(dataIndi[8]);
                        ((SparkControls.IndiGraph)indi).GraphSetting.LegendVis      = Convert.ToBoolean(dataIndi[9]);
                        ((SparkControls.IndiGraph)indi).GraphSetting.LineWidth      = Convert.ToInt32(dataIndi[10]);
                        ((SparkControls.IndiGraph)indi).GraphSetting.LegendPos      = (OxyPlot.LegendPosition)Enum.Parse(typeof(OxyPlot.LegendPosition), dataIndi[11]);
                        if (dataIndi.Length > 13)
                        {
                            indi.MinValue = Convert.ToDouble(dataIndi[12]);
                            indi.MaxValue = Convert.ToDouble(dataIndi[13]);
                        }
                    }
                    else
                    {
                        if (dataIndi.Length > 8)
                        {
                            indi.MinValue = Convert.ToDouble(dataIndi[7]);
                            indi.MaxValue = Convert.ToDouble(dataIndi[8]);
                        }
                    }
                    if (indi.GetType() == typeof(SparkControls.IndiSendStart))
                    {
                        ((SparkControls.IndiSendStart)indi).Input = setting.GetInputByTitle(dataIndi[9]);
                    }
                    if (indi.GetType() == typeof(SparkControls.IndiSendSoOn))
                    {
                        ((SparkControls.IndiSendSoOn)indi).Input = setting.GetInputByTitle(dataIndi[9]);
                    }
                    if (indi.GetType() == typeof(SparkControls.IndiInputStatus))
                    {
                        ((SparkControls.IndiInputStatus)indi).TimerInterval = Convert.ToInt32(dataIndi[9]);
                        ((SparkControls.IndiInputStatus)indi).Input         = setting.GetInputByTitle(dataIndi[10]);
                    }
                    for (int p = 0; p < countDataParam; p++)
                    {
                        Service.DataParam param = setting.GetParamByID(Convert.ToInt32(lines[indexLine++]));
                        if (param != null)
                        {
                            indi.DataParams.Add(param);
                        }
                    }
                    window.ListIndicators.Add(indi);
                }
                setting.Windows.Add(window);
            }
            #endregion

            return(setting);
        }
Example #10
0
 public SelectDataParamOutput(ObservableCollection <Service.DataParam> dataParams, Service.DataParam addedParam)
 {
     InitializeComponent();
     DataContext     = dataParams;
     this.addedParam = addedParam;
 }