Let Share Codes

A Member? Please Login  
type your username and password to login
Date: July 27, 2008, 01:52 AM
223944 members and 127268 Topics
Latest Member: frunteefeexia
Nairaland [Nigerian Forum] Home Help Search Who is currently online? Login Register
Nairaland Forum  |  Technology  |  Programming  |  Let Share Codes
Pages: (1) (2) Go Down Send this topic Notify of replies
Author Topic: Let Share Codes  (Read 1116 views)
Smart K. (m)
Let Share Codes
« on: September 11, 2007, 01:53 PM »

Hi guys,
I have been nursing the idea of starting my blog for some times now but I have been very busy doing office work.
I have seen wonders that have been done in nairaland by developers. I feel its high time we truly help each other. I created this forum to serve as a forum where a developer can meet and help other developers. Mainly
i. Lets share general codes: I mean keep your business rules and share codes that are needed almost everywhere;
ii. Post any question(s) bothering you and possibly I or any other developer might find an answer to it;
iii. Lets share concepts and ideas.

Warning: I am MS developer, meaning I may be able to assist on VB, VB.NET, C, C++, C#, OOP only. Notwithstanding, I have done a little JAVA  in the past (or I may ask some colleagues in my office).  I may also assist on Javascript, PHP, etc.

So, LET US SHARE.

Good Luck.
xanadu
Re: Let Share Codes
« #1 on: September 11, 2007, 02:46 PM »

Nice thread, Smart K. I am definitely interested, will be glad to share PHP codes where I can. Looks like the begining of something great here - some kind of code repository that will help developers here on Nairaland and hopefully help move the country forward technologically.
Smart K. (m)
Re: Let Share Codes
« #2 on: September 11, 2007, 03:29 PM »

@xanadu, welcome.

Check this:
Topic: Classes or Linear Programming

It is very interesting how some developers have neglected the use of classes these days. I have worked with some organizations that have never heard of classes one way or the other. Let me use this opportunity to state the advantages of using classes (the ones I can remember):

i. Class encapsulates;
ii. Makes your programming easier to maintain;
iii. Promotes readability;
iv. Oh sorry, Class is the core central  of OOP: add any advantage that you think OOP has.

Please Note that all my postings in this forum shall come in classes (method, interface, property , ).

Good luck.
xanadu
Re: Let Share Codes
« #3 on: September 12, 2007, 12:32 AM »

Just to add a couple of lines to Smart K's post above: I find that, in my experience with php, the biggest advantage of classes to me has been Reusability.
Using classes, you can use the same code for several programms or projects. You can achieve the same, of course, using functions - but in many cases even functions need to be 'customised' when being reused in different projects. Classes eliminate this.
So, to add to the advantages of classes:

v. Reusability/portability
Smart K. (m)
Re: Let Share Codes
« #4 on: September 12, 2007, 09:57 AM »

