Example #1
0
        private void btnRefresh_Click(object sender, EventArgs e)
        {
            string info = tbInfo.Text.Trim();
            if (String.IsNullOrEmpty(info))
                return;

            if (lvNotices.SelectedItems.Count == 0)//新增
            {

                ListViewItem item = new ListViewItem(info);
                string cdt = GetCondition();
                double dur = Convert.ToDouble(udDur.Value);
                int times = Convert.ToInt32(udTimes.Value);
                Notice n = new Notice(info, cdt, dur, times,cdt.Contains(" "));
                item.Tag = GlobalVar.Helper.FillDataFromObj(_table, n);
                lvNotices.Items.Add(item);
            }
            else
            {
                ListViewItem item = lvNotices.SelectedItems[0];
                item.Text = tbInfo.Text;
                DataRow row = item.Tag as DataRow;
                Notice n = new Notice();
                //GlobalVar.Helper.Row2DbObj(row, n);
                //n.Init();
                string sCdt = GetCondition();
                row.SetField<string>("condition",sCdt);
                row.SetField<bool>("is_temp", sCdt.Contains(" "));
                row.SetField<string>("info", tbInfo.Text);
                row.SetField<double>("dur_times", Convert.ToDouble(udDur.Value));
                row.SetField<int>("times", Convert.ToInt32(udTimes.Value));
            }

            btnOk.Enabled = true;
        }
Example #2
0
 private void btnOk_Click(object sender, EventArgs e)
 {
     Button btn = sender as Button;
     if (btn == null)
         return;
     AbstractIdGengerator gen = new IncreatableIdGengerator("notices");
     GlobalVar.Helper.Update(_table,gen);
     lock (GlobalVar.Instanse.Trigers)
     {
         List<ITrigerable> list = GlobalVar.Instanse.Trigers;
         //去掉原来的通知
         for (int i = 0; i < list.Count; i++)
         {
             ITrigerable t = list[i];
             if (t is Notice)
             {
                 list.Remove(t);
                 i--;
             }
         }
         //加上新的通知
         foreach (ListViewItem item in lvNotices.Items)
         {
             DataRow row = item.Tag as DataRow;
             Notice n = new Notice();
             GlobalVar.Helper.Row2DbObj(row, n);
             GlobalVar.Instanse.Trigers.Add(n);
         }
     }
     //GlobalVar.Instanse.NeedToSaveNotice = true;
     btn.Enabled = false;
 }
