help me to debug my code...

by rudysetyo 26 January 2009 03:32
for (int x = 0; x < takeoutWord.Length; x++)
{
     for (int y=0;y < searchList.Count;y++)
     {
        if (takeoutWord[x].ToString() == searchList[y].ToString())
             searchList.RemoveAt(y);
     }
}


please... help me to find the BUG...

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

.NET Programming | Common

Domain Search using Dynadot API

by rudysetyo 07 April 2008 22:44

Through this weekend, i walk all my time to "cook" this API into one good domain search for my customer...  You could check the live version here http://www.erudeye.net/domain.aspx.

Basically what we need is the code below, the other is for your own purpose on how do you want to serve it. 

    WebRequest myWebRequest = WebRequest.Create(URI);
    WebResponse myWebResponse = myWebRequest.GetResponse();
    StreamReader sr = new StreamReader(myWebResponse.GetResponseStream());
    String dynadotResponse = new String();
    dynadotResponse = sr.ReadToEnd();

Replace the URI parameter with the URI string we got from Dynadot API.

URI example : "https://www.dynadot.com/api.html?version=1.0&key=[key]&command=search&domain0=mydomain.com&domain1=mydomain.net". And we'll get the response as dynadot give the example on http://www.dynadot.com/domain/api.html :

======== Dynadot Response ========
ok,domain0,mydomain.com,,no,domain1,mydomain.net,,yes,

==============================

Than how to serve the response into GridView? Come on, you are the master at all, don't ask me... but it's ok if you insist hehe, here they are...

    string[] substrings = dynadotResponse.Split(new Char[] { ',' }); 

    if (substrings[0] == "ok")
    {
        gvDomain.DataSource = getListDomain(substrings);
        gvDomain.DataBind();
    }
    else
    {
       gvDomain.DataSource = null;
       gvDomain.DataBind()
    }

The getListDomain method is for placing the array into object that i have and save the object in the System.Collections.Generic.List.

    private List<DomainObject> getListDomain(string[] arrayString)
    {
        List<DomainObject> listDomain = new List<DomainObject>();
        DomainObject domain;
        for (int p = 0; p < arrayString.Length; p = p + 2)
        {
            domain = new DomainObject();
            if (p != 0 && p < arrayString.Length - 2 && arrayString[p].Length > 3)
            {
                domain.Domain = arrayString[p];
                domain.Result = arrayString[p + 2];
                listDomain.Add(domain);
            }
        }
        return listDomain;
    }

And the DomainObject class is...

    public class DomainObject
    {
       private string domain;
       private string result;
       public string Domain { get { return domain; } set { domain = value; } }
       public string Result { get { return result; } set { result = value; } }
    }

This is the main point of how to bind the Dynadot API response using C# into good user interface and serve it to your client... actually there are more code in my real application, but that's just my purpose which could be different with others.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

.NET Programming

a "netTiers like" LINQ to SQL application

by rudysetyo 30 January 2008 06:01

Some of us maybe familiar with netTiers when building an application, it's really helping us to cut the development time, LINQ does cut the time also... No, i don't want to compare between netTiers and LINQ to SQL, although in some cases they're comparable... What i want to share here is how to make a simple data visualization using gridview, really simple coz we will use LINQ to accomodate the simpleness... What "simple" i'm talking about? commonly when we build a CRUD application, we use ADO.NET or DAAB to access the database, but in this case, ADO.NET was handled by LINQ.



Familiar with the search control above? if you are new to that control, that is GridViewSearchPanel of netTiers. But what i'll show you is we'll create our own search to GridView exactly the same function as netTiers have.

    <form id="form1" runat="server">
    <div>
        Look for :
        <asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem>Code</asp:ListItem>
            <asp:ListItem>Description</asp:ListItem>
        </asp:DropDownList>
        Which :
        <asp:DropDownList ID="DropDownList2" runat="server">
            <asp:ListItem Value="0">Contains</asp:ListItem>
            <asp:ListItem Value="1">Ends With</asp:ListItem>
            <asp:ListItem Value="2">Starts With</asp:ListItem>
        </asp:DropDownList>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1"
            runat="server" Text="Search" onclick="Button1_Click" />
        <asp:Button ID="Button2"
            runat="server" Text="Reset" onclick="Button2_Click" />
        <p></p>   
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="true">
        </asp:GridView></div>
    </form>

