Пример #1
0
        public static AlarmInfomationItem CreateItem(AlarmInfomationInfo info, UMPApp currentApp)
        {
            if (info == null)
            {
                return(null);
            }
            AlarmInfomationItem item = new AlarmInfomationItem();

            item.CurrentApp = currentApp;
            item.SerialID   = info.SerialID;
            item.MessageID  = info.MessageID;
            item.Level      = info.Level;
            item.IsEnabled  = info.IsEnabled;
            item.CreateTime = info.CreateTime;
            item.Name       = info.Name;
            item.Info       = info;

            item.StrIsEnabled = currentApp.GetLanguageInfo(item.IsEnabled ? "2501001" : "2501000",
                                                           item.IsEnabled ? "Enabled" : "Disabled");
            item.StrType =
                currentApp.GetLanguageInfo(string.Format("{0}{1}", S2501Consts.BID_ALARM_TYPE, item.Type.ToString("000")),
                                           item.Type.ToString());
            item.StrLevel =
                currentApp.GetLanguageInfo(string.Format("{0}{1}", S2501Consts.BID_ALARM_LEVEL, item.Level.ToString("000")),
                                           item.Level.ToString());
            item.StrCreateTime = item.CreateTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss");
            return(item);
        }
Пример #2
0
        private OperationReturn GetAlarmInfomationList(SessionInfo session, List <string> listParams)
        {
            OperationReturn optReturn = new OperationReturn();

            optReturn.Result = true;
            optReturn.Code   = 0;
            try
            {
                //ListParam
                //0      用户编号
                if (listParams == null || listParams.Count < 1)
                {
                    optReturn.Result  = false;
                    optReturn.Code    = Defines.RET_PARAM_INVALID;
                    optReturn.Message = string.Format("Request param is null or count invalid");
                    return(optReturn);
                }
                string  strUserID = listParams[0];
                string  strSql;
                DataSet objDataSet;
                switch (session.DBType)
                {
                case 2:
                    strSql    = string.Format("SELECT * FROM T_25_007 ORDER BY C001");
                    optReturn = MssqlOperation.GetDataSet(session.DBConnectionString, strSql);
                    if (!optReturn.Result)
                    {
                        return(optReturn);
                    }
                    objDataSet = optReturn.Data as DataSet;
                    break;

                case 3:
                    strSql    = string.Format("SELECT * FROM T_25_007 ORDER BY C001");
                    optReturn = OracleOperation.GetDataSet(session.DBConnectionString, strSql);
                    if (!optReturn.Result)
                    {
                        return(optReturn);
                    }
                    objDataSet = optReturn.Data as DataSet;
                    break;

                default:
                    optReturn.Result  = false;
                    optReturn.Code    = Defines.RET_PARAM_INVALID;
                    optReturn.Message = string.Format("Database type not surpport.\t{0}", session.DBType);
                    return(optReturn);
                }
                if (objDataSet == null)
                {
                    optReturn.Result  = false;
                    optReturn.Code    = Defines.RET_OBJECT_NULL;
                    optReturn.Message = string.Format("DataSet is null");
                    return(optReturn);
                }
                List <string> listReturn = new List <string>();
                for (int i = 0; i < objDataSet.Tables[0].Rows.Count; i++)
                {
                    DataRow             dr   = objDataSet.Tables[0].Rows[i];
                    AlarmInfomationInfo item = new AlarmInfomationInfo();
                    item.SerialID    = Convert.ToInt64(dr["C001"]);
                    item.MessageID   = Convert.ToInt64(dr["C002"]);
                    item.Level       = Convert.ToInt32(dr["C003"]);
                    item.IsEnabled   = dr["C004"].ToString() == "1";
                    item.Name        = dr["C005"].ToString();
                    item.Description = dr["C006"].ToString();
                    item.CreateTime  = string.IsNullOrEmpty(dr["C007"].ToString())
                        ? DateTime.MinValue
                        : Convert.ToDateTime(dr["C007"]);
                    item.Creator = string.IsNullOrEmpty(dr["C008"].ToString())
                        ? 0
                        : Convert.ToInt64(dr["C008"]);
                    item.LastModifyTime = string.IsNullOrEmpty(dr["C009"].ToString())
                        ? DateTime.MinValue
                        : Convert.ToDateTime(dr["C009"]);
                    item.LastModifyUser = string.IsNullOrEmpty(dr["C010"].ToString())
                        ? 0
                        : Convert.ToInt64(dr["C010"]);
                    optReturn = XMLHelper.SeriallizeObject(item);
                    if (!optReturn.Result)
                    {
                        return(optReturn);
                    }
                    listReturn.Add(optReturn.Data.ToString());
                }
                optReturn.Data = listReturn;
            }
            catch (Exception ex)
            {
                optReturn.Result  = false;
                optReturn.Code    = Defines.RET_FAIL;
                optReturn.Message = ex.Message;
                return(optReturn);
            }
            return(optReturn);
        }
