public int Insert(UniversalWayTypeEntity entity, TerType terType)
 {
     try
     {
         return(dal.Insert(entity, terType));
     }
     catch (Exception ex)
     {
         logger.ErrorException("Insert", ex);
         return(-1);
     }
 }
Esempio n. 2
0
        private void UniversalTreeNodeInfoForm_Load(object sender, EventArgs e)
        {
            if (cbType.Enabled)
            {
                cbType.Focus();
            }
            else
            {
                txtName.Focus();
            }
            cbPrecision.SelectedIndex = 2;

            entity = new UniversalWayTypeEntity();
        }
        public int Insert(UniversalWayTypeEntity entity, TerType terType)
        {
            if (entity == null)
            {
                return(0);
            }

            string SQL = @"INSERT INTO 
                            UniversalTerWayType(ID,Level,ParentID,WayType,Name,FrameWidth,Sequence,MaxMeasureRange,MaxMeasureRangeFlag,Precision,Unit,ModifyTime,TerminalType) VALUES(
                            @ID,@Level,@ParentID,@WayType,@Name,@FrameWidth,@Sequence,@MaxMeasureRange,@MaxMeasureRangeFlag,@Precision,@Unit,@ModifyTime,@terType)";

            SqlParameter[] parms = new SqlParameter[] {
                new SqlParameter("@ID", DbType.Int32),
                new SqlParameter("@Level", DbType.Int32),
                new SqlParameter("@ParentID", DbType.Int32),
                new SqlParameter("@WayType", DbType.Int32),
                new SqlParameter("@Name", DbType.String),

                new SqlParameter("@FrameWidth", DbType.Int32),
                new SqlParameter("@Sequence", DbType.Int32),
                new SqlParameter("@MaxMeasureRange", DbType.Single),
                new SqlParameter("@MaxMeasureRangeFlag", DbType.Single),
                new SqlParameter("@Precision", DbType.Int32),

                new SqlParameter("@Unit", DbType.String),
                new SqlParameter("@ModifyTime", DbType.DateTime),
                new SqlParameter("@terType", DbType.Int32)
            };
            parms[0].Value = entity.ID;
            parms[1].Value = entity.Level;
            parms[2].Value = entity.ParentID;
            parms[3].Value = (int)entity.WayType;
            parms[4].Value = entity.Name;

            parms[5].Value = entity.FrameWidth;
            parms[6].Value = entity.Sequence;
            parms[7].Value = entity.MaxMeasureRange;
            parms[8].Value = entity.ManMeasureRangeFlag;
            parms[9].Value = entity.Precision;

            parms[10].Value = entity.Unit;
            parms[11].Value = entity.ModifyTime;
            parms[12].Value = (int)terType;

            SQLHelper.ExecuteNonQuery(SQL, parms);
            return(1);
        }
        /// <summary>
        /// 获得配置的PointID(不区分ID),id为空时,获取全部
        /// </summary>
        /// <returns></returns>
        public List <UniversalWayTypeEntity> GetConfigPointID(string id, TerType terType)
        {
            string SQL_Point = string.Format(@"SELECT ID,Level,ParentID,WayType,Name,FrameWidth,Sequence,MaxMeasureRange,MaxMeasureRangeFlag,Precision,Unit,ModifyTime 
                                FROM UniversalTerWayType WHERE ID IN (SELECT DISTINCT PointID FROM UniversalTerWayConfig WHERE TerminalType='{0}' {1}) AND TerminalType='{2}' ORDER BY WayType,Sequence",
                                             (int)terType, (string.IsNullOrEmpty(id) ? "" : "AND TerminalID='" + id.Trim() + "'"), (int)terType);
            List <UniversalWayTypeEntity> lst = new List <UniversalWayTypeEntity>();

            using (SqlDataReader reader = SQLHelper.ExecuteReader(SQL_Point, null))
            {
                while (reader.Read())
                {
                    UniversalWayTypeEntity entity = new UniversalWayTypeEntity();

                    entity.ID       = reader["ID"] != DBNull.Value ? Convert.ToInt32(reader["ID"]) : -1;
                    entity.Level    = reader["Level"] != DBNull.Value ? Convert.ToInt32(reader["Level"]) : 0;
                    entity.ParentID = reader["ParentID"] != DBNull.Value ? Convert.ToInt32(reader["ParentID"]) : 0;
                    entity.WayType  = reader["WayType"] != DBNull.Value ? (UniversalCollectType)(Convert.ToInt32(reader["WayType"])) : UniversalCollectType.Simulate;
                    entity.Name     = reader["Name"] != DBNull.Value ? reader["Name"].ToString() : "";

                    entity.FrameWidth          = reader["FrameWidth"] != DBNull.Value ? Convert.ToInt32(reader["FrameWidth"]) : 2;
                    entity.Sequence            = reader["Sequence"] != DBNull.Value ? Convert.ToInt32(reader["Sequence"]) : 1;
                    entity.MaxMeasureRange     = reader["MaxMeasureRange"] != DBNull.Value ? Convert.ToSingle(reader["MaxMeasureRange"]) : 0f;
                    entity.ManMeasureRangeFlag = reader["MaxMeasureRangeFlag"] != DBNull.Value ? Convert.ToSingle(reader["MaxMeasureRangeFlag"]) : 0f;
                    entity.Precision           = reader["Precision"] != DBNull.Value ? Convert.ToInt32(reader["Precision"]) : 2;

                    entity.Unit = reader["Unit"] != DBNull.Value ? reader["Unit"].ToString() : "";
                    //entity.SyncState = reader["SyncState"] != DBNull.Value ? Convert.ToInt32(reader["SyncState"]) : 0;
                    entity.ModifyTime = reader["ModifyTime"] != DBNull.Value ? Convert.ToDateTime(reader["ModifyTime"]) : ConstValue.MinDateTime;

                    lst.Add(entity);
                }
            }
            foreach (UniversalWayTypeEntity entity in lst)
            {
                entity.HaveChild = IDHaveChild(entity.ID.ToString());
            }
            return(lst.Count > 0 ? lst:null);
        }
        public List <UniversalWayTypeEntity> Select(string where)
        {
            string SQL = "SELECT ID,Level,ParentID,WayType,Name,FrameWidth,Sequence,MaxMeasureRange,MaxMeasureRangeFlag,Precision,Unit,ModifyTime FROM UniversalTerWayType ";

            if (!string.IsNullOrEmpty(where))
            {
                SQL += where;
            }
            using (SqlDataReader reader = SQLHelper.ExecuteReader(SQL, null))
            {
                List <UniversalWayTypeEntity> lst = new List <UniversalWayTypeEntity>();
                while (reader.Read())
                {
                    UniversalWayTypeEntity entity = new UniversalWayTypeEntity();

                    entity.ID       = reader["ID"] != DBNull.Value ? Convert.ToInt32(reader["ID"]) : -1;
                    entity.Level    = reader["Level"] != DBNull.Value ? Convert.ToInt32(reader["Level"]) : 0;
                    entity.ParentID = reader["ParentID"] != DBNull.Value ? Convert.ToInt32(reader["ParentID"]) : 0;
                    entity.WayType  = reader["WayType"] != DBNull.Value ? (UniversalCollectType)(Convert.ToInt32(reader["WayType"])) : UniversalCollectType.Simulate;
                    entity.Name     = reader["Name"] != DBNull.Value ? reader["Name"].ToString() : "";

                    entity.FrameWidth          = reader["FrameWidth"] != DBNull.Value ? Convert.ToInt32(reader["FrameWidth"]) : 2;
                    entity.Sequence            = reader["Sequence"] != DBNull.Value ? Convert.ToInt32(reader["Sequence"]) : 1;
                    entity.MaxMeasureRange     = reader["MaxMeasureRange"] != DBNull.Value ? Convert.ToSingle(reader["MaxMeasureRange"]) : 0f;
                    entity.ManMeasureRangeFlag = reader["MaxMeasureRangeFlag"] != DBNull.Value ? Convert.ToSingle(reader["MaxMeasureRangeFlag"]) : 0f;
                    entity.Precision           = reader["Precision"] != DBNull.Value ? Convert.ToInt32(reader["Precision"]) : 2;

                    entity.Unit = reader["Unit"] != DBNull.Value ? reader["Unit"].ToString() : "";
                    //entity.SyncState = reader["SyncState"] != DBNull.Value ? Convert.ToInt32(reader["SyncState"]) : 0;
                    entity.ModifyTime = reader["ModifyTime"] != DBNull.Value ? Convert.ToDateTime(reader["ModifyTime"]) : ConstValue.MinDateTime;

                    lst.Add(entity);
                }
                return(lst);
            }
            return(null);
        }