private void Init() { try { if (ObjectItem == null) { return; } IsSendMethodItemVisiable = ObjectItem.IsChecked == true; ObjectItem.SendMothodViewer = this; mReceiverInfo = ObjectItem.Data as AlarmReceiverInfo; mAlarmItem = ObjectItem.OtherData01 as AlarmInfomationItem; if (mReceiverInfo == null && IsSendMethodItemVisiable) { mReceiverInfo = new AlarmReceiverInfo(); mReceiverInfo.UserID = ObjectItem.ObjID; mReceiverInfo.AlarmInfoID = 0; if (mAlarmItem != null) { mReceiverInfo.AlarmInfoID = mAlarmItem.SerialID; } mReceiverInfo.TenantID = 0; mReceiverInfo.TenantToken = "00000"; mReceiverInfo.Method = 0; mReceiverInfo.ReplyMode = 0; ObjectItem.Data = mReceiverInfo; } } catch (Exception ex) { ShowException(ex.Message); } }
private void Init() { try { if (ObjectItem == null) { return; } var info = ObjectItem.Data as AlarmReceiverInfo; mReceiverInfo = info; InitStatus(); } catch (Exception ex) { ShowException(ex.Message); } }
private OperationReturn GetAlarmReveiverList(SessionInfo session, List <string> listParams) { OperationReturn optReturn = new OperationReturn(); optReturn.Result = true; optReturn.Code = 0; try { //ListParam //0 用户编号 //1 AlarmInfo SerialID(如果为0表示获取所有接收人信息) 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 strAlarmInfoID = listParams[1]; long alarmInfoID; if (!long.TryParse(strAlarmInfoID, out alarmInfoID)) { optReturn.Result = false; optReturn.Code = Defines.RET_PARAM_INVALID; optReturn.Message = string.Format("AlarmInfoID invalid"); return(optReturn); } string strSql; DataSet objDataSet; switch (session.DBType) { case 2: if (alarmInfoID == 0) { strSql = string.Format("SELECT * FROM T_25_008 ORDER BY C001,C002"); } else { strSql = string.Format("SELECT * FROM T_25_008 WHERE C002 = {0} ORDER BY C001,C002", alarmInfoID); } optReturn = MssqlOperation.GetDataSet(session.DBConnectionString, strSql); if (!optReturn.Result) { return(optReturn); } objDataSet = optReturn.Data as DataSet; break; case 3: if (alarmInfoID == 0) { strSql = string.Format("SELECT * FROM T_25_008 ORDER BY C001,C002"); } else { strSql = string.Format("SELECT * FROM T_25_008 WHERE C002 = {0} ORDER BY C001,C002", alarmInfoID); } 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]; AlarmReceiverInfo item = new AlarmReceiverInfo(); item.UserID = Convert.ToInt64(dr["C001"]); item.AlarmInfoID = Convert.ToInt64(dr["C002"]); item.TenantID = Convert.ToInt64(dr["C003"]); item.TenantToken = dr["C004"].ToString(); item.Method = string.IsNullOrEmpty(dr["C005"].ToString()) ? 0 : Convert.ToInt32(dr["C005"]); item.ReplyMode = string.IsNullOrEmpty(dr["C006"].ToString()) ? 0 : Convert.ToInt32(dr["C006"]); 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); }
private OperationReturn SaveAlarmReceiverList(SessionInfo session, List <string> listParams) { OperationReturn optReturn = new OperationReturn(); optReturn.Result = true; optReturn.Code = 0; try { //ListParam //0 用户编码 //1 告警信息编码 //2 告警接收人总数 //3... 告警接收人信息 if (listParams == null || listParams.Count < 3) { 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 strAlarmInfoID = listParams[1]; string strCount = listParams[2]; int intCount; if (!int.TryParse(strCount, out intCount)) { optReturn.Result = false; optReturn.Code = Defines.RET_PARAM_INVALID; optReturn.Message = string.Format("AlarmReceiver count param invalid"); return(optReturn); } if (listParams.Count < intCount + 3) { optReturn.Result = false; optReturn.Code = Defines.RET_PARAM_INVALID; optReturn.Message = string.Format("AlarmReceiver count invalid"); return(optReturn); } List <AlarmReceiverInfo> listInfos = new List <AlarmReceiverInfo>(); for (int i = 0; i < intCount; i++) { optReturn = XMLHelper.DeserializeObject <AlarmReceiverInfo>(listParams[i + 3]); if (!optReturn.Result) { return(optReturn); } AlarmReceiverInfo info = optReturn.Data as AlarmReceiverInfo; if (info == null) { optReturn.Result = false; optReturn.Code = Defines.RET_OBJECT_NULL; optReturn.Message = string.Format("AlarmReceiverInfo is null"); return(optReturn); } listInfos.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_008 WHERE C002 = {0}", strAlarmInfoID); 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_008 WHERE C002 = {0}", strAlarmInfoID); 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 < objDataSet.Tables[0].Rows.Count; i++) { //删除不在列表中的用户 DataRow dr = objDataSet.Tables[0].Rows[i]; long userID = Convert.ToInt64(dr["C001"]); var info = listInfos.FirstOrDefault(a => a.UserID == userID); if (info == null) { dr.Delete(); string strMsg = string.Format("D{0}{1}{0}{2}", ConstValue.SPLITER_CHAR, userID, strAlarmInfoID); listMsg.Add(strMsg); } } for (int i = 0; i < listInfos.Count; i++) { bool isAdd = false; AlarmReceiverInfo info = listInfos[i]; long userID = info.UserID; DataRow dr = objDataSet.Tables[0].Select(string.Format("C001 = {0}", userID)).FirstOrDefault(); //如果不存在此行列,追加上 if (dr == null) { isAdd = true; dr = objDataSet.Tables[0].NewRow(); dr["C001"] = userID; } dr["C002"] = info.AlarmInfoID; dr["C003"] = info.TenantID; dr["C004"] = info.TenantToken; dr["C005"] = info.Method; dr["C006"] = info.ReplyMode; if (isAdd) { objDataSet.Tables[0].Rows.Add(dr); string strMsg = string.Format("A{0}{1}{0}{2}", ConstValue.SPLITER_CHAR, userID, strAlarmInfoID); listMsg.Add(strMsg); } else { string strMsg = string.Format("M{0}{1}{0}{2}", ConstValue.SPLITER_CHAR, userID, strAlarmInfoID); 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); }