Пример #1
0
 public FrmManageMethod(HA_Method ha_c, string intf_code)
 {
     cobj = ha_c;
     InitializeComponent();
     labelIntfCode.Text = intf_code;
     intfcode           = intf_code;
 }
Пример #2
0
        private void skinLVMethods_DoubleClick(object sender, EventArgs e)
        {
            if (skinLVMethods.SelectedItems.Count > 0 && skinLVInterfaces.SelectedItems.Count > 0)
            {
                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)
                };

                FrmManageMethod addprojForm = new FrmManageMethod(ha_method, intf.Text);
                addprojForm.ShowDialog();
                ReloadMethod(intf.Text);
            }
        }
Пример #3
0
        public HA_Method GetModelById(string id)
        {
            string    sqlStr = "select * from HA_Method where m_code=@id";
            DataTable dt     = SQLHelper.ExecuteDataTable(sqlStr, new SqlParameter("id", id));

            if (dt.Rows.Count > 1)
            {
                throw new Exception("more than 1 row was found");
            }
            if (dt.Rows.Count <= 0)
            {
                return(null);
            }
            DataRow   row   = dt.Rows[0];
            HA_Method model = ToModel(row);

            return(model);
        }
Пример #4
0
        private static HA_Method ToModel(DataRow row)
        {
            HA_Method model = new HA_Method();

            model.intf_code      = row.IsNull("intf_code") ? null : (String)row["intf_code"];
            model.m_name         = row.IsNull("m_name") ? null : (String)row["m_name"];
            model.m_code         = row.IsNull("m_code") ? null : (String)row["m_code"];
            model.m_desc         = row.IsNull("m_desc") ? null : (String)row["m_desc"];
            model.m_reqtype      = row.IsNull("m_reqtype") ? null : (String)row["m_reqtype"];
            model.m_template     = row.IsNull("m_template") ? null : (Int32?)row["m_template"];
            model.m_version      = row.IsNull("m_version") ? null : (String)row["m_version"];
            model.m_funcode      = row.IsNull("m_funcode") ? null : (String)row["m_funcode"];
            model.m_isencrypted  = row.IsNull("m_isencrypted") ? null : (Boolean?)row["m_isencrypted"];
            model.m_arggrpcode   = row.IsNull("m_arggrpcode") ? null : (String)row["m_arggrpcode"];
            model.m_rtnvaluecode = row.IsNull("m_rtnvaluecode") ? null : (String)row["m_rtnvaluecode"];
            model.m_pagesize     = row.IsNull("m_pagesize") ? 0 : (int)row["m_pagesize"];
            return(model);
        }
Пример #5
0
        public int AddNew(HA_Method model)
        {
            string sqlStr = "insert into HA_Method(intf_code,m_name,m_code,m_desc,m_reqtype,m_template,m_version,m_funcode,m_isencrypted,m_arggrpcode,m_rtnvaluecode,m_pagesize) " +
                            "output inserted.m_id values(@intf_code,@m_name,@m_code,@m_desc,@m_reqtype,@m_template,@m_version,@m_funcode,@m_isencrypted,@m_arggrpcode,@m_rtnvaluecode,@m_pagesize)";
            int id = (int)SQLHelper.ExecuteScalar(sqlStr
                                                  , new SqlParameter("intf_code", model.intf_code)
                                                  , new SqlParameter("m_name", model.m_name)
                                                  , new SqlParameter("m_code", model.m_code)
                                                  , new SqlParameter("m_desc", model.m_desc)
                                                  , new SqlParameter("m_reqtype", model.m_reqtype)
                                                  , new SqlParameter("m_template", model.m_template)
                                                  , new SqlParameter("m_version", model.m_version)
                                                  , new SqlParameter("m_funcode", model.m_funcode)
                                                  , new SqlParameter("m_isencrypted", model.m_isencrypted)
                                                  , new SqlParameter("m_arggrpcode", model.m_arggrpcode)
                                                  , new SqlParameter("m_rtnvaluecode", model.m_rtnvaluecode)
                                                  , new SqlParameter("m_pagesize", model.m_pagesize)
                                                  );

            return(id);
        }
