Example #1
0
    public string SqlRead(dyk.Script.Code.Variable.String str)
    {
        string res = "";

        using (Ly.Data.SQLClient Conn = new Ly.Data.SQLClient(gszConnString)) {
            Conn.ExecuteReader(str.Value);
            if (Conn.DataReader.Read())
            {
                res = Conn.DataReader[0].ToString();
            }
        }

        return(res);
    }
Example #2
0
    /// <summary>
    /// 执行Json脚本
    /// </summary>
    /// <returns></returns>
    public int Execute()
    {
        string sql = GetNormalSQLString();

        gSC.Clear();

        using (Ly.Data.SQLClient Conn = new Ly.Data.SQLClient(gstrConn)) {
            Conn.ExecuteReader(sql);
            while (Conn.DataReader.Read())
            {
                Structure st = new Structure();
                for (int i = 0; i < Conn.DataReader.FieldCount; i++)
                {
                    string sName = Conn.DataReader.GetName(i);
                    st[sName] = Conn.DataReader[i].ToString();
                }
                gSC.Add(st);
            }
        }

        return(gSC.Count);
    }
Example #3
0
    //执行SQL语句并返回首行的第一个值
    private string Fun_SqlRead(List <StorageUnit> list, StoragePool pool)
    {
        switch (list.Count)
        {
        case 1:
            string szArg0 = Ly.ZBox.StorageUnit.GetStringValue(list[0], pool);
            string res    = "";

            using (Ly.Data.SQLClient Conn = new Ly.Data.SQLClient(gszConnString)) {
                Conn.ExecuteReader(szArg0);
                if (Conn.DataReader.Read())
                {
                    res = Conn.DataReader[0].ToString();
                }
            }

            return(res);

        default:
            throw new Exception("参数数量不正确,未找到" + list.Count + "参数的定义。");
        }
    }
Example #4
0
        public static string getValue(ClsPage owner, string connstr, int id, string name, string value, string format, string formatpath)
        {
            if (format != "")
            {
                ClsAjaxPageArgs gPageArgs = new ClsAjaxPageArgs();

                for (int i = 0; i < gPageArgs.Object.Count; i++)
                {
                    gPageArgs.Object[i].Value = owner[gPageArgs.Object[i].Name];
                }

                using (Ly.Formats.Json json = new Ly.Formats.Json(format)) {
                    switch (json["Type"].Value)
                    {
                    case "Month":
                        string   sMonth  = value + "-01";
                        DateTime dtMonth = DateTime.Now;
                        if (DateTime.TryParse(sMonth, out dtMonth))
                        {
                            //sValue = dtMonth.ToString(jValue["Binding"].Value);
                            return(dtMonth.ToString(json["Binding"].Value));
                        }
                        break;

                    case "Date":
                        string   sDate  = value;
                        DateTime dtDate = DateTime.Now;
                        if (DateTime.TryParse(sDate, out dtDate))
                        {
                            //sValue = dtDate.ToString(json["Binding"].Value);
                            return(dtDate.ToString(json["Binding"].Value));
                        }
                        break;

                    case "File":
                        switch (json["Binding"].Value)
                        {
                        case "Image":
                            break;

                        default:
                            //sValue = "<a href=\"" + sValue + "\" target=\"_blank\">下载</a>";
                            return("<a href=\"" + value + "\" target=\"_blank\">下载</a>");
                            //break;
                        }
                        break;

                    case "Number":
                        double dbTemp = 0;
                        if (double.TryParse(value, out dbTemp))
                        {
                            //sValue = dbTemp.ToString(json["Binding"].Value);
                            return(dbTemp.ToString(json["Binding"].Value));
                        }
                        else
                        {
                            //sValue = "&nbsp;";
                            return("&nbsp;");
                        }

                    //break;
                    case "Check":
                        #region [=====选择框模式=====]
                        int    nTemp   = 0;
                        string szValue = "";
                        if (int.TryParse(value, out nTemp))
                        {
                            //sValue = dbTemp.ToString(json["Binding"].Value);
                            //return nTemp.ToString(json["Binding"].Value);
                            if (nTemp > 0)
                            {
                                szValue = "√";
                            }
                        }
                        //ClsAjaxPage pg = new ClsAjaxPage(owner);
                        return("<div id=\"" + gPageArgs.UID + "_Check_" + id + "_" + name + "\" style=\"margin: 0 auto; width:14px;height:14px; line-height:14px; border:1px solid #ddd;text-align: center; vertical-align: middle; color:#090; font-weight: bold; background: #fff;cursor:pointer;\" onclick=\"Page.Functions.Table.CheckClick('" + gPageArgs.UID + "',{Arg_Key_ID: " + id + ",Arg_Key_Name: '" + name + "'});\">" + szValue + "</div>");

                        #endregion
                    case "Read":
                        #region [=====数据库读取模式=====]
                        //string szSql = Pub.IO.ReadAllText(Server.MapPath(this.WebConfig.ShareSQLSettingPath + "/" + gTab.SystemTables.Structure.Name + "_" + st.Name + "_Format.azsql"));
                        string szSql = Pub.IO.ReadAllText(formatpath);

                        using (Ly.Formats.Json jSql = new Ly.Formats.Json()) {
                            jSql["Value"].Value = value;
                            using (AzSqlProgram Asm = new AzSqlProgram(owner, connstr, jSql)) {
                                try {
                                    szSql = Asm.ExecuteString(szSql);
                                } catch (Exception ex) {
                                    //pg.OutPut("脚本执行发生异常:" + ex.Message + "<br><br>");
                                    //pg.OutPut(Asm.Program.Debug().Replace("\r\n", "<br>").Replace("\n", "<br>").Replace(" ", "&nbsp;"));
                                    string szError = "脚本执行发生异常:" + ex.Message;
                                    //szError += ";Sql:" + szSql;
                                    return(szError);
                                } finally {
                                    //pg.OutPut(Asm.Program.Debug().Replace("\r\n", "<br>").Replace("\n", "<br>").Replace(" ", "&nbsp;"));
                                }
                                //pg.OutPutAsText(Asm.Test(gszSql));
                                //pg.Dispose();
                            }
                        }

                        using (Ly.Data.SQLClient ConnValue = new Ly.Data.SQLClient(connstr)) {
                            try {
                                ConnValue.ExecuteReader(szSql);
                            } catch (Exception ex) {
                                //pg.OutPutAsText("错误信息:" + ex.Message);
                                //pg.OutPut("<br>");
                                //pg.OutPutAsText("Sql:" + szSql);
                                //pg.Dispose();
                                string szError = "错误信息:" + ex.Message;
                                szError += ";Sql:" + szSql;
                                return(szError);
                            }

                            if (ConnValue.DataReader.Read())
                            {
                                //sValue = ConnValue.DataReader[0].ToString();
                                return(ConnValue.DataReader[0].ToString());
                            }
                            else
                            {
                                //sValue = "";
                                return("&nbsp;");
                            }
                        }
                        //break;
                        #endregion
                    }
                }
            }
            return(value);
        }