Ejemplo n.º 1
0
        public void CreateThread(string threadname, int seconds, string pythonscripts)
        {
            if (_threadDictionary.Keys.Contains(threadname))
            {
                throw new Exception("线程[" + threadname + "]已经存在!禁止重复创建。");
            }

            ParameterManager pm = new ParameterManager();

            pm.Add("threadname", threadname);
            pm.Add("pythonscripts", pythonscripts);
            pm.Add("seconds", seconds);

            //System.Threading.Thread thread = new Thread(new ParameterizedThreadStart(EnableButton));
            //thread.Start(null);

            System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(ThreadRunning));
            thread.IsBackground = true;
            thread.Name         = threadname;
            thread.Start(pm);//线程开始。。。

            //
            _threadDictionary.Add(threadname, thread);
            _threadStopFlagDictionary.Add(threadname, true);
        }
Ejemplo n.º 2
0
        private void ThreadRunning(object pm)
        {
            if (!(pm is ParameterManager))
            {
                return;
            }



            try
            {
                ParameterManager parameterManager = (ParameterManager)pm;
                int    seconds    = (int)parameterManager.Get("seconds");
                string threadname = parameterManager.Get("threadname").ToString();

                if (seconds == -1)
                {
                    //只执行一次;
                    //执行脚本;
                    this.ExecScript(parameterManager.Get("pythonscripts").ToString());
                }
                else
                {
                    //获取
                    while (_threadStopFlagDictionary[threadname])
                    {
                        //如果数据库网络连接中断;不执行;
                        //if (Common.DBHelper.SqlConn.bConnIsAceess)
                        {
                            //执行脚本;
                            this.ExecScript(parameterManager.Get("pythonscripts").ToString());
                        }
                        //间隔;
                        System.Threading.Thread.Sleep(seconds * 1000);
                    }
                }
            }
            catch (Exception exp)
            {
                //AddLogValue("错误:" + exp.Message);
            }
        }
Ejemplo n.º 3
0
        public void SetParameterValue(string key, object value)
        {
            if (this._pageParamterManager == null)
            {
                this._pageParamterManager = new ParameterManager();
            }


            if (this._pageParamterManager._dic.ContainsKey(key))
            {
                Parameter p = _pageParamterManager._dic[key];
                //= value.ToString();
                p.value = value;
            }
            else
            {
                //
                this._pageParamterManager.Add(key, value);
            }
        }
Ejemplo n.º 4
0
        public DataTable SQLGetDataTable(string connstring, string sqltxt, ParameterManager pars)
        {
            try
            {
                List <SqlParameter> sqlPars = new List <SqlParameter>();
                foreach (KeyValuePair <string, Parameter> kv in pars._dic)
                {
                    sqlPars.Add(new SqlParameter("@" + kv.Value.parname, kv.Value.value.ToString()));
                }

                return(EohiDataCenter.Helper.SqlCmdExec.getDataTable(
                           connstring,
                           sqltxt,
                           sqlPars.ToArray()));
            }
            catch (SqlException exp)
            {
                Common.Util.NocsMessageBox.Message(exp.Message);
                //throw;
            }
            return(null);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 执行语句,返回受影响的行数;
        /// select 行数不返回;
        /// </summary>
        /// <param name="sqltxt"></param>
        /// <param name="pars"></param>
        /// <returns></returns>
        public int SQLExecuteNonQuery(string connstring, string sqltxt, ParameterManager pars)
        {
            try
            {
                List <SqlParameter> sqlPars = new List <SqlParameter>();
                foreach (KeyValuePair <string, Parameter> kv in pars._dic)
                {
                    sqlPars.Add(new SqlParameter("@" + kv.Value.parname, kv.Value.value.ToString()));
                }
                var abc = EohiDataCenter.Helper.SqlCmdExec.ExecuteNonQuery(
                    connstring,
                    sqltxt,
                    sqlPars.ToArray());
                return(abc);
            }
            catch (SqlException exp)
            {
                Common.Util.NocsMessageBox.Message(exp.Message);
                //throw;
            }

            return(-1);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 返回第一行第一列的值,如果无返回值,则返回-1;
        /// </summary>
        /// <param name="sqltxt"></param>
        /// <param name="pars"></param>
        /// <returns></returns>
        public object SQLExecuteScalar(string connstring, string sqltxt, ParameterManager pars)
        {
            try
            {
                List <SqlParameter> sqlPars = new List <SqlParameter>();
                foreach (KeyValuePair <string, Parameter> kv in pars._dic)
                {
                    sqlPars.Add(new SqlParameter("@" + kv.Value.parname, kv.Value.value.ToString()));
                }

                object obj = Helper.SqlCmdExec.ExecuteScalar(
                    connstring,
                    sqltxt,
                    sqlPars.ToArray());

                return(obj);
            }
            catch (SqlException exp)
            {
                Common.Util.NocsMessageBox.Message(exp.Message);
                //throw;
            }
            return(null);
        }
Ejemplo n.º 7
0
        public ParameterManager NewPars()
        {
            ParameterManager pm = new ParameterManager();

            return(pm);
        }