Ejemplo n.º 1
0
        protected override void RenderContents(HtmlTextWriter output)
        {
            String html = "";

            output.AddAttribute(HtmlTextWriterAttribute.Id, this.ID);
            if (Class != null)
            {
                output.AddAttribute("class", this.Class);
            }

            try
            {
                DataSet ds = null;
                if (SQL != "")
                {
                    string[] kolonlar = Columns.Split(',');
                    string[] fieldlar = DisplayFields.Split(',');
                    string   prov     = Config.provider.ToString();
                    if (prov == "MSSQL")
                    {
                        ds = WebFramework.DataSetFill(SQL, SQLParams.ToArray());
                    }
                    else if (prov == "MYSQL")
                    {
                        ds = MySQLDb.WebFramework.DataSetFill(SQL, SQLParams.ToArray());
                    }
                    else if (prov == "ACCESS")
                    {
                        ds = AccessDb.WebFramework.DataSetFill(SQL, SQLParams.ToArray());
                    }
                    else if (prov == "ORACLE")
                    {
                        ds = OracleDb.WebFramework.DataSetFill(SQL, SQLParams.ToArray());
                    }
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        html += "<thead><tr>";
                        for (int i = 0; i < fieldlar.Length; i++)
                        {
                            html += "<td>" + fieldlar[i].Trim() + "</td>";
                        }
                        String content = "";
                        if (this.Content != null)
                        {
                            Control templateContainer = new Control();
                            Content.InstantiateIn(templateContainer);

                            content = RenderControl(templateContainer);
                        }
                        if (content != "")
                        {
                            html += "<td class='tablecontrol_content'>" + ContentHeaderTitle + "</td>";
                        }
                        html += "</tr></thead>";
                        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                        {
                            if (PrimaryKey != "")
                            {
                                html += "<tr data-id='" + ds.Tables[0].Rows[i].Field <Object>(PrimaryKey) + "'>";
                            }
                            else
                            {
                                html += "<tr>";
                            }
                            for (int j = 0; j < kolonlar.Length; j++)
                            {
                                html += "<td>" + ds.Tables[0].Rows[i].Field <Object>(kolonlar[j].Trim()) + "</td>";
                            }
                            if (content != "")
                            {
                                html += "<td>" + content + "</td>";
                            }
                            html += "</tr>";
                        }
                    }
                }
                output.RenderBeginTag("table");
            }
            catch (Exception hata)
            {
                output.RenderBeginTag("div");
                html += "<p style='color:red;'><strong>Hata:</strong> " + hata.Message + "</p>";
            }
            output.Write(html);
            output.RenderEndTag();
        }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
//            if (!IsPostBack)
            {
                // extract URL parameters
                if (Request.Params["UCE"] != null)
                {
                    UserControlForEditing = Request.Params["UCE"];
                }
                if (Request.Params["BO"] != null)
                {
                    BaseObject = Request.Params["BO"];
                }
                if (Request.Params["SF"] != null)
                {
                    ShowFields = Request.Params["SF"];
                }
                if (Request.Params["DF"] != null)
                {
                    DisplayFields = Request.Params["DF"];
                }
                if (Request.Params["SEL"] != null)
                {
                    SelectionField = Request.Params["SEL"];
                }
                if (Request.Params["ID"] != null)
                {
                    SelectionID = Request.Params["ID"];
                }
                if (Request.Params["ORD"] != null)
                {
                    OrderField = Request.Params["ORD"];
                }
                if (Request.Params["LNK"] != null)
                {
                    LinkField = Request.Params["LNK"];
                }

                // configure the entity data source
                // use the commandtext to specify the query
                string Query = "select " + ShowFields + " from " + BaseObject + " where " + SelectionField + "=@Par order by " + OrderField;
                EntityDataSourceLinks.CommandText = Query;
                EntityDataSourceLinks.CommandParameters.Clear();
                EntityDataSourceLinks.CommandParameters.Add("Par", System.Data.DbType.Guid, SelectionID);

                // now generate the columns
                GridView1.AutoGenerateColumns = false;
                string[] FieldList  = ShowFields.Split(',');
                string[] FieldNames = DisplayFields.Split(',');
                for (int i = 0; i < FieldList.Count(); i++)
                {
                    BoundField bc = new BoundField();

                    bc.DataField  = FieldList[i];
                    bc.HeaderText = FieldList[i];
                    if (FieldNames.Count() > i)
                    {
                        bc.HeaderText = FieldNames[i];
                    }
                    bc.Visible = bc.HeaderText.ToUpper() != "X";

                    // strip of leading this like it.
                    if (bc.DataField.IndexOf('.') > 0)
                    {
                        bc.DataField = bc.DataField.Split('.')[1];
                    }
                    if (bc.HeaderText.IndexOf('.') > 0)
                    {
                        bc.HeaderText = bc.HeaderText.Split('.')[1];
                    }

                    GridView1.Columns.Add(bc);
                }
            }
        }