Exemplo n.º 1
0
        /// <summary>
        /// 测试拨号连接
        /// </summary>
        public void Connect(string RasName)
        {
            try
            {
                if (OnHandle != null)
                {
                    OnHandle(string.Format("正在拨号 {0}...", RasName));
                }

                RasDialer dialer = new RasDialer();
                dialer.EntryName   = RasName;
                dialer.PhoneNumber = " ";
                dialer.AllowUseStoredCredentials = true;
                dialer.PhoneBookPath             = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers);
                dialer.Timeout = 1000;
                dialer.Dial();

                Thread.Sleep(100);

                if (OnHandle != null)
                {
                    OnHandle(string.Format("拨号完成"));
                }
            }
            catch (Exception ex)
            {
                LogTextHelper.WriteLine(ex.ToString());
                throw;
            }
        }
Exemplo n.º 2
0
 public virtual bool PrivateUpdate(object id, Hashtable recordField, string targetTable, DbTransaction trans)
 {
     try
     {
         if (recordField == null || recordField.Count < 1)
         {
             return(false);
         }
         string setValue = "";
         foreach (string field in recordField.Keys)
         {
             setValue += string.Format("{0}={1}{2},", GetSafeFileName(field), parameterPrefix, field);
         }
         string    sql     = string.Format("UPDATE {0} SET {1} WHERE {2}={3}{2}", targetTable, setValue.Substring(0, setValue.Length - 1), primaryKey, parameterPrefix);
         Database  db      = CreateDatabase();
         DbCommand command = db.GetSqlStringCommand(sql);
         bool      foundID = false;
         foreach (string field in recordField.Keys)
         {
             object val = recordField[field];
             val = val ?? DBNull.Value;
             if (val is DateTime)
             {
                 if (Convert.ToDateTime(val) <= Convert.ToDateTime("1753-1-1"))
                 {
                     val = DBNull.Value;
                 }
                 db.AddInParameter(command, field, DbType.DateTime, val);
             }
             else
             {
                 db.AddInParameter(command, field, TypeToDbType(val.GetType()), val);
             }
             if (field.Equals(primaryKey, StringComparison.OrdinalIgnoreCase))
             {
                 foundID = true;
             }
         }
         if (!foundID)
         {
             db.AddInParameter(command, primaryKey, TypeToDbType(id.GetType()), id);
         }
         bool result = false;
         if (trans != null)
         {
             result = db.ExecuteNonQuery(command, trans) > 0;
         }
         else
         {
             result = db.ExecuteNonQuery(command) > 0;
         }
         return(result);
     }
     catch (Exception ex)
     {
         LogTextHelper.WriteLine(ex.ToString());
         throw;
     }
 }