Пример #3
0
        private OperationReturn SaveAlarmInfoList(SessionInfo session, List <string> listParams)
        {
            OperationReturn optReturn = new OperationReturn();

            optReturn.Result = true;
            optReturn.Code   = 0;
            try
            {
                //ListParam
                //0     用户编码
                //1     告警信息总数
                //2...     告警信息
                if (listParams == null || listParams.Count < 2)
                {
                    optReturn.Result  = false;
                    optReturn.Code    = Defines.RET_PARAM_INVALID;
                    optReturn.Message = string.Format("Request param is null or count invalid");
                    return(optReturn);
                }
                string strUserID = listParams[0];
                string strCount  = listParams[1];
                int    intCount;
                if (!int.TryParse(strCount, out intCount))
                {
                    optReturn.Result  = false;
                    optReturn.Code    = Defines.RET_PARAM_INVALID;
                    optReturn.Message = string.Format("AlarmInfo count param invalid");
                    return(optReturn);
                }
                if (listParams.Count < intCount + 2)
                {
                    optReturn.Result  = false;
                    optReturn.Code    = Defines.RET_PARAM_INVALID;
                    optReturn.Message = string.Format("AlarmInfo count invalid");
                    return(optReturn);
                }
                List <AlarmInfomationInfo> listAlarmInfos = new List <AlarmInfomationInfo>();
                for (int i = 0; i < intCount; i++)
                {
                    optReturn = XMLHelper.DeserializeObject <AlarmInfomationInfo>(listParams[i + 2]);
                    if (!optReturn.Result)
                    {
                        return(optReturn);
                    }
                    AlarmInfomationInfo info = optReturn.Data as AlarmInfomationInfo;
                    if (info == null)
                    {
                        optReturn.Result  = false;
                        optReturn.Code    = Defines.RET_OBJECT_NULL;
                        optReturn.Message = string.Format("PropertyValue is null");
                        return(optReturn);
                    }
                    listAlarmInfos.Add(info);
                }
                string           rentToken = session.RentInfo.Token;
                string           strSql;
                IDbConnection    objConn;
                IDbDataAdapter   objAdapter;
                DbCommandBuilder objCmdBuilder;
                switch (session.DBType)
                {
                //MSSQL
                case 2:
                    strSql        = string.Format("SELECT * FROM T_25_007");
                    objConn       = MssqlOperation.GetConnection(session.DBConnectionString);
                    objAdapter    = MssqlOperation.GetDataAdapter(objConn, strSql);
                    objCmdBuilder = MssqlOperation.GetCommandBuilder(objAdapter);
                    break;

                //ORCL
                case 3:
                    strSql        = string.Format("SELECT * FROM T_25_007");
                    objConn       = OracleOperation.GetConnection(session.DBConnectionString);
                    objAdapter    = OracleOperation.GetDataAdapter(objConn, strSql);
                    objCmdBuilder = OracleOperation.GetCommandBuilder(objAdapter);
                    break;

                default:
                    optReturn.Result  = false;
                    optReturn.Code    = Defines.RET_PARAM_INVALID;
                    optReturn.Message = string.Format("Database type not support");
                    return(optReturn);
                }
                if (objConn == null || objAdapter == null || objCmdBuilder == null)
                {
                    optReturn.Result  = false;
                    optReturn.Code    = Defines.RET_OBJECT_NULL;
                    optReturn.Message = string.Format("Db object is null");
                    return(optReturn);
                }
                objCmdBuilder.ConflictOption = ConflictOption.OverwriteChanges;
                objCmdBuilder.SetAllValues   = false;
                try
                {
                    DataSet objDataSet = new DataSet();
                    objAdapter.Fill(objDataSet);
                    List <string> listMsg = new List <string>();
                    for (int i = 0; i < listAlarmInfos.Count; i++)
                    {
                        bool isAdd = false;
                        AlarmInfomationInfo info = listAlarmInfos[i];
                        long    serialID         = info.SerialID;
                        DataRow dr = objDataSet.Tables[0].Select(string.Format("C001 = {0}", serialID)).FirstOrDefault();
                        //如果不存在此行列,追加上
                        if (dr == null)
                        {
                            isAdd      = true;
                            dr         = objDataSet.Tables[0].NewRow();
                            dr["C001"] = serialID;
                        }
                        dr["C002"] = info.MessageID;
                        dr["C003"] = info.Level;
                        dr["C004"] = info.IsEnabled ? "1" : "0";
                        dr["C005"] = info.Name;
                        dr["C006"] = info.Description;
                        dr["C007"] = info.CreateTime;
                        dr["C008"] = info.Creator;
                        dr["C009"] = info.LastModifyTime;
                        dr["C010"] = info.LastModifyUser;
                        if (isAdd)
                        {
                            objDataSet.Tables[0].Rows.Add(dr);
                            string strMsg = string.Format("A{0}{1}", ConstValue.SPLITER_CHAR, serialID);
                            listMsg.Add(strMsg);
                        }
                        else
                        {
                            string strMsg = string.Format("M{0}{1}", ConstValue.SPLITER_CHAR, serialID);
                            listMsg.Add(strMsg);
                        }
                    }
                    objAdapter.Update(objDataSet);
                    objDataSet.AcceptChanges();
                    optReturn.Data = listMsg;
                }
                catch (Exception ex)
                {
                    optReturn.Result  = false;
                    optReturn.Code    = Defines.RET_DBACCESS_FAIL;
                    optReturn.Message = ex.Message;
                }
                finally
                {
                    if (objConn.State == ConnectionState.Open)
                    {
                        objConn.Close();
                    }
                    objConn.Dispose();
                }
            }
            catch (Exception ex)
            {
                optReturn.Result    = false;
                optReturn.Code      = Defines.RET_FAIL;
                optReturn.Message   = ex.Message;
                optReturn.Exception = ex;
            }
            return(optReturn);
        }