C # Book Management system with source download _c# Tutorial

Source: Internet
Author: User
Tags rowcount

Used to practicing or good, share a look, or some new points! Ha ha

Is the custom DataGridView, facilitates each function part to call! Simple! REAFFIRM!!! The back source will be sent!

First look at the login, the above picture Bar!

Only Super admin and admin

Next look at the main interface


Change DataGridView Data Columns

DataGridView Custom Class

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using System.Windows.Forms;
Using System.Data.SqlClient;
Using System.Reflection;

Using System.Drawing; Namespace Common {public class Com {public void thread () {}///<summary>///datagridview Style///
   </summary>///<param name= "GridView" ></param> public void Exitgridview (DataGridView GridView) {
   Gridview.allowdrop = false;
   Gridview.allowusertoaddrows = false;
   Gridview.allowusertodeleterows = false;
   Gridview.allowusertoordercolumns = false;
  Gridview.allowusertoresizecolumns = false; ///<summary>///generates a list of functional buttons///</summary>///<param name= "name" ></param>///&LT;PA Ram Name= "GridView" ></param> public void AddColumn (string name, DataGridView GridView) {//Add Modify button Datag
   Ridviewbuttoncolumn C = new Datagridviewbuttoncolumn (); Sets the name of the column header cell C.text = Name
   The background color of the cell c.defaultcellstyle.backcolor = Color.lightgray;

   The background color when the cell is selected C.defaultcellstyle.selectionbackcolor = Color.darkgray;
   The default text for the cell C.usecolumntextforbuttonvalue = true;
   Cell width c.width = 60;
   Add a new Column object//When selected the background color is gray c.defaultcellstyle.selectionbackcolor = Color.lightgray;
   C.defaultcellstyle.selectionforecolor = Color.Black;
   C.fillweight = 50;
  GRIDVIEW.COLUMNS.ADD (c); ///<summary>///automatic generation columns did not modify and delete///</summary>///<param name= "HeaderText" &GT;&LT;/PARAM&G
  T <param name= "Datapropertynames" ></param>///<param name= "Grdiview" ></param> public void A Utocolumn (String HeaderText, String datapropertynames, DataGridView Grdiview) {//Remove automatically generated columns Grdiview.autogenerateco
   Lumns = false;
   GrdiView.RowHeadersDefaultCellStyle.SelectionBackColor = Color.darkgray;
   Method of generating row heading label Grdiview.datasource = System.Drawing.Imaging.ImageCodecInfo.GetImageDecoders (); Prevent user from changing DAtaGridView1 the column width of all columns Grdiview.allowusertoresizecolumns = false;
   Prevents the user from changing the row height Grdiview.allowusertoresizerows = False of all datagridview1の rows;
   Select whole line grdiview.selectionmode = Datagridviewselectionmode.fullrowselect;
   Grdiview.allowdrop = false;
   You cannot add rows grdiview.allowusertoaddrows = false;
   Row Grdiview.allowusertodeleterows = False can not be deleted;
   The column cannot be repositioned manually grdiview.allowusertoordercolumns = false;
   You cannot resize the column Grdiview.allowusertoresizecolumns = false;
   You cannot adjust the size of a row grdiview.allowusertoresizerows = false;
   Width of row header row grdiview.rowheaderswidth = 32;
   Cannot select multiple Grdiview.multiselect = false;
   Gets the heading style GrdiView.ColumnHeadersDefaultCellStyle.Alignment = Datagridviewcontentalignment.middlecenter;
   string[] Arrayheadertext = Headertext.split (', ');
   string[] Arraydatapropertynames = Datapropertynames.split (', '); for (int i = 0; i < arrayheadertext.length i++) {datagridviewtextboxcolumn d = new Datagridviewtextboxcolumn ()
    ; Bound database column Name
    D.datapropertyname = Arraydatapropertynames[i];
    Sets the name of the column header d.headertext = Arrayheadertext[i];
    The background color when the cell is selected D.defaultcellstyle.selectionbackcolor = Color.gainsboro;
    D.defaultcellstyle.selectionforecolor = Color.Black;
    The contents of the cell are centered d.defaultcellstyle.alignment = Datagridviewcontentalignment.middlecenter;
   GRDIVIEW.COLUMNS.ADD (d);
  } Grdiview.datasource = null; ///<summary>///found the data row that just added success s///</summary>///<param name= "A" ></param>///<pa Ram Name= "GridView" ></param> public void Autofindrow (string A, DataGridView GridView) {//Get DataGridView

   The total number of rows int rows = Gridview.rowcount; Locate the data row for which you just added success for (int i = 0; i < rows; i++) {String a = Gridview.rows[i]. Cells[0].
    Value.tostring (); if (a = = = a) {//select whole row gridview.rows[i].
     Selected = true;
    Vertical scroll bar, scrolling to the current row index position gridview.firstdisplayedscrollingrowindex = i; else {//clear full line Select GridView. Rows[i].
    Selected = false; {}}}///<summary>///found the data row that just added success///</summary>///<param name= "A" ></param>/ <param name= "GridView" ></param> public void Autofindrow (int A, DataGridView GridView) {//Get DataGrid

   Total number of rows in view int rows = Gridview.rowcount; Locate the data row for which you just added success for (int i = 0; i < rows; i++) {int a = (int) gridview.rows[i]. Cells[0].
    Value; if (a = = = a) {//select whole row gridview.rows[i].
     Selected = true;
    Vertical scroll bar, scrolling to the current row index position gridview.firstdisplayedscrollingrowindex = i; else {//clear full line check gridview.rows[i].
    Selected = false; 

 }
   }
  }
 }
}

Pretty simple   It is the book Management load data method  

private void Bookinfomanager_ui_load (object sender, EventArgs e) {#region DataGridView1 binding//column header string to add column Stri
   ng Arraysheadertext = @ "book number, book name, registration time, book type, author, pinyin code, translation, language, page, price, printing layout, storage location, Isbs code, version, description"; String arraysname = @ "bookid,bookname,timein,booktypename,author,pinyincode,translator,language that requires binding database column names.


   Booknumber,price,layout,address,isbs,versions,bookremark "; Automatic generation of columns Autocoumns.
   Autocolumn (Arraysheadertext, Arraysname, dataGridView1); Datagridview1.datasource = Bookinfo_bll.selectbookinfo1 ().
   Tables[0]; Autocoumns.
   AddColumn ("modification", dataGridView1); Autocoumns.

   AddColumn ("delete", dataGridView1); DataGridView1 DataSet Binding This.dataGridView1.DataSource = Bookinfo_bll.selectbookinfo1 ().
   Tables[0]; Default hidden column this.datagridview1.columns[14 when form is loaded].
   Visible = false; THIS.DATAGRIDVIEW1.COLUMNS[13].
   Visible = false; THIS.DATAGRIDVIEW1.COLUMNS[12].
   Visible = false; THIS.DATAGRIDVIEW1.COLUMNS[11].
   Visible = false; THIS.DATAGRIDVIEW1.COLUMNS[10]. ViSible = false;

   #endregion #region Drop-down Box binding datagridviewcolumncollection columns = datagridview1.columns; for (int i = 0; i < columns. Count-2; i++) {comboBox1.Items.Add (columns[i].
   HeaderText);
   } comboBox1.Items.Insert (0, "all");

   Combobox1.selectedindex = 0;

   The binding Treeviewband () of #endregion #region tree graph;
   #endregion #region dgvhostory Binding string Header1 = @ "book number, book name, reader number, reader name, loan time, book should return time, actual return time, payable fine, renewal times, borrow also description"; String PropertyNames1 = @ "Bookid,bookname,readerid,readername,borrowtime,returntime,factreturntime,fine,
   Renewcount,borrowremark "; Automatic generation of columns Autocoumns.

   Autocolumn (Header1, PropertyNames1, dgvhostory);

 #endregion}

SOURCE Download: Http://xiazai.jb51.net/201609/yuanma/C

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

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.