Ejemplo n.º 1
0
 private void ConnectTest_Click(object sender, EventArgs e)
 {
     if (DataHelper.Instance.ConnectionTest())
     {
         MessageBox.Show("数据库连接成功!");
         Log4Net.AddLog("数据库连接成功!", InfoLevel.INFO);
     }
     else
     {
         MessageBox.Show("数据库连接失败!");
         Log4Net.AddLog("数据库连接失败!", InfoLevel.FATAL);
     }
 }
Ejemplo n.º 2
0
        public static void AddErrorLog(Exception e)
        {
            string    err = "";
            Exception exp = e;

            while (exp != null)
            {
                err += string.Format("{0}\n ", exp.Message);
                exp  = exp.InnerException;
            }
            err += string.Format("{0}\n ", e.StackTrace);

            Log4Net.AddLog(err, InfoLevel.ERROR);
        }
Ejemplo n.º 3
0
        public int BatchWrite(Dictionary <string, object> tags, bool sync)
        {
            int rs = -1;
            Dictionary <IGroup, SortedDictionary <ITag, object> > dict = new Dictionary <IGroup, SortedDictionary <ITag, object> >();

            foreach (var item in tags)
            {
                var tag = this[item.Key];
                if (tag != null)
                {
                    IGroup grp = tag.Parent;
                    SortedDictionary <ITag, object> values;
                    if (!dict.ContainsKey(grp))
                    {
                        values = new SortedDictionary <ITag, object>();
                        if (tag.Address.VarType != DataType.BOOL && tag.Address.VarType != DataType.STR)
                        {
                            values.Add(tag, tag.ValueToScale(Convert.ToSingle(item.Value)));
                        }
                        else
                        {
                            values.Add(tag, item.Value);
                        }
                        dict.Add(grp, values);
                    }
                    else
                    {
                        values = dict[grp];
                        if (tag.Address.VarType != DataType.BOOL && tag.Address.VarType != DataType.STR)
                        {
                            values.Add(tag, tag.ValueToScale(Convert.ToSingle(item.Value)));
                        }
                        else
                        {
                            values.Add(tag, item.Value);
                        }
                    }
                }
                else
                {
                    Log4Net.AddLog(string.Format("变量{0}不在变量表中,无法下载", item.Key), InfoLevel.ERROR);
                }
            }
            foreach (var dev in dict)
            {
                rs = dev.Key.BatchWrite(dev.Value, sync);
            }
            return(rs);
        }
Ejemplo n.º 4
0
        private void LoadFromCsv()
        {
            if (Clipboard.ContainsText(TextDataFormat.Text))
            {
                List <TagData> dataList = new List <TagData>();
                string         data     = Clipboard.GetText(TextDataFormat.Text);
                if (string.IsNullOrEmpty(data))
                {
                    return;
                }
                list.Clear();
                using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(data)))
                {
                    using (var mysr = new StreamReader(stream))
                    {
                        string strline = "";
                        while ((strline = mysr.ReadLine()) != null)
                        {
                            string[] aryline = strline.Split('\t');
                            try
                            {
                                var     id      = Convert.ToInt16(aryline[0]);
                                var     groupid = Convert.ToInt16(aryline[1]);
                                var     name    = aryline[2];
                                var     address = aryline[3];
                                var     type    = Convert.ToByte(aryline[4]);
                                var     size    = Convert.ToUInt16(aryline[5]);
                                var     active  = Convert.ToBoolean(aryline[6]);
                                var     desp    = aryline[7];
                                TagData tag     = new TagData(id, groupid, name, address, type, size, active, false, false, false, null, desp, 0, 0, 0);
                                list.Add(tag);
                                dataList.Add(tag);
                            }
                            catch (Exception err)
                            {
                                Log4Net.AddLog("LoadFromCsv() " + err.Message, InfoLevel.FATAL);
                                continue;
                            }
                        }
                    }
                }
                list.Sort();

                bindSourceProtocol.DataSource = new SortableBindingList <TagData>(dataList);
                tagCount.Text += dataList.Count.ToString();
            }
        }
Ejemplo n.º 5
0
 //完成从_list<TagMetaData>  ===>   _mapping<string,ITag>里面通过 名字找出 Itag
 public ITag this[string name]
 {
     get
     {
         try
         {
             if (string.IsNullOrEmpty(name))
             {
                 return(null);
             }
             ITag dataItem;
             _mapping.TryGetValue(name.ToUpper(), out dataItem);
             return(dataItem);
         }
         catch (Exception ex)
         {
             Log4Net.AddLog(ex.StackTrace, InfoLevel.ERROR);
             return(null);
         }
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 把异常写入系统日志
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void reader_OnClose(object sender, IOErrorEventArgs e)
 {
     Log4Net.AddLog(e.Reason, InfoLevel.ERROR);
 }
Ejemplo n.º 7
0
 public void AddErrorLog(Exception e)
 {
     Log4Net.AddLog(e.GetExceptionMsg(), InfoLevel.ERROR);
 }