Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtName.Text))
                {
                    MessageBox.Show("请输入类名");
                    return;
                }

                HA_RetValObjectDAL dal = new HA_RetValObjectDAL();

                if (cobj == null)
                {
                    int ret = dal.AddNew(new HA_RetValObject
                    {
                        rv_name    = txtName.Text,
                        rv_exttype = txtExtType.Text,
                        rv_note    = txtNote.Text,
                        rv_JSON    = txtRetJSON.Text
                    });

                    if (ret < 0)
                    {
                        MessageBox.Show("保存失败 : " + ret);
                    }
                }
                else
                {
                    //UpdateProject
                    bool ret = dal.Update(new HA_RetValObject
                    {
                        rv_name    = txtName.Text,
                        rv_exttype = txtExtType.Text,
                        rv_note    = txtNote.Text,
                        rv_JSON    = txtRetJSON.Text
                    });

                    if (ret == false)
                    {
                        MessageBox.Show("保存失败 : " + ret);
                    }
                }
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("保存失败 : " + ex.Message);
            }
        }
Пример #2
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);
                }
            }
        }