Пример #1
0
        private static HA_RetValObject ToModel(DataRow row)
        {
            HA_RetValObject model = new HA_RetValObject();

            model.rv_name    = row.IsNull("rv_name") ? null : (String)row["rv_name"];
            model.rv_JSON    = row.IsNull("rv_JSON") ? null : (String)row["rv_JSON"];
            model.rv_exttype = row.IsNull("rv_exttype") ? null : (String)row["rv_exttype"];
            model.rv_note    = row.IsNull("rv_note") ? null : (String)row["rv_note"];
            return(model);
        }
Пример #2
0
        public bool Update(HA_RetValObject model)
        {
            string sqlStr = "update HA_RetValObject set rv_name=@rv_name,rv_JSON=@rv_JSON,rv_exttype=@rv_exttype,rv_note=@rv_note where rv_name=@rv_name";
            int    rows   = SQLHelper.ExecuteNonQuery(sqlStr
                                                      , new SqlParameter("rv_name", model.rv_name)
                                                      , new SqlParameter("rv_JSON", model.rv_JSON)
                                                      , new SqlParameter("rv_exttype", model.rv_exttype)
                                                      , new SqlParameter("rv_note", model.rv_note)
                                                      );

            return(rows > 0);
        }
Пример #3
0
        public int AddNew(HA_RetValObject model)
        {
            string sqlStr = "insert into HA_RetValObject(rv_name,rv_JSON,rv_exttype,rv_note) output inserted.rv_id values(@rv_name,@rv_JSON,@rv_exttype,@rv_note)";
            int    id     = (int)SQLHelper.ExecuteScalar(sqlStr
                                                         , new SqlParameter("rv_name", model.rv_name)
                                                         , new SqlParameter("rv_JSON", model.rv_JSON)
                                                         , new SqlParameter("rv_exttype", model.rv_exttype)
                                                         , new SqlParameter("rv_note", model.rv_note)
                                                         );

            return(id);
        }
Пример #4
0
        public HA_RetValObject GetModelById(string id)
        {
            string    sqlStr = "select * from HA_RetValObject where rv_name=@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_RetValObject model = ToModel(row);

            return(model);
        }
Пример #5
0
        private void tBtnModiConn_Click(object sender, EventArgs e)
        {
            if (skinLVRetVO.SelectedItems.Count > 0)
            {
                var             a       = skinLVRetVO.SelectedItems[0];
                HA_RetValObject ha_conn = new HA_RetValObject
                {
                    rv_name    = a.SubItems[0].Text,
                    rv_JSON    = a.SubItems[1].Text,
                    rv_exttype = a.SubItems[2].Text,
                    rv_note    = a.SubItems[3].Text
                };

                FrmManageRetVO connForm = new FrmManageRetVO(ha_conn, a.SubItems[0].Text);
                connForm.ShowDialog();
                ReloadRetVO();
            }
        }
Пример #6
0
 public FrmManageRetVO(HA_RetValObject ha_c, string retvname)
 {
     cobj = ha_c;
     InitializeComponent();
     txtName.Text = retvname;
 }
Пример #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);
                }
            }
        }