Example #3
0
        public bool Init()
        {
            try
            {
                //初始化程序配置数据
                bNeedToSaveCfg = false;
                bIsSetFrmShown = false;
                //sSkinFile = @"skin\PageColor2.ssk";
                //clStyleColor = System.Drawing.SystemColors.Window;

                //初始化通知
                DataSet ds = new DataSet();
                Helper.AddSelect("taskitem", "shortcut,condition,type,fid");
                Helper.AddSelect("notices", "id,info,dur_times,times,condition,is_temp");

                Helper.Fill(ds, "taskitem,notices");

                foreach (DataRow row in ds.Tables["taskitem"].Rows)
                {
                    TaskItem item = new TaskItem();
                    Helper.Row2DbObj(row, item);
                    Trigers.Add(item);
                }
                foreach (DataRow row in ds.Tables["notices"].Rows)
                {
                    Notice item = new Notice();
                    Helper.Row2DbObj(row, item);
                    Trigers.Add(item);
                }

                if (Trigers.Count > 0)
                {
                    TaskThread = new Thread(TaskCallback);
                    //TaskThread.Priority = ThreadPriority.Highest;
                    TaskThread.Start();
                }
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
Example #4
0
        /// <summary>
        /// Reads this instance.
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, ConfigData> Read()
        {
            Dictionary<string, ConfigData> datas = null;
            XmlReader reader = null;
            ConfigData data = null;
            SecurityOpr so = null;
            StringReader sr = null;
            try
            {
                datas = new Dictionary<string, ConfigData>();
                so = new SecurityOpr(m_Key);
                //从加密文件中读取出数据,并进行解密
                string buf = so.ReadFromFile(m_Path);
                if (buf.Equals(String.Empty))
                    return datas;
                //去掉XML文件结尾的一些无效的字符,因为在解密过程中,从内存取出的数据为原始字节,
                //因此字节串的长度应该等于2的指数,否则系统会自动在字节串结尾加空字节
                int pos = buf.LastIndexOf('>');
                if (pos != -1)
                    sr = new StringReader(buf.Substring(0, pos + 1));
                else
                    sr = new StringReader(buf);
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.CheckCharacters = false;
                settings.CloseInput = true;
                reader = XmlReader.Create(sr, settings);
                while (reader.Read())
                {
                    if (reader.Name.Equals("program") && reader.IsStartElement())
                    {
                        data = new ConfigData();
                        if (reader.HasAttributes)
                        {
                            while (reader.MoveToNextAttribute())
                            {
                                Type type = typeof(ConfigData);
                                FieldInfo finfo = type.GetField(reader.Name, BindingFlags.Instance | BindingFlags.NonPublic);

                                if (finfo != null)
                                {
                                    object value = Convert.ChangeType(reader.Value, finfo.FieldType);
                                    finfo.SetValue(data, value);
                                }
                            }
                        }
                    }
                    else if (reader.Name.Equals("path") && reader.IsStartElement())
                    {
                        reader.Read();
                        data.Path = reader.Value.Trim();
                        reader.Read();
                    }
                    else if (reader.Name.Equals("shortcut") && reader.IsStartElement())
                    {
                        reader.Read();
                        data.Shortcut = reader.Value.Trim();
                        reader.Read();
                    }
                    else if ((reader.Name.Equals("notice") || reader.Name.Equals("taskitem"))
                                && reader.IsStartElement())
                    {
                        ITrigerable item;
                        Type type;
                        string name = reader.Name;
                        if (name.Equals("taskitem"))
                        {
                            item = new TaskItem();
                            type = typeof(TaskItem);
                        }
                        else
                        {
                            item = new Notice();
                            type = typeof(Notice);
                        }

                        if (reader.HasAttributes)
                        {
                            while (reader.MoveToNextAttribute())
                            {

                                FieldInfo finfo = type.GetField(reader.Name, BindingFlags.Instance | BindingFlags.NonPublic);

                                if (finfo != null)
                                {
                                    object value = Convert.ChangeType(reader.Value, finfo.FieldType);
                                    finfo.SetValue(item, value);
                                }
                            }
                        }
                        //多一份拷贝,否则在修改运行任务的时候,扫描对象和修改对象为同一个,有可能会造成冲突
                        //虽然冲突没有什么大问题,现在的概率也较小,但这样不太好。
                        //if (name.Equals("taskitem"))
                        //    data.TaskItem = item.Clone() as TaskItem;

                        GlobalVar.Instanse.Trigers.Add(item);
                    }
                    else if (reader.Name.Equals("program") && !reader.IsStartElement())
                    {
                        datas.Add(data.Shortcut, data);
                    }
                }
            }
            catch (FileNotFoundException)
            {

            }
            catch (System.Xml.XmlException)
            {
                GlobalVar.Tip.Error("XML文档格式错误");
            }
            catch (Exception ex)
            {

                GlobalVar.Tip.Error(ex.Message);
            }
            finally
            {
                if (reader != null)
                    reader.Close();
            }

            GlobalVar.Helper.AddInsert("programs", "shortcut,path,is_auto_run,title");
                DataTable dt = new DataTable("programs");
                GlobalVar.Helper.MakeSchemaFromObj(dt, typeof(ConfigData));

                foreach (KeyValuePair<string, ConfigData> pair in datas)
                {

                    ConfigData d = pair.Value;
                    GlobalVar.Helper.FillDataFromObj(dt, d);
                }
                GlobalVar.Helper.Update(dt);
            return datas;
        }
Example #5
0
 object ICloneable.Clone()
 {
     Notice n = new Notice(_Info,_Condition,_DurMin,_Times,_IsTemp);
     return n;
 }
Example #6
0
        private void NoticeMgrFrm_Load(object sender, EventArgs e)
        {
            Init();

            foreach (DataRow row in _table.Rows)
            {
                Notice n = new Notice();
                GlobalVar.Helper.Row2DbObj(row, n);

                ListViewItem i = new ListViewItem(n.Info);
               // i.Text = ;
                i.SubItems.Add(n.Condition);
                i.Tag = row;
                lvNotices.Items.Add(i);
            }
            cbStop.Checked = GlobalVar.Instanse.StopNotice;
        }
Example #7
0
        private void lvNotices_SelectedIndexChanged(object sender, EventArgs e)
        {
            ListView lv = sender as ListView;

            if (lv == null || lv.SelectedItems.Count == 0)
            {
                Clear();
                return;
            }
            ListViewItem item = lv.SelectedItems[0];
            tbInfo.Text = item.Text;
            DataRow row = item.Tag as DataRow;

            if (row == null)
                return;
            Notice n = new Notice();
            GlobalVar.Helper.Row2DbObj(row, n);

            DateTime dt;
            if (DateTime.TryParse(n.Condition, out dt))
            {
                udHour.Value = dt.Hour;
                udMnt.Value = dt.Minute;
                udSec.Value = dt.Second;
                dtpDate.Value = dt;
                cbOneTime.Checked = n.IsTemp;
                udDur.Value = Convert.ToDecimal(n.DurMin);
                udTimes.Value = n.Times;
            }
            cbOneTime_CheckedChanged(null, null);
        }