Hi all,
I have been writing aspx some times now and I discovered that I have been writing the same function every time, so I decided to put it in a class and just call the function from the class whenever I need the function.
Here is a class that helps you to upload image file e.g. passport (u don't need to bother yourself everytime doing the same ):


public class UploadManager
{
public bool UploadFile(ref FileUpload f, ref string message)
{
    if (!f.HasFile)
    {
        message = "No file is selected.";
        return false;
    }
    HttpContext context = HttpContext.Current;
    string sessionid = context.Session.SessionID;
    string fileExtension = Path.GetExtension(f.FileName).ToLower();
    string[] allowedExtensions = new string[] { ".jpeg", ".jpg" };
    int totallegth = allowedExtensions.Length;
    for (int counter = 0; counter < totallegth; counter++)
    {
        if (fileExtension == allowedExtensions[counter])
        {
            Bitmap myImage = new Bitmap(120, 140);
            try
            {
                string path = context.Server.MapPath("~/UploadedImages/");
                string filename = sessionid + DateAndTime.get_Now().Millisecond.ToString() + ".jpg";
                string fullpath = path + filename;
                f.PostedFile.SaveAs(fullpath);
                myImage = new Bitmap(fullpath);
                if (((myImage.Width >= 110) & (myImage.Width <= 130)) & ((myImage.Height >= 130) & (myImage.Height <= 150)))
                {
                    message = "~/UploadedImages/" + filename;
                    return true;
                }
                message = "Invalid Picture size! The Passport Photograph must be of size 120 X 140px";
                return false;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception ex = exception1;
                AppException.LogError(ex.Message);
                message = "Image could not be uploaded at the moment.";
                ProjectData.ClearProjectError();
                return false;
                ProjectData.ClearProjectError();
            }
            finally
            {
                myImage.Dispose();
            }
        }
    }
    message = "Invalid Picture format! The Passport Photograph must a jpeg.";
    return false;
}

}

Usage:
 UploadManager um = new UploadManager();

if (um.UploadFile(this.filPassport, message) )
{
                this.imgPassport.ImageUrl = message;
                ViewState("picPath") = message;
 }
else
{
   this.lblErrorMesage = message;
}

Enjoy and please let me know if u have any problem using the class.

Good luck.
           
Fikzy (m)
Re: Let Share Codes
« #5 on: September 12, 2007, 08:11 PM »


I need to load a lot of records from database with C# and simultaneously UP date UI with status like "Loading X or Y, " and also update the progress monitor. I know its

Treading, I have raved around the internet and deciphering the tutorials on Threads is not working for me now. I need a code sample to handle my need.

I need help.

Cheers,
Smart K. (m)
Re: Let Share Codes
« #6 on: September 21, 2007, 09:50 AM »

Sorry Fikzy,
will get back to u before end of work today. i have been very busy lately.
Fikzy (m)
Re: Let Share Codes
« #7 on: September 21, 2007, 11:51 AM »

@Smart K
The BackgroundWorker Component allows a form to run an operation asynchronously. This is very useful when we deal with such kind of operations as database transactions, image downloads etc.

I used the backgroud worker to partially solve my code challenges but the following problem arose.

1. I needed to update UI like textbox with status of my program but couldnt because C# said i can't call the object from another thread. what i did then was to increament an integer and get the current value of the integer via a Timer's Tick() event. here, i update the textBox with the current value of the Increamenting integer.

2. I am not satisfied with the speed of loading. Ok, what i am realy loading is some byte records of about 1001K [Database size] into an ArrayList. my programs loads aproximatelly 1 record every 100miliseconds. i believe it should be able to do this faster.

Question: how do i know the default  sleep time for the BackgroundWorker Class Thread. 2) can control the sleep time.

Ultimatelly, i want to be able to manage my app threading requirments withuout using the BackgroudWorker with the hopes that it will give me a better performance.


Fikzy (m)
Re: Let Share Codes
« #8 on: September 21, 2007, 12:05 PM »

@Smart K
some how, this post is not active. why? or is there another code sharing link on this forumn where developers hang out?, 
Smart K. (m)
Re: Let Share Codes
« #9 on: September 21, 2007, 12:29 PM »

Quote
some how, this post is not active. why? or is there another code sharing link on this forumn where developers hang out?,

Not exactly that I know of but there also similar forums in programming. Its just a matter of time.
Fikzy (m)
Re: Let Share Codes
« #10 on: September 21, 2007, 04:23 PM »

Guys, check out this link.

Title: How to: Make Thread-Safe Calls to Windows Forms Controls

It explains how to check if the call to a thread is from the current Thread or not,
it also explained how to update UI using the BackgroundWorker RunWorkerCompleted(, ) and ProgressChanged(, ) metchods.

http://msdn2.microsoft.com/en-us/library/ms171728(VS.80).aspx

miclad
HELP WITH CODE TO SEARCH A DOMAIN NAME
« #11 on: September 29, 2007, 09:20 AM »

