Exemple #1
0
        private void AddRecord(ConfigData data)
        {
            ListViewItem item = new ListViewItem();

            item.Tag = data;
            m_lvRecords.Items.Add(item);
            data.Row = GlobalVar.Helper.FillDataFromObj(_table, data);

            SetValueToItem(data, item);
        }
Exemple #2
0
        private void LoadDatas()
        {
            int iscrWid = 15;//滚动栏宽度
            lvRec.Items.Clear();

            long count = (long)GlobalVar.Helper.ExcuteForUnique<object>("select count(*) from programs");
            if (count >= 10)
            {
                //还未曾改变过
                if (m_Width == this.Width)
                {
                    this.Width += iscrWid;//空出垂直滚动条空间
                    //窗体向左移动垂直滚动条宽度距离
                    this.Left -= iscrWid;
                }
            }
            else
            {
                if (m_Width != this.Width)
                {
                    //恢复原状
                    this.Width -= iscrWid;
                    this.Left += iscrWid;
                }
            }
            bool bChgCol = true;//是否另外着色
            DataTable table = new DataTable("programs");
            GlobalVar.Helper.AddSelect("programs", "id,shortcut,path,title,is_auto_run,has_taskitem");
            GlobalVar.Helper.Fill(ref table);
            foreach (DataRow row in table.Rows)
            {
                ConfigData data = new ConfigData();
                GlobalVar.Helper.Row2DbObj(row, data);
                ListViewItem item = new ListViewItem(data.Title);
                item.SubItems.Add(data.Shortcut);
                item.ToolTipText = data.Path;
                item.Tag = data;
                lvRec.Items.Add(item);
                if (data.HasTaskitem || data.IsAutRun)
                {
                    item.BackColor = Color.Pink;
                }
                else if (bChgCol)
                    item.BackColor = HVH_Ken_Modules.GlobalVar.Instanse.StyleColor;
                bChgCol = !bChgCol;
            }
            lbSum.Text = lvRec.Items.Count.ToString();
        }
Exemple #3
0
 public void Merge(ConfigData data)
 {
     this._isAutRun = data._isAutRun;
     this.Row["is_auto_run"] = _isAutRun;
     this._title = data._title;
     this.Row["title"] = _title;
     this._path = data.Path;
     this.Row["path"] = _path;
     this._shortcut = data.Shortcut;
     this.Row["shortcut"] = _shortcut;
     this._hints = data._hints;
     this.Row["hints"] = data._hints;
 }
Exemple #4
0
        public object Clone()
        {
            ConfigData data = new ConfigData();
            data.IsAutRun = this._isAutRun;
            data.Path = this._path;
            //if(this.item != null)
            //    data.TaskItem = this.item.Clone() as TaskItem;
            data.Shortcut = this._shortcut;
            data.Title = this._title;

            return data;
        }
Exemple #5
0
        /************************************************************************/
        /* return null : 命令不存在; Count==0,用户没有选择
           /************************************************************************/
        public System.Collections.Generic.List<ConfigData> FindCommand(string shortcut)
        {
            GlobalVar.Helper.AddSelect("programs", "id,shortcut,path,title,is_auto_run,hints","shortcut");
            GlobalVar.Helper.AddCustomParam("shortcut", shortcut);
            DataTable table = new DataTable("programs");
            System.Collections.Generic.List<ConfigData> list = new System.Collections.Generic.List<ConfigData>();
            GlobalVar.Helper.Fill(ref table);
            if (table.Rows.Count == 0)
                return null;

            foreach (DataRow row in table.Rows)
            {
                ConfigData cd = new ConfigData();
                cd.Row = row;
                GlobalVar.Helper.Row2DbObj(row, cd);
                list.Add(cd);
            }
            if(list.Count > 1)
            {
                SelectFrm frm = new SelectFrm(list);
                if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    frm.UpdateSelectedHint();
                }
                else
                {
                    list.Clear();
                    return list;
                }

                //进行选择
            }
            else
            {
                DataRow row = list[0].Row;
                int hint = row.Field<int>("hints");
                row.SetField<int>("hints", ++hint);
            }
            Helper.AddUpdate("programs", "hints", "id");
            Helper.Update(table);
            return list;
        }
