Esempio n. 1
0
 /// <summary>
 /// 类的单例创建函数
 /// </summary>
 /// <returns>创建类的构造函数</returns>
 public static AndonPlayer CreateInstance(string sqlConStr, string andonType, string andonFilePath)
 {
     // 当第一个线程运行到这里时,此时会对locker对象 "加锁",
     // 当第二个线程运行该方法时,首先检测到locker对象为"加锁"状态,该线程就会挂起等待第一个线程解锁
     // lock语句运行完之后(即线程运行完之后)会对该对象"解锁"
     // 双重锁定只需要一句判断就可以了
     if (_andonPlayer == null)
     {
         lock (_locker)
         {
             // 如果类的实例不存在则创建,否则直接返回
             if (_andonPlayer == null)
             {
                 _andonPlayer = new AndonPlayer();
             }
         }
     }
     _andonPlayer.SqlConStr     = sqlConStr;
     _andonPlayer.AndonType     = andonType;
     _andonPlayer.AndonFilePath = andonFilePath;
     return(_andonPlayer);
 }
Esempio n. 2
0
        private void Play()
        {
            StringBuilder andonTypeStr = new StringBuilder();

            andonTypeStr.Append("'");
            if (ckbEqm.Checked)
            {
                andonTypeStr.Append("01','");
            }
            if (ckbPe.Checked)
            {
                andonTypeStr.Append("02','");
            }
            if (ckbProduct.Checked)
            {
                andonTypeStr.Append("03','");
            }
            if (ckbQc.Checked)
            {
                andonTypeStr.Append("04','");
            }
            if (ckbOther.Checked)
            {
                andonTypeStr.Append("05','");
            }
            if (andonTypeStr.Length >= 2)
            {
                andonTypeStr.Remove(andonTypeStr.Length - 2, 2);
            }
            else
            {
                andonTypeStr.Remove(0, andonTypeStr.Length);
                andonTypeStr.Append("''");
            }
            string      path      = Common.ConfigHelper.GetConfigValueFromXml("generalSet", "musicDirectory", AppDomain.CurrentDomain.BaseDirectory + @"Config\mesMusicPlayerConfig.xml");
            AndonPlayer adnPlayer = AndonPlayer.CreateInstance(Common.ConfigHelper.GetConfigValueFromXml("connectionStr", "defaultSqlDb", AppDomain.CurrentDomain.BaseDirectory + @"Config\mesMusicPlayerConfig.xml"), andonTypeStr.ToString(), path);

            adnPlayer.Play(OpenSftwTime, PlayerIndex);
        }