Пример #6
0
        public bool Update(HA_Method model)
        {
            string sqlStr = "update HA_Method set intf_code=@intf_code,m_name=@m_name,m_code=@m_code,m_desc=@m_desc,m_reqtype=@m_reqtype," +
                            "m_template=@m_template,m_version=@m_version,m_funcode=@m_funcode,m_isencrypted=@m_isencrypted,m_arggrpcode=@m_arggrpcode," +
                            "m_rtnvaluecode=@m_rtnvaluecode, m_pagesize=@m_pagesize where m_code=@m_code";
            int rows = SQLHelper.ExecuteNonQuery(sqlStr
                                                 , new SqlParameter("intf_code", model.intf_code)
                                                 , new SqlParameter("m_name", model.m_name)
                                                 , new SqlParameter("m_code", model.m_code)
                                                 , new SqlParameter("m_desc", model.m_desc)
                                                 , new SqlParameter("m_reqtype", model.m_reqtype)
                                                 , new SqlParameter("m_template", model.m_template)
                                                 , new SqlParameter("m_version", model.m_version)
                                                 , new SqlParameter("m_funcode", model.m_funcode)
                                                 , new SqlParameter("m_isencrypted", model.m_isencrypted)
                                                 , new SqlParameter("m_arggrpcode", model.m_arggrpcode)
                                                 , new SqlParameter("m_rtnvaluecode", model.m_rtnvaluecode)
                                                 , new SqlParameter("m_pagesize", model.m_pagesize)
                                                 );

            return(rows > 0);
        }
Пример #7
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);
                }
            }
        }
Пример #8
0
        private void btnPreviewReq_Click(object sender, EventArgs e)
        {
            #region 调用返回json串的操作
            //SqlSugarUtils ssu = new SqlSugarUtils();
            //string resultJSON = ssu.TestGetDbAndOperate();
            //JsonTool jt = new JsonTool();
            //resultJSON = jt.ConvertJsonString(resultJSON);
            //edtJson.Text = resultJSON;
            #endregion
            try
            {
                if (skinLVMethods.SelectedItems.Count > 0)
                {
                    var a = skinLVMethods.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)
                    };

                    string                m_code = a.SubItems[2].Text;
                    SugarParameter        sp     = new SugarParameter("m_code", m_code);
                    List <SugarParameter> lsp    = new List <SugarParameter>();
                    lsp.Add(sp);
                    string sysConnString = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
                    //查询所有参数
                    string sqlStmt = @"SELECT
                                    a.[para_name]
                                   ,a.[para_default]
                                   ,a.[para_datatype]
                                   FROM [dbo].[HA_Parameter] a 
                                   left join [dbo].[HA_ArgGroup] b on  a.para_code
                                   in (select col from dbo.split((select i.ag_paras from [dbo].[HA_ArgGroup] i
                                   where i.ag_code=b.ag_code)+',' ,','))
                                   left join [dbo].[HA_Method] c on c.m_arggrpcode = b.ag_code
                                   where c.m_code =@m_code";
                    using (DataTable dt = SqlSugarUtils.GetQueryDataTableResult(sysConnString, sqlStmt, lsp))
                    {
                        int columnNumber = dt.Columns.Count;
                        int rowNumber    = dt.Rows.Count;
                        //var obj = DynamicParasFactory.ConstructRequestObject(dt);
                        string codeString = DynamicParasFactory.CodeBuilder(dt);
                        string resultJSON = DynamicParasFactory.TranslateObjectInCodeToJSON(codeString);

                        JsonTool jt = new JsonTool();
                        //美化JSON字符串
                        resultJSON   = jt.ConvertJsonString(resultJSON);
                        edtJson.Text = resultJSON;
                        #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, "Req" + ha_method.m_arggrpcode);

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