Finding power source of laptop in c#
Posted by Bikash Karmokar in C# on October 7, 2013
Here i am going to write a simple process about how to detect whether your laptop running on battery or current. For this i create a simple windows form application.
A button is placed on the form. I just want to show the system so nothing added without this.
Double click on the button and on its click event write these codes:
private void button1_Click(object sender, EventArgs e)
{
PowerLineStatus status = SystemInformation.PowerStatus.PowerLineStatus;
if (status == PowerLineStatus.Offline)
{
MessageBox.Show(“Running on Battery”);
}
else
{
MessageBox.Show(“Running on Power”);
}
}
Its done. So simple. Try this.
Fun with code.
Important Things That Always Needs In Java
Posted by Bikash Karmokar in Java on September 16, 2013
1. Setting limited number after decimal point in java:
double relativeSpeed =3.125878;
java.text.DecimalFormat df = new java.text.DecimalFormat();
df.setMaximumFractionDigits(2);
String r = df.format(relativeSpeed);
System.out.println(r);
2. Converting string to int
String s = “123”;
int value = Integer.parseInt(s);
3. Converting int to string
int a = 3;
String str = Integer.toString(a);
Cookies In ASP.NET
Posted by Bikash Karmokar in ASP.NET on September 16, 2013
Cookies provide a means in Web applications to store user-specific information, such as history or user preferences. A cookie is a small bit of text that accompanies requests and responses as they go between the Web server and client. The cookie contains information that the Web application can read whenever the user visits the site.
The browser manages the cookies on client computers. Cookies are sent to the client using the HttpResponse object, which exposes a property called Cookies. Any cookies that you want your Web application to send to the browser must be added to this collection. When you write a new cookie, you must specify the Name and Value. Each cookie must have a unique name so that your Web application can identify it when the browser sends it with future requests.
There are two ways to write a cookie to a user’s computer. You can either directly set cookie properties on the Cookies collection or you can create an instance of the HttpCookie object and add it to the Cookies collection. You must create cookies before the ASP.NET page is rendered to the client. For example, you can write a cookie in a Page_Load event handler but not in a Page_Unload event handler.
To write a cookie by setting cookie properties on the Cookies collection:
The following code example shows a cookie named UserSettings with the values of the subkeys Font and Color set. It also sets the expiration time to be tomorrow.
C#:
Response.Cookies[“UserSettings”][“Font”] = “Arial”;
Response.Cookies[“UserSettings”][“Color”] = “Blue”;
Response.Cookies[“UserSettings”].Expires = DateTime.Now.AddDays(1d);
To write a cookie by creating an instance of the HttpCookie object:
C#:
HttpCookie myCookie = new HttpCookie(“UserSettings”);
myCookie[“Font”] = “Arial”;
myCookie[“Color”] = “Blue”;
myCookie.Expires = DateTime.Now.AddDays(1d);
Response.Cookies.Add(myCookie);
More Examples:
***********
Cookies with One Value:
******************
Response.Cookies[“userName”].Value = “Bikash”;
Response.Cookies[“userName”].Expires = DateTime.Now.AddDays(1);
HttpCookie aCookie = new HttpCookie(“lastVisit”);
aCookie.Value = DateTime.Now.ToString();
aCookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(aCookie);
Cookies with More Than One Value:
**************************
Response.Cookies[“userInfo”][“userName”] = “Bikash”;
Response.Cookies[“userInfo”][“lastVisit”] = DateTime.Now.ToString();
Response.Cookies[“userInfo”].Expires = DateTime.Now.AddDays(1);
HttpCookie aCookie = new HttpCookie(“userInfo”);
aCookie.Values[“userName”] = “Bikash”;
aCookie.Values[“lastVisit”] = DateTime.Now.ToString();
aCookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(aCookie);
By default, cookies are shared by all pages that are in the same domain, but you can limit cookies to specific subfolders in a Web site by setting their Path property. To allow a cookie to be retrieved by all pages in all folders of your application, set it from a page that is in the root folder of your application and do not set the Path property.
If you do not specify an expiration limit for the cookie, the cookie is not persisted to the client computer and it expires when the user session expires.
Cookies can store values only of type String. You must convert any non-string values to strings before you can store them in a cookie. For many data types, calling the ToString method is sufficient.
More Information:
*************
Most browsers support cookies of up to 4096 bytes.
Browsers also impose limitations on how many cookies your site can store on the user’s
computer. Most browsers allow only 20 cookies per site; if you try to store more,
the oldest cookies are discarded. Some browsers also put an absolute limit, usually
300, on the number of cookies they will accept from all sites combined.
In addition, a single cookie takes up about 50 characters for overhead (expiration information, and so on),
plus the length of the value that you store in it, all of which counts toward the 4096-byte limit.
If you store five subkeys instead of five separate cookies, you save the overhead of the separate
cookies and can save around 200 bytes.
Thanks to all
Bikash.
For any information please Mail me:
bikash_kuet@yahoo.com
Unable to update the EntitySet ‘yourTableName’ because it has a DefiningQuery and no element exists in the element to support the current operation.
Posted by Bikash Karmokar in ASP.NET, C# on December 5, 2012
Recently i am switching to MVC4 with Razor view engine for ASP.NET, C# web application. Tomorrow i was developing a blogging site where there were some works related to database. There i have created a table with 4 columns but none of them were made primary key.
When i tried to run the application the visual studio 2012 shows the error “Unable to update the EntitySet ‘UserTable’ because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation.” Here UserTable was my table name.
The database was sql server compact edition of visual studio 2012. I became confused about the error because this type of table with no primary key works well before. After a while i came to know that the problem was because of the lacking of primary key in the table. when i mark one of the columns as a primary key then the project run without error. This type of error was new to me so i thought to write down here so later on it may be helpful to someone like me.
Summary of the error and solution:
Problem: No primary key in the table
Solution: Add a primary key in the table
Happy Coding……….
Bikash, Software Engineer.
Find your GrameenPhone account balance or remaining MegaBytes for internet uses using Modem insted of Mobile phone
Posted by Bikash Karmokar in Miscellaneous on February 6, 2012
Most of us feel too much burden when we have to see our account balance or remaining megabytes because of changing simcard from modem to mobile phone. That’s why, to remove our burden we can use USSD activator plugins for GrameenPhone modem software. By using this we can find our account balance or remaining megabytes from the software. Then we do not need any mobile phone for knowing these necessary information. We can also know other information entering appropriate USSD numbers. This is an useful plugins for the GP users. Anyone can try this for better feelings.
To download the plugins click here. Install the plugins then restart the modem software. Then you will find USSD tab. Click on the that tab and start using.
Thanks for reading this post.
Bikash
Online learning and Batch learning
Posted by Bikash Karmokar in Neural Network on December 30, 2011
On line learning or stochastic learning:
Stochastic learning occurs when the neuron weights are updated after each individual piece of data is passed through the system. The Feed Forward Neural Network therefore changes with every piece of data and is in a constant state of change during training.
Batch learning:
Batch Learning on the other hand stores each neuron weight change when it occurs, and only at the end of each epoch does it update the weights with the net change over the training set. This means the neural network will only update once at the end of each epoch.
Errors in Visual Studio During Application Development in C#
Posted by Bikash Karmokar in C# on October 21, 2011
Error01: Unable to find manifest sigining certificate in the certification store.
Solution01:
To get rid of from this error right click on the project name in the solution explorer (not in solution) and click in the properties. Then go to the Signing.
Then uncheck the checkbox>> Sign the ClickOnce manifests. Its done.
Solution02:
Click on the Button Select from Store. A box will pop up name Windows Security. Click ok. Its done.
Now your program will run without error.
Enjoy C#.
Back Propagation Algorithm
Posted by Bikash Karmokar in Neural Network on August 7, 2011
The generalized delta rule also known as back propagation algorithm is explained here briefly for feed forward Neural Network (NN). The explanation here is intended to give an outline of the process involved in back propagation algorithm.
See the figure carefully and try to match with the explanation given below.
The NN explained here contains three layers. These are input, hidden, and output Layers. During the training phase, the training data is fed into to the input layer. The data is propagated to the hidden layer and then to the output layer. This is called the forward pass of the back propagation algorithm. In forward pass, each node in hidden layer gets input from all the nodes from input layer, which are multiplied with appropriate weights and then summed. The output of the hidden node is the non-linear transformation of the this resulting sum. Similarly each node in output layer gets input from all the nodes from hidden layer, which are multiplied with appropriate weights and then summed. The output of this node is the non-linear transformation of the resulting sum.
The output values of the output layer are compared with the target output values. The target output values are those that we attempt to teach our network. The error between actual output values and target output values is calculated and propagated back toward hidden layer. This is called the backward pass of the back propagation algorithm. The error is used to update the connection strengths between nodes, i.e. weight matrices between input-hidden layers and hidden-output layers are updated.
During the testing phase, no learning takes place i.e., weight matrices are not changed. Each test vector is fed into the input layer. The feed forward of the testing data is similar to the feed forward of the training data.
Windows7/8/8.1 installation from Pendrive
Posted by Bikash Karmokar in Miscellaneous on August 4, 2011
For installing windows7/8/8.1 from pendrive you need a pendrive(4GB or above) and windows 7/8/8.1 installation files.
Follow the instruction below for making Pendrive bootable for installation of windows7/8/8.1:
1. Plug-in your USB drive ( pendrive ).
Open cmd as administrator.
GO to start menu and then All programs>Accessories, then right click on Command Prompt and select Run as administrator.
2. Then write diskpart and press enter. A message will show. Then type list disk.
if you have one hard disk then two disk will show: Make sure which is your pendrive by seeing the size of the device or any other properties.
i assume your pendrive is disk1.
Now type each bold line and press enter:
select disk 1
clean
create partition primary
select partition 1
active
format fs=ntfs quick
assign
exit
don’t close cmd.
Now insert your windows7/8/8.1 DVD into DVD drive or If you have ISO file in your hard drive extract it to a folder.
let DVD drive letter is D( or let we extract it to D drive) and pendrive letter is H(check your own letter).
Now type the following command>
D: cd boot and press enter.
finally type bootsect.exe /nt60 H: and press enter.
Now copy your windows 7/8/8.1 files from your DVD(or from extracted folder) to pendrive and restart your pc for cheking the pendrive.
Remember you have to change boot device priority from bios and set usb device boot first>from disable to enable.
this is all.
thanks for reading this post.
Some of my projects
Posted by Bikash Karmokar in C# on August 3, 2011