示例#1
0
        public static bool InitProjGenOptions(string projcode)
        {
            bool ret = false;

            projOption = new ProjGenOptions();
            try
            {
                DbService db = null;
                db = DB.GetMainDb();
                Hashtable htPara = new Hashtable();
                htPara.Add("AntiSqlInject", "0");
                htPara.Add("proj_code", projcode);
                //初始化Project
                DataSet projects = db.ExecuteSqlID("GetProject", htPara);
                if (projects != null && projects.Tables.Count > 0)
                {
                    using (DataTable dt = projects.Tables[0])
                    {
                        projOption.ProjCode   = dt.Rows[0]["proj_code"].ToString();
                        projOption.ProjName   = dt.Rows[0]["proj_name"].ToString();
                        projOption.ProjPort   = dt.Rows[0]["proj_port"].ToString();
                        projOption.Interfaces = new List <IntfGenOptions>();
                    }
                    //初始化接口
                    htPara = new Hashtable();
                    htPara.Add("AntiSqlInject", "0");
                    htPara.Add("proj_code", projcode);
                    DataSet interfaces = db.ExecuteSqlID("GetInterfaceGen", htPara);
                    if (interfaces != null && interfaces.Tables.Count > 0)
                    {
                        using (DataTable idt = interfaces.Tables[0])
                        {
                            foreach (DataRow iRow in idt.Rows)
                            {
                                IntfGenOptions igo = new IntfGenOptions
                                {
                                    IntfCode = iRow["intf_code"].ToString(),
                                    IntfName = iRow["intf_name"].ToString(),
                                    Methods  = new List <MethodOptions>()
                                };

                                string conn = iRow["intf_dbconn"].ToString();
                                htPara = new Hashtable();
                                htPara.Add("AntiSqlInject", "0");
                                htPara.Add("conn_name", iRow["intf_dbconn"].ToString());
                                DataSet connections = db.ExecuteSqlID("GetConnection", htPara);
                                if (connections != null && connections.Tables.Count > 0)
                                {
                                    using (DataTable cdt = connections.Tables[0])
                                    {
                                        //初始化连接 目前 一个接口只会有一个数据库连接,所以这里直接取第一条记录
                                        ConnStrOption connOption = new ConnStrOption
                                        {
                                            Account    = cdt.Rows[0]["conn_Account"].ToString(),
                                            DBName     = cdt.Rows[0]["conn_Alias"].ToString(),
                                            DbType     = cdt.Rows[0]["conn_DBType"].ToString(),
                                            Password   = cdt.Rows[0]["conn_Password"].ToString(),
                                            ConnString = cdt.Rows[0]["conn_String"].ToString(),
                                            Host       = cdt.Rows[0]["conn_IP"].ToString()
                                        };
                                        igo.ConnOption = connOption;

                                        //初始化方法
                                        Hashtable htParaM = new Hashtable();
                                        htParaM.Add("AntiSqlInject", "0");
                                        htParaM.Add("intf_code", iRow["intf_code"].ToString());
                                        DataSet methods = db.ExecuteSqlID("GetMethodGen", htParaM);
                                        if (methods != null && methods.Tables.Count > 0)
                                        {
                                            using (DataTable mdt = methods.Tables[0])
                                            {
                                                foreach (DataRow mRow in mdt.Rows)
                                                {
                                                    MethodOptions mOption = new MethodOptions
                                                    {
                                                        MCode     = mRow["m_code"].ToString(),
                                                        MSqlStmt  = mRow["m_funcode"].ToString(),
                                                        MTemplate = mRow["m_template"].ToString(),
                                                        pagesize  = Convert.ToInt32(mRow["m_pagesize"].ToString())
                                                    };

                                                    htPara = new Hashtable();
                                                    htPara.Add("AntiSqlInject", "0");
                                                    htPara.Add("ag_code", mRow["m_arggrpcode"].ToString());
                                                    DataSet ag = db.ExecuteSqlID("GetAG", htPara);
                                                    if (ag != null && ag.Tables.Count > 0)
                                                    {
                                                        using (DataTable agdt = ag.Tables[0])
                                                        {
                                                            //一个method只有一组参数,所以这里也只取第一条记录
                                                            //初始化参数组
                                                            AGGroupOption agOption = new AGGroupOption
                                                            {
                                                                AgCode = agdt.Rows[0]["ag_code"].ToString(),
                                                                Paras  = new List <ParameterOption>()
                                                            };

                                                            // 初始化参数
                                                            htPara = new Hashtable();
                                                            htPara.Add("AntiSqlInject", "0");
                                                            htPara.Add("ag_code", mRow["m_arggrpcode"].ToString());
                                                            DataSet paras = db.ExecuteSqlID("GetParasWithAgCodeGen", htPara);
                                                            if (paras != null && paras.Tables.Count > 0)
                                                            {
                                                                using (DataTable pdt = paras.Tables[0])
                                                                {
                                                                    foreach (DataRow pitem in pdt.Rows)
                                                                    {
                                                                        ParameterOption paraOption = new ParameterOption
                                                                        {
                                                                            DataType  = pitem["para_datatype"].ToString(),
                                                                            MaxLength = pitem["para_length"].ToString(),
                                                                            ParaCode  = pitem["para_code"].ToString(),
                                                                            ParaName  = pitem["para_name"].ToString()
                                                                        };
                                                                        agOption.Paras.Add(paraOption);
                                                                    }
                                                                }
                                                            }
                                                            mOption.MAgOption = agOption;
                                                        }
                                                    }
                                                    igo.Methods.Add(mOption);
                                                }
                                            }
                                        }
                                    }
                                    projOption.Interfaces.Add(igo);
                                }
                                else
                                {
                                    throw new Exception("没有配置连接信息");
                                }
                            }
                            ret = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(ret);
        }