Developing a database application system using C #

Source: Internet
Author: User

Developing a database application system using C #

Chapter I. Notes

1: Initial windows:

In Visual Studio, there are two types of edits in the form file that WinForm applies to:

----1: Form Designer

----2: Code Editor

2: Steps to create a Windows application in VS:

----1> New Project

----2> Project type: visualc# Project

----3> Templates

3:windows Applications:

There are a lot of projects in a solution.

Main program file contains main () method

The main () method is the Windows program entry

Change the startup form by modifying the main () method in program debugging

4: Use partial to separate the code of the same form into two files:

----A store vs auto-generated code

----A code to store our own writing

Form1:form-------Colon indicates inheritance. Like a child inherits the characteristics of the parents all forms inherit form

5: constructor: Do a bit of initialization work

Form title: Icon for the Name form: Icons background icon: backgroundimage background color: backgroundcolor

Maximize button: Maximinbox Minimize button: Minimun form border Style: FormBorderStyle

Form initial position: StartPosition form State: Windowsstate

6: Naming specification prefix:

Control Name: Control class Name: Name prefix:

Tag Label IbI

Text box textbox txt

Combo Box ComboBox CBO

Pushbutton button BTN

Normalization of naming can improve the readability and maintainability of programs

Main properties of the text box:

Max Length: Specifies the maximum number of hungry strings entered in the text box

Mulitiline: Indicates whether multiple lines of text can be entered in the text box

PasswordChar: Indicates the character that is displayed in the text box when it is used as a password box. Instead of the actual input text

ReadOnly: Specifies whether text boxes are allowed to be edited

Text: Texts associated with text

Properties of the combo box:

Items: item in a combo box

DropDownStyle: Defines the style of the combo box, indicating whether the list box section is displayed, whether the user is allowed to edit parts of the text box

Text: Texts associated with a combo box

SelectedIndex: The index number of the currently selected item, and each item in the list box has an index number. Start from scratch

SelectedItem: Gets the currently selected item

Event: Description:

Click: Occurs when a single-machine control

Selecteddindexchanged: Occurs after the Selecteddindex property has been modified

Main properties of the button:

Enable: A Boolean value that indicates whether the control is available. True indicates available, False indicates not available, and if the control is not available, it appears dimmed after running.

Text: button to display the texts

TextAlign: The text on the button is on its way

To write an event handler:

(1): The form of a single machine to create event-handling programs or control

(2): In the Properties window, click the Events button (the character of the Lightning Bolt)

(3): Double-click the method to navigate to event handling for the event you want to handle

(4): Write processing code

MessageBox message Box:

====1: The simplest message box:

MessageBox.Show ("string to display");

====2: Message box with caption:

MessageBox.Show ("The string to display, the title of the message box");

====3: Message box with caption, Button:

MessageBox.Show ("To Reality message box, message box caption, message box button");

====4: Message box with caption, button, icon:

MessageBox.Show ("To display the message box, the message box header, the Message box button, the message box icon");

This chapter summarizes

====1: Use the form's properties to design the form, the properties commonly used by the form are formborderstyle,startposition,windowstate, and so on:

====2: Use the label (label) textbox (TextBox) combo box (ComboBox) button to design the form's interface, which have common properties, such as name text, Enable: also has its own properties:

====3: Write event Handlers: and write appropriate handling for user-triggered events

====4: Use the form's show () method and the Hide () method to implement the form display and hide;

====5: Define fields in a form to implement data transfer for a form

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Data.SqlClient;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespaceFirst Chapter { Public Partial classFrmmain:form {//Connection String        Private Const stringSqlcon ="Data Source=.;i Nitial Catalog=myschool; User Id=sa; pwd=."; //used to turn database connections on/offSqlConnection con =NewSqlConnection (Sqlcon); //construction method: Used to do initialization work         PublicFrmmain () {InitializeComponent (); }        //Cancel button's Click event        Private voidBtnexit_click (Objectsender, EventArgs e) {DialogResult result= MessageBox.Show ("do you want to cancel? ","Tips", Messageboxbuttons.yesno); if(Result = =dialogresult.yes) {//Close the form                 This.            Close (); }            Else            {                //Clear all information in the form                 This. Txtname.clear ();  This. Txtpwd.clear ();  This. Cborow. SelectedIndex =-1 ; }                               }        //Click events for the login button        Private voidBtnok_click (Objectsender, EventArgs e) {            if(Checkinput ()) {Try{con.                    Open (); stringsql ="Select COUNT (*) from Student where studentno= '"+ This. txtName.Text +"' and loginpwd= '"+ This. Txtpwd.text +"'"; SqlCommand com=NewSqlCommand (sql, con); intCount = (int) com.                    ExecuteScalar (); if(Count >0) {MessageBox.Show ("Landing Success! ","Tips"); //Create a frmtest formFrmtest test =Newfrmtest (); //test represents the Frmtest form. Test is the title .Test.txtshow.Text ="you are welcome:"+ This. txtName.Text; Test.                                           Show (); }                    Else{MessageBox.Show ("Login failed! ","Tips");  This. Txtname.clear ();  This. Txtpwd.clear ();  This. Cborow. SelectedIndex =-1; }                }                Catch(Exception ex) {Console.WriteLine (ex); }                finally{con.                Close (); }                           }        }        //Verify that the contents of the text box are empty when you click the login button        Private BOOLCheckinput () {BOOLFlag =true; //Determine if the text box has entered a value? //determine if the txtname has entered a value            if( This. TxtName.Text.Trim () = =NULL|| This. TxtName.Text.Trim () = ="")            {                //Prompt InformationMessageBox.Show ("Please enter your login account! ","Login Verification"); Flag=false; }Else if( This. TxtPwd.Text.Trim () = =NULL|| This. TxtPwd.Text.Trim () = ="")            {                //Prompt InformationMessageBox.Show ("Please enter your login password! ","Login Verification"); Flag=false; }            Else if( This. Cborow. Text.trim () = =NULL|| This. Cborow. Text.trim () = ="") {MessageBox.Show ("Please select login role! ","Login Verification"); Flag=false; }            returnFlag; }    }}

Developing a database application system using C #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.