Exemple #6
0
        private void SetValueToItem(ConfigData data, ListViewItem item)
        {
            Type type = typeof(ConfigData);
            string[] fs = m_fields.Split(',');
            int i = 0;
            string value;
            item.SubItems.Clear();

            foreach (string f in fs)
            {
                FieldInfo fi;
                fi = type.GetField(f, BindingFlags.NonPublic | BindingFlags.Instance);
                if (fi == null)
                    continue;
                value = fi.GetValue(data).ToString();
                if (i != 0)
                    item.SubItems.Add(value);
                else
                    item.Text = value;
                i++;
            }

            ((ConfigData)item.Tag).IsAutRun = data.IsAutRun;
            if (data.HasTaskitem)
            {
                  lbTaskSum.Text = (Convert.ToInt32(lbTaskSum.Text) + 1).ToString();
                //((ConfigData)item.Tag).TaskItem = data.TaskItem;
            }
            else if (data.IsAutRun == true)
            {
                lbAutoRun.Text = (Convert.ToInt32(lbAutoRun.Text) + 1).ToString();
            }
        }
Exemple #7
0
        /// <summary>
        /// 根据缓存数据更新列表.
        /// </summary>
        /// <param name="buf">The buf.</param>
        private void RefreshList()
        {
            int iAutoRun = 0;
            int iTask = 0;
            m_lvRecords.SuspendLayout();

            foreach (DataRow row in _table.Rows)
            {
                ConfigData data = new ConfigData();;
                GlobalVar.Helper.Row2DbObj(row, data);
                data.Row = row;
                ListViewItem item = new ListViewItem(data.Title);
                item.SubItems.Add(data.Path);
                item.SubItems.Add(data.Shortcut);
                item.SubItems.Add(data.Hints.ToString());
                //item.SubItems.Add(data.IsAutRun);
                item.ToolTipText = data.Path;

                if (data.HasTaskitem)
                {
                    iTask++;
                }else if (data.IsAutRun == true)
                {
                    iAutoRun++;
                }

                item.Tag = data;
                m_lvRecords.Items.Add(item);
            }
            lbAutoRun.Text = iAutoRun.ToString();
            lbTaskSum.Text = iTask.ToString();
            lbSum.Text = m_lvRecords.Items.Count.ToString();

            m_lvRecords.ResumeLayout();
        }
Exemple #8
0
 private ConfigData GetValueFromItem(ListViewItem item)
 {
     ConfigData data = new ConfigData();
     Type type = typeof(ConfigData);
     string[] fs = m_fields.Split(',');
     int i = 0;
     foreach (string f in fs)
     {
         FieldInfo fi;
         fi = type.GetField(f, BindingFlags.NonPublic | BindingFlags.Instance);
         if (fi == null)
             continue;
         fi.SetValue(data, item.SubItems[i++].Text);
     }
     ConfigData newinfo = item.Tag as ConfigData;
     if (newinfo != null)
     {
         //data.TaskItem = newinfo.TaskItem;
         data.IsAutRun = newinfo.IsAutRun;
     }
     return data;
 }
Exemple #9
0
 /// </summary>
 /// <param name="data">The data.</param>
 private void ColNewDat(ConfigData data)
 {
     data.Title = tbTitle.Text;
     data.Path = tbPath.Text;
     data.Row = _table.NewRow();
     //去掉左右和中间的空格,并且所有的命令都为小写格式
     data.Shortcut = tbSct.Text.Replace(" ", null).ToLower();
     data.IsAutRun = cbAutRun.Checked;
     //einfo.IsAutoRun = data.IsAutRun;
     if (m_lvRecords.SelectedItems.Count == 1)
     {
         ConfigData einfo = m_lvRecords.SelectedItems[0].Tag as ConfigData;
         //data.TaskItem = einfo.TaskItem;
     }
 }