Good of you guy please kindlly hlp me for the code (php) i can use for searching a domain name like whois and some other php tutorials i am a beginner my email is solution@miclad.com thanks Miclad.
Fikzy (m)
Re: Let Share Codes
« #12 on: September 29, 2007, 07:48 PM »

@miclad

PHP scripts to do WHOIS, check this out;
http://www.hotscripts.com/PHP/Scripts_and_Programs/Networking_Tools/Whois/index.html

To get elementry tutorial on php, check this out;
http://www.phpfreaks.com/tutorial_cat/8/Basics-&-Beginner-Tutorials.php

PHP is interesting and easy to lean.

all the best,
ritchboi
Re: Let Share Codes
« #13 on: September 29, 2007, 10:29 PM »

i jus started learnin basic programin wit C.oviously u guys r WAY ahead of me,so can someone kindly share wid me where they studied IT,what kind of job u do now or any oda tin that can b helpful 2 me.Tanx
Kobojunkie
Re: Let Share Codes
« #14 on: September 30, 2007, 07:15 PM »

In the Spirit of Sharing code, anyone know how to write and able to share code for an ASP.NET/AJAX Image Preloader that basically allows users to select picture user would like to upload into web album and preview the image at the same time without necessarily uploading the picture??? I started working on one but since I am not really a Javascript guru, I was wondering if someone has already figured this out and would like to share.


KoboJunkie
seluvsmayo (f)
Re: Let Share Codes
« #15 on: October 02, 2007, 09:20 AM »

Hello Fellow Nairaland developers,
   Am relatively new to this site but have being so fascinated about this site, i really find it quite interesting to read different peoples comment on different issues. Am a learning developer and i just started working for this firm and basically the sofware they are using is Delphi, i don't know if there is anyone on this blog that is very familiar with that language I know its not like an everyday programming language but i will really appreciate it if there is anyone that will be of help to me. I hope i will get responses. Thank you
Fikzy (m)
Re: Let Share Codes
« #16 on: October 02, 2007, 12:46 PM »

@seluvsmayo
I am not conversant with delphi  but you can get tutorials corvering various aspect of Delphi from; http://www.delphibasics.co.uk/
seluvsmayo (f)
Re: Let Share Codes
« #17 on: October 02, 2007, 01:46 PM »

thanks fikzy, have being to the site already but its still not giving me all i need. thanks anyway for your quick reply.
Fikzy (m)
Re: Let Share Codes
« #18 on: October 04, 2007, 10:30 AM »

Smart K. (m)
Re: Let Share Codes
« #19 on: November 01, 2007, 07:14 PM »

c u guys morrow with something new. sorry for long-time-no-c. i have 2 busy lately.
scientist (m)
Re: Let Share Codes
« #20 on: November 02, 2007, 07:39 PM »

  Shocked Shocked Shocked Shocked  can i incorporate this code segment on a form in vb6.0 such that it enables me load pictures from a database?  e.g. ms access  Grin Grin Grin Grin
Kobojunkie
Re: Let Share Codes
« #21 on: November 02, 2007, 08:01 PM »

Quote from: scientist on November 02, 2007, 07:39 PM
  Shocked Shocked Shocked Shocked  can i incorporate this code segment on a form in vb6.0 such that it enables me load pictures from a database?  e.g. ms access  Grin Grin Grin Grin


You simply need to write an SQL Query/Stored procedure to return the dataset containing the information which you then attach to your datagridview control on the front end.

http://www.beansoftware.com/ASP.NET-Tutorials/Images-Database.aspx
scientist (m)
Re: Let Share Codes
« #22 on: November 03, 2007, 01:40 PM »

 Shocked wow, now this is getting even much more interesting. I've heard of stored procedures but don't know what they are and how they are used/implemented on vb 6.0 since I've never used them. I need more lectures on these areas stored procedures and also on modules/classes/collections etc  Grin Thanks
