示例#1
0
 //private void tBtnAddConn_Click(object sender, EventArgs e)
 //{
 //    HA_RetValObjectDAL dal = new HA_RetValObjectDAL();
 //    FrmManageRetVO methodForm = new FrmManageRetVO(null, "");
 //    methodForm.ShowDialog();
 //    ReloadRetVO();
 //}
 private void ReloadRetVO()
 {
     try
     {
         Controller c = new Controller();
         db = DB.GetMainDb();
         c.RefreshListViewFromSqlIDWithOutParas(null, skinLVRetVO, "GetRetVOs");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
示例#2
0
        private void GetAllProjects()
        {
            DbService  db       = DB.GetMainDb();
            Controller c        = new Controller();
            DataSet    projects = db.ExecuteSqlID("GetProjects", null);
            DataTable  Projects = null;

            if (projects != null && projects.Tables.Count > 0)
            {
                Projects = projects.Tables[0];
            }
            c.ShowDataTableInListView(Projects, listVProjects);
        }
示例#3
0
        private void FrmConnection_Load(object sender, EventArgs e)
        {
            Controller c  = new Controller();
            DbService  db = null;

            db = DB.GetMainDb();
            DataSet   retvos = db.ExecuteSqlID("GetRetVOs", null);
            DataTable RetVOs = null;

            if (retvos != null && retvos.Tables.Count > 0)
            {
                RetVOs = retvos.Tables[0];
                c.ShowDataTableInListView(RetVOs, skinLVRetVO);
            }
        }
示例#4
0
        private void FrmConnection_Load(object sender, EventArgs e)
        {
            Controller c  = new Controller();
            DbService  db = null;

            db = DB.GetMainDb();
            DataSet   connections = db.ExecuteSqlID("GetConnections", null);
            DataTable Connections = null;

            if (connections != null && connections.Tables.Count > 0)
            {
                Connections = connections.Tables[0];
                c.ShowDataTableInListView(Connections, skinLVConns);
            }
        }
示例#5
0
        private void FrmProject_Load(object sender, EventArgs e)
        {
            Controller c = new Controller();

            db = DB.GetMainDb();
            DataSet   ags = db.ExecuteSqlID("GetAGs", null);
            DataTable AGs = null;

            if (ags != null && ags.Tables.Count > 0)
            {
                AGs = ags.Tables[0];
                c.ShowDataTableInListView(AGs, listVAGs);
            }
            DataSet   paras = db.ExecuteSqlID("GetParas", null);
            DataTable Paras = null;

            if (paras != null && paras.Tables.Count > 0)
            {
                Paras = paras.Tables[0];

                c.ShowDataTableInListView(Paras, skinLVParas);
            }
        }
示例#6
0
        private void InitSystem()
        {
            try
            {
                db = DB.GetMainDb();
                if (Projects != null)
                {
                    Projects.Dispose();
                }
                if (Interfaces != null)
                {
                    Interfaces.Dispose();
                }

                DataSet projects = db.ExecuteSqlID("GetProjects", null);

                if (projects != null && projects.Tables.Count > 0)
                {
                    Projects = projects.Tables[0];
                }

                DataSet interfaces = db.ExecuteSqlID("GetInterfaces", null);

                if (interfaces != null && interfaces.Tables.Count > 0)
                {
                    Interfaces = interfaces.Tables[0];
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                db.Close();
            }
        }
示例#7
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);
        }
示例#8
0
        private void btnSaveRetVal_Click(object sender, EventArgs e)
        {
            if (skinLVMethods.SelectedItems.Count > 0 && skinLVInterfaces.SelectedItems.Count > 0)
            {
                try
                {
                    var       a         = skinLVMethods.SelectedItems[0];
                    var       intf      = skinLVInterfaces.SelectedItems[0];
                    HA_Method ha_method = new HA_Method
                    {
                        intf_code = a.SubItems[0].Text,
                        m_name    = a.SubItems[1].Text,
                        m_code    = a.SubItems[2].Text,
                        m_desc    = a.SubItems[3].Text,
                        //m_reqtype = a.SubItems[4].Text,
                        m_template     = Convert.ToInt32(a.SubItems[4].Text),
                        m_version      = a.SubItems[5].Text,
                        m_funcode      = a.SubItems[6].Text,
                        m_isencrypted  = false, //a.SubItems[2].Text,
                        m_arggrpcode   = a.SubItems[8].Text,
                        m_rtnvaluecode = a.SubItems[9].Text,
                        m_pagesize     = Convert.ToInt32(a.SubItems[10].Text)
                    };
                    //1.connStr: 通过intf_code得到 interface上的dbConn,取出connStr和DBType
                    string    connStr  = "";
                    string    connName = "";
                    string    dbType   = "";
                    string    intfcode = ha_method.intf_code;
                    DbService db       = DB.GetMainDb();
                    Hashtable htPara   = new Hashtable();
                    htPara.Add("intf_code", intfcode);
                    DataSet tempds = db.ExecuteSqlID("GetInterface2", htPara);
                    if (tempds != null && tempds.Tables.Count > 0)
                    {
                        if (tempds.Tables[0].Rows.Count > 0)
                        {
                            connName = tempds.Tables[0].Rows[0]["intf_dbconn"].ToString();
                        }
                    }
                    if (string.IsNullOrEmpty(connName))
                    {
                        MessageBox.Show("接口没有配置数据库连接");
                        return;
                    }
                    //2.dt
                    SqlSugar.DbType sdt        = SqlSugar.DbType.SqlServer;
                    Hashtable       htParaConn = new Hashtable();
                    htParaConn.Add("conn_name", connName);
                    tempds = db.ExecuteSqlID("GetConnection2", htParaConn);

                    if (tempds != null && tempds.Tables.Count > 0)
                    {
                        if (tempds.Tables[0].Rows.Count > 0)
                        {
                            connStr = tempds.Tables[0].Rows[0]["conn_string"].ToString();
                            dbType  = tempds.Tables[0].Rows[0]["conn_dbtype"].ToString();
                        }
                    }
                    if (string.IsNullOrEmpty(connStr))
                    {
                        MessageBox.Show("数据库连接不存在");
                        return;
                    }
                    switch (dbType)
                    {
                    case "MSSql":
                        sdt = SqlSugar.DbType.SqlServer;
                        break;

                    case "Cache*":

                        break;

                    case "Oracle*":
                        sdt = SqlSugar.DbType.Oracle;
                        break;

                    default:
                        break;
                    }
                    //3.sqlStmt
                    string sqlStmt = ha_method.m_funcode;
                    if (string.IsNullOrEmpty(sqlStmt))
                    {
                        MessageBox.Show("没有查询语句");
                        return;
                    }
                    //4.paras 从ag_code里得到 ag组,再去得到所有的参数
                    string    ag_code  = ha_method.m_arggrpcode;
                    Hashtable htParaAG = new Hashtable();
                    htParaAG.Add("ag_code", ag_code);
                    tempds = db.ExecuteSqlID("GetParas2", htParaAG);
                    List <SugarParameter> sParas = new List <SugarParameter>();

                    if (tempds != null && tempds.Tables.Count > 0)
                    {
                        if (tempds.Tables[0].Rows.Count > 0)
                        {
                            int rowCount = tempds.Tables[0].Rows.Count;

                            for (int i = 0; i < rowCount; i++)
                            {
                                SugarParameter sp = new SugarParameter(tempds.Tables[0].Rows[i]["para_name"].ToString(), tempds.Tables[0].Rows[i]["para_default"].ToString());
                                sParas.Add(sp);
                            }
                        }
                    }
                    if (sParas.Count == 0)
                    {
                        MessageBox.Show("没有配置参数");
                        return;
                    }
                    //5 处理pagesize
                    if (!sqlStmt.ToLower().Contains("top"))
                    {
                        if (ha_method.m_pagesize == 0)
                        {
                            sqlStmt = sqlStmt.ToLower().Replace("select", "select top 1");
                        }
                        else
                        {
                            string topnumber = ha_method.m_pagesize.ToString();
                            if (ha_method.m_pagesize > 5)
                            {
                                topnumber = "5";
                            }
                            sqlStmt = sqlStmt.ToLower().Replace("select", "select top " + topnumber);
                        }
                    }
                    string   resultJSON = SqlSugarUtils.GetSingleJSONResult(connStr, sdt, sqlStmt, sParas);
                    JsonTool jt         = new JsonTool();
                    //6 美化JSON字符串
                    resultJSON   = jt.ConvertJsonString(resultJSON);
                    edtJson.Text = resultJSON;
                    //7 顺便保存到 RetVO 的 类JSON里去
                    Hashtable htParaRV = new Hashtable();
                    htParaRV.Add("rv_name", "ret" + ha_method.m_code);
                    tempds = db.ExecuteSqlID("GetRetVO2", htParaRV);
                    if (tempds != null && tempds.Tables.Count > 0)
                    {
                        HA_RetValObjectDAL dal = new HA_RetValObjectDAL();
                        HA_RetValObject    rvo = new HA_RetValObject
                        {
                            rv_name    = "ret" + ha_method.m_code,
                            rv_exttype = tempds.Tables[0].Rows[0]["rv_exttype"].ToString(),
                            rv_note    = tempds.Tables[0].Rows[0]["rv_note"].ToString(),
                            rv_JSON    = resultJSON
                        };
                        bool ret = dal.Update(rvo);
                        if (ret == false)
                        {
                            MessageBox.Show("保存到RetVO失败 : " + ret);
                        }
                    }
                    //8 顺手将json转换为类文件
                    #region 测试后屏蔽这段代码
                    //string destFolder = System.AppDomain.CurrentDomain.BaseDirectory;
                    //destFolder += ha_method.intf_code + @"\" + ha_method.m_code + @"\Model";
                    //DirectoryInfo di = new DirectoryInfo(destFolder);
                    //if (di.Exists == false)
                    //{
                    //    Directory.CreateDirectory(destFolder);
                    //}

                    //bool writeClassRet = RunTimeHelper.GenClassStringByJSON(resultJSON, "ILAK.API", "ILAK.API.Model", destFolder, "ret" + ha_method.m_code);

                    //if (!writeClassRet)
                    //{
                    //    MessageBox.Show("写文件失败");
                    //}
                    #endregion
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }