Ejemplo n.º 1
0
        // 添加新列
        public void AddNewRow(CEntitySubCenter entity)
        {
            // 记录超过1000条,或者时间超过1分钟,就将当前的数据写入数据库
            m_mutexDataTable.WaitOne(); //等待互斥量
            DataRow row = m_tableDataAdded.NewRow();

            row[CN_SubCenterName] = entity.SubCenterName;
            row[CN_Comment]       = entity.Comment;
            m_tableDataAdded.Rows.Add(row);
            if (m_tableDataAdded.Rows.Count >= CDBParams.GetInstance().AddBufferMax)
            {
                // 如果超过最大值,写入数据库
                Task task = new Task(() => { AddDataToDB(); });
                task.Start();
            }
            else
            {
                // 没有超过缓存最大值,开启定时器进行检测,多次调用Start()会导致重新计数
                m_addTimer.Start();
            }
            m_mutexDataTable.ReleaseMutex();
        }
Ejemplo n.º 2
0
        private void EHSubCenterChanged(object sender, EventArgs e)
        {
            this.cmbStation.Text = "";
            int selectindex = cmb_SubCenter.SelectedIndex;

            if (0 == selectindex)
            {
                this.cmbStation.m_listBoxStation.Items.Clear();
                // 根据分中心查找测站
                m_listStations     = CDBDataMgr.Instance.GetAllStation();
                m_listSoilStations = CDBSoilDataMgr.Instance.GetAllSoilStation();
                //   m_dgvStatioin.SetSubCenterName(null); //所有分中
                for (int i = 0; i < m_listStations.Count; ++i)
                {
                    this.cmbStation.m_listBoxStation.Items.Add(string.Format("({0,-4}|{1})", m_listStations[i].StationID, m_listStations[i].StationName));
                }
                for (int i = 0; i < m_listSoilStations.Count; ++i)
                {
                    this.cmbStation.m_listBoxStation.Items.Add(string.Format("({0,-4}|{1})", m_listSoilStations[i].StationID, m_listSoilStations[i].StationName));
                }
                //    this.cmbStation.Text = this.cmbStation.m_listBoxStation.Items[0].ToString();
            }
            else
            {
                string subcentername = cmb_SubCenter.Text;
                //  m_dgvStatioin.SetSubCenterName(subcentername);
                //this.panelLeft.Controls.Remove(this.cmbStation);
                //  this.cmbStation = new CStationComboBox();
                // this.cmbStation.SetSubcenter(subcentername);
                this.cmbStation.m_listBoxStation.Items.Clear();

                // 根据分中心查找测站
                //List<CEntityStation> listAllStation = CDBDataMgr.Instance.GetAllStation();
                m_listStations     = CDBDataMgr.Instance.GetAllStation();
                m_listSoilStations = CDBSoilDataMgr.Instance.GetAllSoilStation();
                CEntitySubCenter subcenter = CDBDataMgr.Instance.GetSubCenterByName(subcentername);
                if (null != subcenter)
                {
                    // 如果不为空
                    for (int i = 0; i < m_listStations.Count; ++i)
                    {
                        if (m_listStations[i].SubCenterID == subcenter.SubCenterID)
                        {
                            this.cmbStation.m_listBoxStation.Items.Add(string.Format("({0,-4}|{1})", m_listStations[i].StationID, m_listStations[i].StationName));
                        }
                    }
                    for (int i = 0; i < m_listSoilStations.Count; ++i)
                    {
                        if (m_listSoilStations[i].SubCenterID == subcenter.SubCenterID)
                        {
                            this.cmbStation.m_listBoxStation.Items.Add(string.Format("({0,-4}|{1})", m_listSoilStations[i].StationID, m_listSoilStations[i].StationName));
                        }
                    }
                    //      this.cmbStation.Text = this.cmbStation.m_listBoxStation.Items[0].ToString();
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("分中心 Error");
                }
                //  this.cmbStation.m_listBoxStation.Items.Add(GetDisplayStationName(station));
            }

            //   this.labelUserCount.Text = string.Format("共{0}个站点", m_dgvStatioin.Rows.Count);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 根据分中心站点来加载测站,如果为空,或者NULL,则加载所有分中心
 /// </summary>
 public void SetSubCenterName(string subcenterName)
 {
     try
     {
         if (subcenterName == null || subcenterName.Equals(""))
         {
             // 加载所有的用户分中心
             // List<CEntityStation> listStation = CDBDataMgr.Instance.GetAllStation();
             // 根据分中心查找测站
             List <CEntityStation>     listAllStation     = CDBDataMgr.Instance.GetAllStation();
             List <CEntitySoilStation> listAllSoilStation = CDBSoilDataMgr.Instance.GetAllSoilStation();
             this.SuspendLayout();//暂停VIEW的刷新(datagridview的方法
             this.Hide();
             m_dataTable_1.Clear();
             m_mutexDataTable.WaitOne();
             RefreshGPRSInfo(listAllStation);
             RefreshGPRSInfoSoil(listAllSoilStation);
             this.Show();
             m_mutexDataTable.ReleaseMutex();
             this.ResumeLayout();
         }
         else
         {
             // 根据分中心查找测站
             List <CEntityStation>     listAllStation     = CDBDataMgr.Instance.GetAllStation();
             List <CEntitySoilStation> listAllSoilStation = CDBSoilDataMgr.Instance.GetAllSoilStation();
             CEntitySubCenter          subcenter          = CDBDataMgr.Instance.GetSubCenterByName(subcenterName);
             if (null != subcenter)
             {
                 // 如果不为空
                 List <CEntityStation>     listUseStation   = new List <CEntityStation>();
                 List <CEntitySoilStation> listUseStation_1 = new List <CEntitySoilStation>();
                 for (int i = 0; i < listAllStation.Count; ++i)
                 {
                     if (listAllStation[i].SubCenterID == subcenter.SubCenterID)
                     {
                         listUseStation.Add(listAllStation[i]);
                     }
                 }
                 for (int i = 0; i < listAllSoilStation.Count; ++i)
                 {
                     if (listAllSoilStation[i].SubCenterID == subcenter.SubCenterID)
                     {
                         listUseStation_1.Add(listAllSoilStation[i]);
                     }
                 }
                 this.SuspendLayout();//暂停VIEW的刷新(datagridview的方法
                 this.Hide();
                 this.ClearAllRows();
                 m_dataTable_1.Clear();
                 m_mutexDataTable.WaitOne();
                 RefreshGPRSInfo(listUseStation);
                 RefreshGPRSInfoSoil(listUseStation_1);
                 this.Show();
                 m_mutexDataTable.ReleaseMutex();
                 this.ResumeLayout();
             }
             else
             {
                 System.Diagnostics.Debug.WriteLine("Error");
             }
         }
         this.UpdateDataToUI();
     }
     catch (Exception ex)
     {
         MessageBox.Show("分中心切换有误!" + ex.ToString());
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取所有分中心信息
        /// </summary>
        public List <CEntitySubCenter> QueryAll()
        {
            var result  = new List <CEntitySubCenter>();
            var sqlConn = CDBManager.GetInstacne().GetConnection();

            try
            {
                m_mutexWriteToDB.WaitOne();         // 取对数据库的唯一访问权
                m_mutexDataTable.WaitOne();         // 获取内存表的访问权
                sqlConn.Open();                     // 建立数据库连接

                /**********异步查询数据库**********/
                String sqlStr = GetQueryAllSQL();

                SqlCommand sqlCmd = new SqlCommand(sqlStr, sqlConn);


                SqlDataReader reader = sqlCmd.ExecuteReader();

                Debug.Assert(reader.FieldCount == CN_FIELD_COUNT, CT_TableName + "表与类" + CT_EntityName + "中定义字段不符合");

                //  处理查询结果
                while (reader.Read())
                {
                    try
                    {
                        var item = new CEntitySubCenter();

                        item.SubCenterID = (Int32)reader[CN_SubCenterID];

                        if (reader[CN_SubCenterName] is DBNull)
                        {
                            item.SubCenterName = null;
                        }
                        else
                        {
                            item.SubCenterName = (String)reader[CN_SubCenterName];
                        }

                        if (reader[CN_Comment] is DBNull)
                        {
                            item.Comment = null;
                        }
                        else
                        {
                            item.Comment = (String)reader[CN_Comment];
                        }

                        result.Add(item);
                    }
                    catch
                    {
                    }
                }
            }
            catch (Exception exp)
            {
                throw exp;
            }
            finally
            {
                sqlConn.Close();                    //  关闭数据库连接
                m_mutexDataTable.ReleaseMutex();    //  释放内存表的访问权
                m_mutexWriteToDB.ReleaseMutex();    //  释放数据库的访问权
            }
            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 修改分中心信息
        /// </summary>
        public void Update(CEntitySubCenter entity)
        {
            String sqlStr = GetUpdateSQL(entity);

            ExecuteNonQuery(sqlStr);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 添加分中心
        /// </summary>
        public void Add(CEntitySubCenter entity)
        {
            String sqlStr = GetInsertSQL(entity);

            ExecuteNonQuery(sqlStr);
        }