1. Add an aspx page right exactly the same as above. 

2. Add LINQ to SQL (.dbml), disobey what behind the dbml right now, we talk about it later, here is my dbml:  

 

3. Go to your code behind, add this code and play it:

    protected void Page_Load(object sender, EventArgs e)
    {
        GridView1.DataSource = GetJobPrefix(0);
        GridView1.DataBind();
    }

    public IList<JobPrefix> GetJobPrefix(int rowStatus)
    {
        using (JobPrefixDataContext context = new JobPrefixDataContext())
        {
            return (from c in context.JobPrefixes
                    where c.RowStatus == rowStatus
                    select c).ToList();
        }
    }

    protected void Button1_Click(object sender, EventArgs e){}

    protected void Button2_Click(object sender, EventArgs e){}

 

In my application, the aspx will render like this, at this point the search facility didn't worked yet.


 

4. Next we'll create a method for searching and filtering.

    public IList<JobPrefix> GetJobPrefix(int rowStatus, string desc, string code, SearchOperator searchOperator)
    {
        using (JobPrefixDataContext context = new JobPrefixDataContext())
        {
            switch (searchOperator)
            {
                case SearchOperator.contains:
                    return (from c in context.JobPrefixes
                            where c.RowStatus == rowStatus && c.JobPrefixDesc.Contains(desc) && c.JobPrefixCode.Contains(code)
                            select c).ToList();
                    break;
                case SearchOperator.endswith:
                    return (from c in context.JobPrefixes
                            where c.RowStatus == rowStatus && c.JobPrefixDesc.EndsWith(desc) && c.JobPrefixCode.EndsWith(code)
                            select c).ToList();
                    break;
                case SearchOperator.startswith:
                    return (from c in context.JobPrefixes
                            where c.RowStatus == rowStatus && c.JobPrefixDesc.StartsWith(desc) && c.JobPrefixCode.StartsWith(code)
                            select c).ToList();
                    break;
                default:
                    return (from c in context.JobPrefixes
                            where c.RowStatus == rowStatus && c.JobPrefixDesc.Contains(desc) && c.JobPrefixCode.Contains(code)
                            select c).ToList();
            }
        }
    }

    public enum SearchOperator
    {
        contains = 0,
        endswith = 1,
        startswith = 2,
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        switch (DropDownList1.SelectedValue)
        {
            case "Code":
                GridView1.DataSource = GetJobPrefix(0, string.Empty,TextBox1.Text,(SearchOperator)Convert.ToInt32(DropDownList2.SelectedValue));
                GridView1.DataBind();
                break;
            case "Description":
                GridView1.DataSource = GetJobPrefix(0, TextBox1.Text, string.Empty, (SearchOperator)Convert.ToInt32(DropDownList2.SelectedValue));
                GridView1.DataBind();
                break;
        }
       
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        GridView1.DataSource = GetJobPrefix(0);
        GridView1.DataBind();
    }

 

Ok, that's it. When i try to filter the data using keyword "in" in the Description(JobPrefixDesc) field with the "Contains" method, the aspx will render like this (you could try the "Ends With" and "Starts With" by yourself) 

  

 

  Really simple isn't it? Laughing build our own "netTiers like" GridViewSearchPanel using LINQ to SQL. Please enjoy...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

.NET Programming | Database

Copyright © Rudy Setyo Purnomo. Hosting by erudeye.

About the author

me Developer
Researcher
Entrepreneur
Juventini

Chat with me!