Exemplo n.º 3
0
 public static int ExecuteNonQuery(string insert)
 {
     try
     {
         CommandFactory factory = OThinker.H3.Controllers.AppUtility.Engine.EngineConfig.CommandFactory;
         ICommand       command = factory.CreateCommand();
         return(command.ExecuteNonQuery(insert));
     }
     catch (Exception ex)
     {
         LogTextHelper.WriteLine(ex.Message);
         return(-1);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// 设置Alt+S的显示/隐藏窗体全局热键
 /// </summary>
 private void SetHotKey()
 {
     try
     {
         hotKey2.Keys         = Keys.S;
         hotKey2.ModKey       = RegisterHotKeyHelper.MODKEY.MOD_ALT;
         hotKey2.WindowHandle = this.Handle;
         hotKey2.WParam       = 10003;
         hotKey2.HotKey      += new RegisterHotKeyHelper.HotKeyPass(hotKey2_HotKey);
         hotKey2.StarHotKey();
     }
     catch (Exception ex)
     {
         MessageDxUtil.ShowError(ex.Message);
         LogTextHelper.WriteLine(ex.ToString());
     }
 }
Exemplo n.º 5
0
 private void ClockRing(object obj)
 {
     try
     {
         ControledClock clk = obj as ControledClock;
         #region 把要使用的变量都用新的内存保存起来
         DateTime ringTime    = new DateTime();
         string   ID          = "";
         string   taskContent = "";
         int      interval    = 0;
         string   excuteId    = clk.ExcuteId;
         ringTime    = clk.RingTime;
         ID          = clk.ID;
         taskContent = clk.TaskContent;
         interval    = clk.Interval;
         //LogTextHelper.WriteLine("ClockRing:\t" + JsonConvert.SerializeObject(m_RingSet.firstRingClock));
         DateTime dtNow = DateTime.Now;
         #endregion
         //休眠到响铃时间
         Thread.Sleep(ringTime - dtNow);
         //睡醒之后,如果突然发现:咦,你这闹钟变了。因为变了之后是使用另外的线程去响铃了,这线程被抛弃了。停止他
         #region
         if (ringTime != clk.RingTime)
         {
             return;
         }
         #endregion
         #region  如果在响铃之前这闹钟已经被删除或被停止了,那么也没必要往下执行这线程了
         bool bRingClockExist = false;
         foreach (ControledClock temp in listControlClock)
         {
             if (ID == temp.ID)
             {
                 bRingClockExist = true;
                 if (temp.Status == "Stop")   //如果被改成暂停了也没必要往下执行
                 {
                     bRingClockExist = false;
                 }
             }
         }
         if (!bRingClockExist)
         {
             return;
         }
         #endregion
         //其实这里最好要锁住那个响铃闹钟,防止刚好响铃时,那个闹钟被更改
         //开始响铃
         RingClockSet.MciStartRing(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wav\\" + WavToTaskcontent.GetWavfilename(taskContent)));
         //闹钟依据间隔继续使用?
         string tips = string.Format("响铃时间:{0}\n内容:{1}\nID:{2}", ringTime.ToStandardTimeStr(), taskContent, ID);
         #region 继续响铃?
         if (DialogResult.Yes == MessageBox.Show(tips, "继续响铃?", MessageBoxButtons.YesNo))
         {   //修改响铃闹钟集以及控制闹钟列表
             FileHelper.AddControledClockInfoToHistoryFile(clk, "响铃后继续");
             //更新listBoxControledClock,新信息显示在listBox1
             for (int i = 0; i < listControlClock.Count(); i++)
             {
                 if (ID == listControlClock[i].ID)
                 {
                     listControlClock[i].RingTime = ringTime.AddSeconds(interval);   //如果加上了interval,还是小于当前时间,怎么处理??
                     listControlClock[i].Status   = "Start";
                     if (ringTime.AddSeconds(interval) < DateTime.Now.AddSeconds(1)) //给1秒运行时间
                     {
                         MessageBox.Show("抱歉!设置的闹铃时间已过!自动为您停止!");
                         listControlClock[i].Status = "Stop";
                         m_SynContext.Post(SetListBoxSafePost, "");
                         RingClockSet.MciStopRing(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wav\\" + WavToTaskcontent.GetWavfilename(taskContent)));
                     }
                     else
                     {
                         m_SynContext.Post(SetListBoxSafePost, "");
                         RingClockSet.MciStopRing(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wav\\" + WavToTaskcontent.GetWavfilename(taskContent)));
                         //ClockRing(listControlClock[i]);   //这种方式想着不用创建线程更节省内存,但会造成MciRing函数只响上一次未响完的那一段。
                         BeginRingClock(listControlClock[i]);    //线程中重启线程
                     }
                 }
             }
         }
         else
         {
             //从响铃闹钟类中移除闹钟,并设置此闹钟状态为停止
             FileHelper.AddControledClockInfoToHistoryFile(clk, "响铃后不继续");
             //更新listBoxControledClock,新信息显示在listBox1
             for (int i = 0; i < listControlClock.Count(); i++)
             {
                 if (ID == listControlClock[i].ID)
                 {
                     listControlClock[i].Status = "Stop";
                     m_SynContext.Post(SetListBoxSafePost, "");
                     RingClockSet.MciStopRing(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wav\\" + WavToTaskcontent.GetWavfilename(taskContent)));
                 }
             }
         }
         #endregion
     }
     catch (Exception ex)
     {
         LogTextHelper.WriteLine("响铃时出现错误!ERROR:" + ex.ToString());
     }
 }
Exemplo n.º 6
0
        private void RingBeingreadyMciPlay(object threadNum)
        {
            try
            {
                m_SynContext.Post(SetRichTextSafePost, threadNum + "-1");
                Thread.Sleep(4000);
                Thread.CurrentThread.Join();
                WavPlayer.mciPlay(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, string.Format("wav\\第{0}次测试.wav", ((int)threadNum) % 5 + 1).ToString()));
                //SetRichTextSafePost(threadNum);
                //Thread.CurrentThread.Abort();
                #region //继续响铃?
                if (DialogResult.OK == (new FrmSetTime()).ShowDialog())
                {
                    LogTextHelper.WriteLine("DialogResult.OK");
                }
                else
                {
                    LogTextHelper.WriteLine("DialogResult....");
                }
                #endregion
                m_SynContext.Post(SetRichTextSafePost, threadNum + "-2");
                //WavPlayer.mciStop(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, string.Format("wav\\第{0}次测试.wav", ((int)threadNum) % 5 + 1).ToString()));
                return;

                m_SynContext.Post(SetRichTextSafePostByContent, DateTime.Now.ToString() + "开始");
                LogTextHelper.WriteLine("正常执行m_SynContext.Post");
                #region //继续响铃?
                //if (DialogResult.OK == (new FrmSetTime()).ShowDialog())
                //{
                //    LogTextHelper.WriteLine("DialogResult.OK");
                //}
                //else
                //{
                //    LogTextHelper.WriteLine("DialogResult....");
                //}
                #endregion
                //LogTextHelper.WriteLine("在弹窗后执行");
                //Thread.Sleep(20000);
                m_SynContext.Post(SetRichTextSafePostByContent, DateTime.Now + "结束");
                LogTextHelper.WriteLine("休眠后结束");
            }
            catch (ThreadAbortException ex)
            {
                m_SynContext.Post(SetRichTextSafePostByContent, DateTime.Now + "进入Catch ThreadAbortException");
                //RingBeingreadyMciPlay(threadNum);
                Thread.ResetAbort();
            }
            catch (ThreadInterruptedException ex)
            {
                RingBeingreadyMciPlay(threadNum);
            }
            m_SynContext.Post(SetRichTextSafePost, string.Format(threadNum + "---End"));

            return;

            bool reRing = true;
            do
            {
                //WavPlayer.mciPlay(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, string.Format("wav\\{0}.wav", ((int)threadNum) % 6).ToString()));
                //m_SynContext.Post(SetRichTextSafePost, threadNum);
                ////SetRichTextSafePost(threadNum);
                //Thread.Sleep(4000);
                //WavPlayer.mciStop(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, string.Format("wav\\{0}.wav", ((int)threadNum) % 6).ToString()));

                WavPlayer.mciPlay(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, string.Format("wav\\平凡之路.wav").ToString()));
                m_SynContext.Post(SetRichTextSafePost, threadNum);
                //SetRichTextSafePost(threadNum);
                Thread.Sleep(4000);
                //WavPlayer.mciStop(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, string.Format("wav\\平凡之路.wav").ToString()));
            } while (false);
        }