Exemple #10
0
        /// <summary>
        /// 修改记录.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnMod_Click(object sender, EventArgs e)
        {
            //列表有记录被选中时,修改键才有效,但在修改模式下按下,需要判断
            if (m_lvRecords.SelectedItems.Count == 0)
                return;
            ConfigData data = new ConfigData();

            ColNewDat(data);
            //检查快捷名
            if (CheckShortcut(data.Shortcut, GlobalVar.ActionType.Modify)
                )
            {
                ListViewItem item = m_lvRecords.SelectedItems[0];
                ((ConfigData)item.Tag).Merge(data);
                SetValueToItem(data, item);

                btnSave.Enabled = true;
            }
        }
Exemple #11
0
        /// <summary>
        /// 添加记录.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (tbPath.Text.Trim().Equals(""))
            {
                toolTip.Show("路径不能为空", tbPath);
                return;
            }
            ConfigData data = new ConfigData();
            ColNewDat(data);

            //检查快捷名
            if (CheckShortcut(data.Shortcut, GlobalVar.ActionType.Add))
            {
                AddRecord(data);
                ClearData();
                btnSave.Enabled = true;
                lbSum.Text = m_lvRecords.Items.Count.ToString();
            }
        }
        /// <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;
        }
Exemple #13
0
        /// <summary>
        /// 命令解析执行线程方法.
        /// </summary>
        /// <param name="obj">命令对象.</param>
        private static void StartFindThread(object obj)
        {
            CommanderData cmdObj = obj as CommanderData;
            bool bParsed = false;//命令被解析标志
            if (cmdObj == null)
                return;

            try
            {
                if (cmdObj.IsRunDirectly == true)
                {
                    //运行时用ParsedCmd
                    cmdObj.ParsedCmd = cmdObj.Cmd;
                    ProgExecuter.Execute(cmdObj);
                }
                else
                {
                    ////大多数情况下都没有空格,如果含有空格,说明可能有参数,该判断为提高性能用
                    //int iPos = cmdObj.Cmd.IndexOf(" ");
                    //if (iPos != -1)
                    //{
                    //    //解析输入命令、参数
                    //    ParseCommand(cmdObj.Cmd, cmdObj);
                    //    //有空格且为完整路径直接执行程序,Cmd无用;如果为快捷命令,则进行提取
                    //    cmdObj.Cmd = cmdObj.ParsedCmd.Substring(0, iPos);
                    //    cmdObj.Description = cmdObj.Cmd;

                    //    bParsed = true;
                    //}
                    //查找程序
                    System.Collections.Generic.List<ConfigData> datas = GlobalVar.Instanse.FindCommand(cmdObj.Cmd);

                    if(datas == null)
                    {
                        datas = new System.Collections.Generic.List<ConfigData>();
                        ConfigData data = new ConfigData();
                        data.Path = cmdObj.Cmd;
                        data.Title = cmdObj.Description;
                        data.Shortcut = cmdObj.Cmd;
                        datas.Add(data);
                    }
                    else if (datas.Count == 0)
                    {
                        return;
                    }
                    foreach(ConfigData data in datas)
                    {
                        //如果上面已经调用过,还需要将data.Path中的参数解析出来
                        ParseCommand(data.Path, cmdObj);
                        //bParsed = true;
                        cmdObj.Description = data.Title;

                    //if (bParsed == false)
                    //{
                    //    //解析输入命令、参数
                    //    ParseCommand(cmdObj.Cmd, cmdObj);
                    //}
                    //这里的判断有待改进
                    if (cmdObj.ParsedCmd != string.Empty &&
                        cmdObj.ParsedCmd[0] == INNERSTART &&
                        cmdObj.ParsedCmd[cmdObj.ParsedCmd.Length - 1] == INNEREND)
                    {
                        string sExtCmd = ParseExtCmd(cmdObj.ParsedCmd);
                        ProgExecuter.ExecExtCmd(sExtCmd, cmdObj);
                    }
                    else
                        ProgExecuter.Execute(cmdObj);
                    }
                }
            }
            catch
                (ExtCommandLineBrokenException)
            { }
            catch (Exception ex)
            {
                ErrorInfo ei = new ErrorInfo(cmdObj.Cmd, ex.Message);
                GlobalVar.PushErrorInfo(ei);
                GlobalVar.Instanse.MainVisitor.Visit(ex.Message);
            }
        }