Kobojunkie
Re: Let Share Codes
« #23 on: November 03, 2007, 05:15 PM »

Here is how to learn of anything ,  go to www.google.com  type in Stored Procedures tutorial and select one of the many search results that follow,  There is a ton of information available to every developer free of charge online. All you have to do is search for it .

http://www.geekpedia.com/
Smart K. (m)
Re: Let Share Codes
« #24 on: November 05, 2007, 11:39 AM »

Hi guys,
I was doing a project recently and I needed to interact with server without post back. Guess wath I did: I created a webservice and called the webservice from client with javascript and i could now upate my UI with javascript. isn't that cool. I guess i may share some of the codes with u.
Note: this is for aspnet developers (the sample code is c# though simple enough to convert).

i. Create a webservice called MyService
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;

/// <summary>
/// Project:    Byaxiom  Service
/// Company:    Byaxiom Solutions Limited, http://www.byaxiom.com
/// Author:     I. A. Rahman
/// Created:    October 2007
/// </summary>
[WebService(Namespace = "http://www.byaxiom.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService()]
public class MyService : System.Web.Services.WebService
{
    public MyService()
    {
        //Uncomment the following line if using designed components
        //InitializeComponent();
    }

    public string doSomething(string tabID)
    {
      string retVal = "Up Smart.";//do your business logics here
        return retVal;   //return back to javascript
    }
}

ii. create an aspx code to consume the guy

      


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="default.aspx.cs" Inherits="default" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Poolsol Portal 1.0</title>
    <link href=", /stylesheets/main.css" rel="stylesheet" type="text/css" />
    <link href=", /stylesheets/content.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" language="javascript" src=", /scripts/moduleProcess.js"></script>

<script type="text/javascript" language="javascript" >
function doSomethingFromWebService(action){       
        MyService.doSomething(action, doSomethingComplete, doSomethingError, doSomethingTimeOut);             
    }


function doSomethingComplete(arg)
      {
         document.getElementsByID("<%ReturnTextBox.ClientID %>").value=arg;         
      }
function doSomethingTimeOut(arg)
      {
         alert("timeOut has occured");
      }
function doSomethingError(arg)
      {
         alert("error has occured: " + arg._message);
      }
            
</script>
</head>

<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
            <Services>
                <asp:ServiceReference Path="~/MyService.asmx" />
            </Services>
        </asp:ScriptManager>
        <table border="0" width="100%" style="border-collapse: collapse" id="mainTable">
            <tr>
                <td id="master_header_left" >&nbsp;<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="doSomethingFromWebService(1)" />
                    <asp:TextBox ID="ReturnTextBox" runat="server"></asp:TextBox></td>
            </tr>
</table>
</form>
</body>
</html>

SO, GOOD LUCK.

Kobojunkie
Re: Let Share Codes
« #25 on: November 05, 2007, 11:44 AM »

I worked on exactly same type of project. Calling server side code without postbacks from client side. I on the other hand did not have to use webservice, I instead made use of the ClientCallback objects in .NET ,  here is a sample and link


http://msdn2.microsoft.com/en-us/library/ms178210.aspx



using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class ClientCallback : System.Web.UI.Page,
     System.Web.UI.ICallbackEventHandler
{
    protected System.Collections.Specialized.ListDictionary catalog;
    protected String returnValue;
    protected void Page_Load(object sender, EventArgs e)
    {
        String cbReference =
            Page.ClientScript.GetCallbackEventReference(this,
            "arg", "ReceiveServerData", "context");
        String callbackScript;
        callbackScript = "function CallServer(arg, context)" +
            "{ " + cbReference + ";}";
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
            "CallServer", callbackScript, true);

        catalog = new System.Collections.Specialized.ListDictionary();
        catalog.Add("monitor", 12);
        catalog.Add("laptop", 10);
        catalog.Add("keyboard", 23);
        catalog.Add("mouse", 17);

        ListBox1.DataSource = catalog;
        ListBox1.DataTextField = "key";
        ListBox1.DataBind();

    }

    public void RaiseCallbackEvent(String eventArgument)
    {
        if (catalog[eventArgument] == null)
        {
            returnValue = "-1";
        }
        else
        {
            returnValue = catalog[eventArgument].ToString();
        }
    }
    public String GetCallbackResult()
    {
        return returnValue;
    }
}
lucianoefe (m)
Re: Let Share Codes
« #26 on: November 05, 2007, 12:04 PM »

[b] hey people, hw r yall doin? must commend the guy that started this blog,  it seems every body in this blog is too advanced 4 me. is there any other blog where the young developers can meet? i've just started studyin Java, got a supposed to be compiler but i don't know hw to test what i've studied. got it installed in my system though, but dnt knw hw to use it. can any body help? will be mo than grateful,  Wink[b]
Smart K. (m)
Re: Let Share Codes
« #27 on: November 05, 2007, 12:15 PM »

Quote
i've just started studyin Java, got a supposed to be compiler but i don't know hw to test what i've studied.

Have u installed SDK. Which compiler are u talking about? What editor are u using.

Quote
it seems every body in this blog is too advanced 4 me. is there any other blog where the young developers can meet?
You can ask your questions here or u can simply start your question on a thread if u feel its worthwhile.

Good Luck.
Smart K. (m)
Re: Let Share Codes
« #28 on: November 06, 2007, 09:45 AM »

DOT NET: Anyone looking for ways to avoid page refresh re-sending your data. Check out
http://jarednevans.typepad.com/technoblog/2005/01/jareds_techno_b.html
SayoMarvel (m)
Re: Let Share Codes
« #29 on: November 06, 2007, 10:42 AM »

I am Oladeji Oluwasayo. I'm a Java Programmer. I'm highly intrested in this sharing of code stuff. I'm still young in programming but i can still solve problems. my codes will come in classes and they will be fully indented. I have a problem in getting integers from text fields.

int s;
JTextField f = new JTextField();
s = f.getText();

the above snipet only works if s is a String. I want i to work for integer.
SayoMarvel (m)
Re: Let Share Codes
« #30 on: November 06, 2007, 10:54 AM »

you don't know how to use your java compiler?

install JDK (java development kit), set the path, and then go to cammand prompt, browse to
the folder where you hava your source code, and use the command "javac".
for example if your code is named wolf.java and it is in the root directory of your hard disk c.
then at command promt. type "cd\".
you will have something like this.  C:\>
then type "javac Wolf.java"
you will have "C:\>javac Wolf.java"
if your code contains no error. it will reurn to C:\>
then a class file will be generated. i.e Wolf.class
execute it by typing "java Wolf"
you will have C:\>java Wolf

the class file will be executed.

I do hope i've been able to solve your problem.

Smart K. (m)
Re: Let Share Codes
« #31 on: November 06, 2007, 11:04 AM »

Quote
int s;
JTextField f = new JTextField();
s = f.getText();

the above snipet only works if s is a String. I want i to work for integer.

try this man!

int s;
JTextField f = new JTextField();
s = Integer.parseInt( f.getText());
 Please Need Help With Writing These C++ Programmes Please This Is Really Urgent  Qbasic On Windows Xp  Why Nigerian Software Firms Are Absent On The Global Map  Page 2
Pages: (1) (2) Go Up Send Topic to Friend by E-mail Reply 
Google
 
Web www.nairaland.com
Sections: TV/Movies (2) Music/Radio (2) Celebrities Jobs (2) Career Romance Books Politics Sports Fashion Travel
Health Schooling Religion General(2) Business Webmaster Programming Computers Phones Cars & Trucks

Links: Page1 Page2 Page3 Page4 Page5 Page6 Page7 Page8 Page9 Page10

Nairaland is owned by Oluwaseun Osewa
Nairaland Forum | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.