Ejemplo n.º 1
0
 /// <summary>
 /// 以sql语句填充DataSet的第一张表(Table1)
 /// </summary>
 /// <param name="sql"></param>
 /// <returns></returns>
 public static DataSet Query(string sql)
 {
     //锁上oleDbConn,保证每时刻只有一个线程使用oleDbConn。
     lock (oleDbConn)
     {
         OleDbDataAdapter myAdapter = new OleDbDataAdapter(sql, oleDbConn);
         DataSet          ds        = new DataSet();
         try
         {
             myAdapter.Fill(ds, "Table1");
         }
         catch (OleDbException ex)
         {
             MessageHandle.MessageError(ex.ToString(), "错误信息");
         }
         return(ds);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 构造系统运行参数
        /// </summary>
        public static void InitSysParameter()
        {
            ChineseCalendarInfo cClaendar = new ChineseCalendarInfo(DateTime.Today);
            //string strLunar = cClaendar.LunarYear + "-" + cClaendar.LunarMonth + "-" + cClaendar.LunarDay;
            //LUNAR_TODAY = Convert.ToDateTime(strLunar);

            XmlDocument xml      = new XmlDocument();
            string      fileName = Application.StartupPath + "\\Config.xml";

            try
            {
                xml.Load(fileName);
            }
            catch (Exception ex)
            {
                MessageHandle.MessageError(ex.Message, "错误信息");
                Application.Exit();
            }
            XmlNode xmlNode = xml.SelectSingleNode("Root");

            if (xmlNode != null && xmlNode.HasChildNodes)
            {
                XmlNodeList xmlNodeList = xmlNode.ChildNodes;
                if (xmlNodeList.Count == 4)
                {
                    Int32.TryParse(xmlNodeList[0].InnerText.Trim(), out TIMES);
                    Int32.TryParse(xmlNodeList[1].InnerText.Trim(), out MINUTES);
                    DEFAULT_MUSIC_PATH = xmlNodeList[2].InnerText.Trim();
                    bool.TryParse(xmlNodeList[3].InnerText.Trim(), out RUN_BACKGROUND);
                }
            }
            RegistryKey dailyRun = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");

            string[] subkeyNames = dailyRun.GetValueNames();
            foreach (string key in subkeyNames)
            {
                if (key.ToLower() == "daily")
                {
                    RUN_ON_START = true;
                    break;
                }
            }
            BusinessFacade.BusAdminDaily.InitTodayUnDoDaily();
        }
Ejemplo n.º 3
0
 public static bool UpdateDataSet(string sql, DataSet ds)
 {
     lock (oleDbConn)
     {
         oleDbConn.Open();
         OleDbTransaction trans = oleDbConn.BeginTransaction();
         try
         {
             OleDbDataAdapter myAdapter = new OleDbDataAdapter(sql, trans.Connection);
             myAdapter.ContinueUpdateOnError     = false;
             myAdapter.SelectCommand             = new OleDbCommand();
             myAdapter.SelectCommand.Connection  = trans.Connection;
             myAdapter.SelectCommand.CommandText = sql;
             OleDbCommandBuilder builder = new OleDbCommandBuilder();
             builder.DataAdapter    = myAdapter;
             builder.ConflictOption = ConflictOption.OverwriteChanges;
             myAdapter.SelectCommand.Transaction = trans;
             myAdapter.InsertCommand             = builder.GetInsertCommand();
             myAdapter.InsertCommand.Transaction = trans;
             myAdapter.DeleteCommand             = builder.GetDeleteCommand();
             myAdapter.DeleteCommand.Transaction = trans;
             myAdapter.UpdateCommand             = builder.GetUpdateCommand();
             myAdapter.UpdateCommand.Transaction = trans;
             string srcTable = ds.Tables[0].TableName;
             myAdapter.Update(ds, srcTable);
             trans.Commit();
         }
         catch (OleDbException ex)
         {
             trans.Rollback();
             MessageHandle.MessageError(ex.ToString(), "错误信息");
             return(false);
         }
         finally
         {
             oleDbConn.Close();
         }
         return(true);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 执行一个sql语句,返回受影响的行数
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static int ExecuteNonQuery(string sql)
        {
            int count = 0;

            oleDbConn.Open();
            OleDbTransaction trans = oleDbConn.BeginTransaction();

            try
            {
                OleDbCommand myCmd = new OleDbCommand(sql, oleDbConn, trans);
                count = myCmd.ExecuteNonQuery();
                trans.Commit();
            }
            catch (OleDbException ex)
            {
                trans.Rollback();
                MessageHandle.MessageError(ex.ToString(), "错误信息");
            }
            finally
            {
                oleDbConn.Close();
            }
            return(count);
        }