Esempio n. 1
0
        private OperationReturn ModifyOrgInfo(SessionInfo session, List <string> listParams)
        {
            OperationReturn optReturn = new OperationReturn();

            optReturn.Result = true;
            optReturn.Code   = 0;
            try
            {
                if (listParams.Count != 6)
                {
                    optReturn.Result  = false;
                    optReturn.Code    = Defines.RET_PARAM_INVALID;
                    optReturn.Message = string.Format("Param count invalid");
                    return(optReturn);
                }
                //0     OrgID
                //1     OrgName
                //2     OrgType
                //3     OrgDesc
                //4     IsActive
                //5     ObjParentID
                string orgID       = listParams[0];
                string orgName     = EncryptToDB(listParams[1]);
                string orgType     = listParams[2];
                string orgDesc     = listParams[3];
                string IsActive    = listParams[4];
                string rentToken   = session.RentInfo.Token;
                string orgParentId = listParams[5];
                string strSql;
                //判断同级父机构下是否有同名的机构
                IDbConnection  objConn    = null;
                IDbDataAdapter objAdapter = null;
                DataSet        objDataSet = new DataSet();
                switch (session.DBType)
                {
                //MSSQL
                case 2:
                    strSql = string.Format("SELECT  * FROM T_11_006_{0} WHERE  C002='{1}' AND C004='{2}' AND  C001<>{3} ",
                                           rentToken,
                                           orgName,
                                           orgParentId,
                                           orgID);
                    objConn    = MssqlOperation.GetConnection(session.DBConnectionString);
                    objAdapter = MssqlOperation.GetDataAdapter(objConn, strSql);
                    break;

                //ORCL
                case 3:
                    strSql = string.Format("SELECT  * FROM T_11_006_{0} WHERE  C002='{1}' AND C004='{2}' AND  C001 <>{3} ",
                                           rentToken,
                                           orgName,
                                           orgParentId,
                                           orgID);
                    objConn    = OracleOperation.GetConnection(session.DBConnectionString);
                    objAdapter = OracleOperation.GetDataAdapter(objConn, strSql);
                    break;
                }
                if (objConn == null ||
                    objAdapter == null)
                {
                    optReturn.Result  = false;
                    optReturn.Code    = Defines.RET_OBJECT_NULL;
                    optReturn.Message = string.Format("DBConnection or DBDataAdapter is null");
                    return(optReturn);
                }
                objAdapter.Fill(objDataSet);
                if (objDataSet != null && objDataSet.Tables[0].Rows.Count > 0)
                {
                    //同名机构名称
                    optReturn.Result  = false;
                    optReturn.Code    = Defines.RET_DBACCESS_EXIST;
                    optReturn.Message = string.Format("EXIST");
                    return(optReturn);
                }

                switch (session.DBType)
                {
                //MSSQL
                case 2:
                    strSql =
                        string.Format(
                            "UPDATE T_11_006_{0} SET C002 = '{1}', C003 = {2}, C012 = '{3}',C005='{5}' WHERE C001 = {4}",
                            rentToken,
                            orgName,
                            orgType,
                            orgDesc,
                            orgID,
                            IsActive);
                    optReturn = MssqlOperation.ExecuteSql(session.DBConnectionString, strSql);
                    if (!optReturn.Result)
                    {
                        return(optReturn);
                    }
                    break;

                //ORCL
                case 3:
                    strSql =
                        string.Format(
                            "UPDATE T_11_006_{0} SET C002 = '{1}', C003 = {2}, C012 = '{3}' ,C005='{5}'  WHERE C001 = {4}",
                            rentToken,
                            orgName,
                            orgType,
                            orgDesc,
                            orgID,
                            IsActive
                            );
                    optReturn = OracleOperation.ExecuteSql(session.DBConnectionString, strSql);
                    if (!optReturn.Result)
                    {
                        return(optReturn);
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                optReturn.Result  = false;
                optReturn.Code    = Defines.RET_FAIL;
                optReturn.Message = ex.Message;
            }
            return(optReturn);
        }
Esempio n. 2
0
        private OperationReturn SetUserControlObject(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);
                }
                string strUserID, strCount;
                int    intCount;
                //0     userID
                //1     count
                //...   object check state
                strUserID = listParams[0];
                strCount  = listParams[1];
                if (!int.TryParse(strCount, out intCount))
                {
                    optReturn.Result  = false;
                    optReturn.Code    = Defines.RET_PARAM_INVALID;
                    optReturn.Message = string.Format("ObjectCount param invalid");
                    return(optReturn);
                }
                if (listParams.Count < 2 + intCount)
                {
                    optReturn.Result  = false;
                    optReturn.Code    = Defines.RET_PARAM_INVALID;
                    optReturn.Message = string.Format("Object count invalid");
                    return(optReturn);
                }
                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 C003 = {1}"
                                           , rentToken
                                           , strUserID);
                    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 C003 = {1}"
                                           , rentToken
                                           , strUserID);
                    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 = 2; i < listParams.Count; i++)
                    {
                        string   objectState     = listParams[i];
                        string[] listObjectState = objectState.Split(new[] { ConstValue.SPLITER_CHAR },
                                                                     StringSplitOptions.RemoveEmptyEntries);
                        if (listObjectState.Length < 2)
                        {
                            optReturn.Result  = false;
                            optReturn.Code    = Defines.RET_PARAM_INVALID;
                            optReturn.Message = string.Format("ListObjectState invalid");
                            break;
                        }
                        string    objID     = listObjectState[0];
                        string    isChecked = listObjectState[1];
                        DataRow[] drs       = objDataSet.Tables[0].Select(string.Format("C004 = {0}", objID));
                        if (isChecked == "1")
                        {
                            //不存在,则插入
                            if (drs.Length <= 0)
                            {
                                DataRow newRow = objDataSet.Tables[0].NewRow();
                                newRow["C001"] = 0;
                                newRow["C002"] = 0;
                                newRow["C003"] = Convert.ToInt64(strUserID);
                                newRow["C004"] = Convert.ToInt64(objID);
                                newRow["C005"] = DateTime.Now;
                                newRow["C006"] = DateTime.MaxValue;
                                objDataSet.Tables[0].Rows.Add(newRow.ItemArray);

                                listMsg.Add(string.Format("{0}{1}{2}", "A", ConstValue.SPLITER_CHAR, objID));
                            }
                        }
                        else
                        {
                            //存在,则移除
                            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, objID));
                                }
                            }
                        }
                    }
                    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);
        }