|
Smart K. (m)
|
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
|
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)
|
@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
|
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)
|
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)
|
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)
|
Sorry Fikzy, will get back to u before end of work today. i have been very busy lately.
|
|
|
|
|
|
Fikzy (m)
|
@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)
|
@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)
|
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)
|
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
|
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.
|
|
|
|
|
|
|
|
ritchboi
|
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
|
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)
|
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
|
|
|
|
|
|
|
|
seluvsmayo (f)
|
thanks fikzy, have being to the site already but its still not giving me all i need. thanks anyway for your quick reply.
|
|
|
|
|
|
|
|
Smart K. (m)
|
c u guys morrow with something new. sorry for long-time-no-c. i have 2 busy lately.
|
|
|
|
|
|
|
|
|
|
scientist (m)
|
 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  Thanks
|
|
|
|
|
|
Kobojunkie
|
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)
|
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" > <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
|
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.aspxusing 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)
|
[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,  [b]
|
|
|
|
|
|
Smart K. (m)
|
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. 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.
|
|
|
|
|
|
|
|
SayoMarvel (m)
|
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)
|
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)
|
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());
|
|
|
|
|
|