Exemplo n.º 1
0
        private OperationReturn GetDomainInfo(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  rentToken = session.RentInfo.Token;
                string  strSql;
                DataSet objDataSet;
                switch (session.DBType)
                {
                case 2:

                    strSql    = string.Format("SELECT * FROM T_00_012 WHERE C002={0}", rentToken);
                    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_00_012 WHERE C002={0}", rentToken);
                    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];
                    BasicDomainInfo item = new BasicDomainInfo();

                    item.RentID             = Convert.ToInt64(dr["C002"]);
                    item.DomainID           = Convert.ToInt64(dr["C001"]);
                    item.DomainName         = DecryptFromDB102(dr["C003"].ToString().Trim()).Trim();
                    item.DomainCode         = Convert.ToInt32(dr["C004"]);
                    item.DomainUserName     = DecryptFromDB102(dr["C005"].ToString().Trim()).Trim();
                    item.DomainUserPassWord = DecryptFromDB103(dr["C006"].ToString().Trim()).Trim();
                    item.RootDirectory      = dr["C007"].ToString();
                    item.IsActive           = dr["C008"].ToString() == "1";
                    item.IsActiveLogin      = dr["C010"].ToString() == "1";
                    item.IsDelete           = dr["C009"].ToString() == "1";
                    item.Creator            = Convert.ToInt64(dr["C011"].ToString());
                    item.CreatTime          = dr["C012"].ToString();
                    item.Description        = dr["C999"].ToString();

                    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);
        }
Exemplo n.º 2
0
        private OperationReturn SaveDomainInfo(SessionInfo session, List <string> listParams)
        {
            OperationReturn optReturn = new OperationReturn();

            optReturn.Result = true;
            optReturn.Code   = 0;
            string Mes = string.Empty;

            try
            {
                //ListParam
                //0      操作编号:0:删除;1:添加;2:修改
                //1      被操作的对象DomainInfo类系列化的string
                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 OperationCode = listParams[0];
                optReturn = XMLHelper.DeserializeObject <BasicDomainInfo>(listParams[1]);
                BasicDomainInfo DI         = optReturn.Data as BasicDomainInfo;
                string          domainName = EncryptToDB002(DI.DomainName);
                string          rentToken  = session.RentInfo.Token;
                string          strSql     = string.Empty;
                DataSet         objDataSet;

                if (OperationCode == "1")
                {
                    switch (session.DBType)
                    {
                    //MSSQL
                    case 2:
                        using (SqlConnection connection = new SqlConnection(session.DBConnectionString))
                        {
                            DataSet dataSet = new DataSet();
                            connection.Open();
                            strSql = string.Format("SELECT * FROM T_00_012 WHERE C002 = '{0}' AND C009=0 ORDER BY C004", rentToken);
                            SqlDataAdapter sqlDA = new SqlDataAdapter(strSql, connection);
                            sqlDA.Fill(dataSet);
                            //设置主键
                            //dataSet.Tables[0].PrimaryKey = new DataColumn[] { dataSet.Tables[0].Columns[0] };
                            SqlCommandBuilder sqlCB = new SqlCommandBuilder(sqlDA);
                            sqlDA.InsertCommand = sqlCB.GetInsertCommand();
                            int drCurrent = dataSet.Tables[0].Select(string.Format("C003 = '{0}'", domainName)).Count() > 0 ? 1 : 0;

                            if (drCurrent == 0)
                            {
                                optReturn = SaveNewDomainInfo(dataSet, session, DI);
                                Mes      += "SaveNewDomainInfo ok/";
                                if (optReturn.Result)
                                {
                                    dataSet = optReturn.Data as DataSet;
                                    sqlDA.Update(dataSet);
                                    dataSet.AcceptChanges();
                                }
                            }
                            else
                            {
                                sqlDA.Dispose();
                                connection.Close();
                                //如果重名,返回报错提醒
                                optReturn.Result = false;
                                optReturn.Code   = 99;
                                return(optReturn);
                            }
                            sqlDA.Dispose();
                            connection.Close();
                        }
                        break;

                    //ORCL
                    case 3:
                        using (OracleConnection connection = new OracleConnection(session.DBConnectionString))
                        {
                            DataSet dataSet = new DataSet();
                            connection.Open();
                            strSql = string.Format("SELECT * FROM T_00_012 WHERE C002 = '{0}' AND C009=0 ORDER BY C004", rentToken);
                            OracleDataAdapter oracleDA = new OracleDataAdapter(strSql, connection);
                            oracleDA.Fill(dataSet);
                            //设置主键
                            //dataSet.Tables[0].PrimaryKey = new DataColumn[] { dataSet.Tables[0].Columns[0] };
                            OracleCommandBuilder oracleCB = new OracleCommandBuilder(oracleDA);
                            oracleDA.InsertCommand = oracleCB.GetInsertCommand();
                            int drCurrent = dataSet.Tables[0].Select(string.Format("C003='{0}'", domainName)).Count() > 0 ? 1 : 0;
                            //dataSet.Tables[0].Rows.Find(newRole.RoleID.ToString());
                            if (drCurrent == 0)
                            {
                                optReturn = SaveNewDomainInfo(dataSet, session, DI);
                                if (optReturn.Result)
                                {
                                    dataSet = optReturn.Data as DataSet;
                                    oracleDA.Update(dataSet);
                                    dataSet.AcceptChanges();
                                }
                            }
                            else
                            {
                                oracleDA.Update(dataSet);
                                dataSet.AcceptChanges();
                                //如果重名,返回报错提醒
                                optReturn.Result = false;
                                optReturn.Code   = 99;
                                return(optReturn);
                            }
                            oracleDA.Dispose();
                            connection.Close();
                        }
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    switch (OperationCode)
                    {
                    case "0":    //删除
                        strSql = string.Format("UPDATE T_00_012 SET C009=1 WHERE C001={1} AND C002='{0}'", rentToken, DI.DomainID);
                        break;

                    case "2":    //修改
                        strSql = string.Format("UPDATE T_00_012 SET C003='{2}',C005='{3}',C006='{4}',C010='{5}',C999='{6}' WHERE C001={1} AND C002='{0}'"
                                               , rentToken, DI.DomainID
                                               , EncryptToDB002(DI.DomainName.Trim()).Trim()
                                               , EncryptToDB002(DI.DomainUserName.Trim()).Trim()
                                               , EncryptToDB003(string.Format("{0}@{1}", DI.DomainID.ToString().Trim(), DI.DomainUserPassWord.Trim())).Trim()
                                               , DI.IsActiveLogin ? 1 : 0, DI.Description);
                        break;
                    }
                    switch (session.DBType)
                    {
                    case 2:
                        optReturn = MssqlOperation.GetDataSet(session.DBConnectionString, strSql);
                        if (!optReturn.Result)
                        {
                            return(optReturn);
                        }
                        objDataSet = optReturn.Data as DataSet;

                        break;

                    case 3:
                        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);
                    }
                }
            }
            catch (Exception ex)
            {
                optReturn.Result  = false;
                optReturn.Code    = Defines.RET_FAIL;
                optReturn.Message = ex.Message;
                return(optReturn);
            }
            return(optReturn);
        }