Exemplo n.º 1
0
        private List <string> GetAllUserID(SessionInfo session)
        {
            List <string>    AllUserID = new List <string>();
            string           rentToken = session.RentInfo.Token;
            string           strSql;
            IDbConnection    objConn;
            IDbDataAdapter   objAdapter;
            DbCommandBuilder objCmdBuilder;

            switch (session.DBType)
            {
            //MSSQL
            case 2:
                strSql = string.Format("SELECT C001 FROM T_11_005_{0} WHERE C011 = 0 ORDER BY C001"
                                       , rentToken);
                objConn       = MssqlOperation.GetConnection(session.DBConnectionString);
                objAdapter    = MssqlOperation.GetDataAdapter(objConn, strSql);
                objCmdBuilder = MssqlOperation.GetCommandBuilder(objAdapter);
                break;

            case 3:
                strSql = string.Format("SELECT C001 FROM T_11_005_{0} WHERE C011 = 0 ORDER BY C001"
                                       , rentToken);
                objConn       = OracleOperation.GetConnection(session.DBConnectionString);
                objAdapter    = OracleOperation.GetDataAdapter(objConn, strSql);
                objCmdBuilder = OracleOperation.GetCommandBuilder(objAdapter);
                break;

            default:
                return(AllUserID);
            }
            if (objConn == null || objAdapter == null || objCmdBuilder == null)
            {
                return(AllUserID);
            }
            objCmdBuilder.ConflictOption = ConflictOption.OverwriteChanges;
            objCmdBuilder.SetAllValues   = false;
            try
            {
                DataSet objDataSet = new DataSet();
                objAdapter.Fill(objDataSet);
                foreach (DataRow dr in objDataSet.Tables[0].Rows)
                {
                    AllUserID.Add(dr[0].ToString());
                }
            }
            catch (Exception EX)
            {
                return(AllUserID);
            }
            return(AllUserID);
        }
Exemplo n.º 2
0
        private OperationReturn Relation(SessionInfo session, List <string> listParams)
        {
            OperationReturn optReturn = new OperationReturn();

            optReturn.Result = true;
            optReturn.Code   = 0;
            try
            {
                if (listParams.Count < 2)
                {
                    optReturn.Result  = false;
                    optReturn.Code    = Defines.RET_PARAM_INVALID;
                    optReturn.Message = string.Format("Param count invalid");
                    return(optReturn);
                }
                List <string> Users = GetAllUserID(session);
                bool          IsOk  = false;
                if (Users != null)
                {
                    if (Users.Count != 0)
                    {
                        IsOk = true;
                    }
                }
                string strUserID, strResourceID;
                string strST = string.Empty;
                string strET = string.Empty;
                //0     userID
                //1     resourceID

                //2     start time
                //3     end time
                List <string> User = new List <string>();
                User.Add(listParams[0]);
                User.Add(string.Format("102{0}00000000001", session.RentInfo.Token));
                strResourceID = listParams[1];
                if (listParams.Count == 4)
                {
                    strST = listParams[2];
                    strET = listParams[3];
                }
                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_11_201_{0} WHERE C001 = 0 AND C004 = {1}"
                                           , rentToken
                                           , strResourceID);
                    objConn       = MssqlOperation.GetConnection(session.DBConnectionString);
                    objAdapter    = MssqlOperation.GetDataAdapter(objConn, strSql);
                    objCmdBuilder = MssqlOperation.GetCommandBuilder(objAdapter);
                    break;

                //ORCL
                case 3:
                    strSql = string.Format("SELECT * FROM T_11_201_{0} WHERE C001 = 0 AND C004 = {1}"
                                           , rentToken
                                           , strResourceID);
                    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 < User.Count; i++)
                    {
                        strUserID = User[i];
                        //DataRow[] drs = objDataSet.Tables[0].Select(string.Format("C004 = {0}", strResourceID));
                        DataRow[] drs = objDataSet.Tables[0].Select(string.Format("C003={0}", strUserID));
                        //不存在,则插入
                        if (drs.Length <= 0)
                        {
                            if (listParams.Count == 4)
                            {
                                DataRow newRow = objDataSet.Tables[0].NewRow();
                                newRow["C001"] = 0;
                                newRow["C002"] = 0;
                                newRow["C003"] = Convert.ToInt64(strUserID);
                                newRow["C004"] = Convert.ToInt64(strResourceID);
                                newRow["C005"] = Convert.ToDateTime(strST);
                                newRow["C006"] = Convert.ToDateTime(strET);
                                objDataSet.Tables[0].Rows.Add(newRow.ItemArray);

                                listMsg.Add(string.Format("{0}{1}{2}", "A", ConstValue.SPLITER_CHAR, strResourceID));
                            }
                            else
                            {
                                optReturn.Result  = false;
                                optReturn.Code    = Defines.RET_DBACCESS_NOT_EXIST;
                                optReturn.Message = string.Format("Data is not exist");
                            }
                        }
                        else
                        {
                            if (listParams.Count == 2)
                            {
                                //存在,则移除
                                if (drs.Length > 0)
                                {
                                    for (int j = drs.Length - 1; j >= 0; j--)
                                    {
                                        drs[j].Delete();

                                        listMsg.Add(string.Format("{0}{1}{2}", "D", ConstValue.SPLITER_CHAR, strResourceID));
                                    }
                                }
                            }
                            else
                            {
                                optReturn.Result  = false;
                                optReturn.Code    = Defines.RET_DBACCESS_EXIST;
                                optReturn.Message = string.Format("Data is exist");
                            }
                        }
                    }
                    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;
            }
            return(optReturn);
        }