C#圖書管理系統(tǒng) 附源碼下載
用來練手還是不錯(cuò)的,分享大家看一下,還是一些新穎點(diǎn)的!哈哈
就是自定義DataGridView,方便每個(gè)功能部分調(diào)用!簡單!再次重申?。。『竺嬖创a會(huì)送上!
首先看一下登錄,上圖吧!

只有超級(jí)管理員跟管理員
接下來看一下主界面

更改DataGridView數(shù)據(jù)列

datagridView自定義類
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的樣式
/// </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>
/// 生成一列有功能的按鈕
/// </summary>
/// <param name="name"></param>
/// <param name="GridView"></param>
public void AddColumn(string name, DataGridView GridView)
{
//添加修改按鈕
DataGridViewButtonColumn c = new DataGridViewButtonColumn();
//設(shè)置列標(biāo)題單元格的名稱
c.Text = name;
//單元格的背景色
c.DefaultCellStyle.BackColor = Color.LightGray;
//單元格選定時(shí)的背景色
c.DefaultCellStyle.SelectionBackColor = Color.DarkGray;
//單元格的默認(rèn)文本
c.UseColumnTextForButtonValue = true;
//單元格寬
c.Width = 60;
//添加新的一列對(duì)象
//選中時(shí)背景色為灰色
c.DefaultCellStyle.SelectionBackColor = Color.LightGray;
c.DefaultCellStyle.SelectionForeColor = Color.Black;
c.FillWeight = 50;
GridView.Columns.Add(c);
}
/// <summary>
/// 自動(dòng)生成columns 沒有修改和刪除
/// </summary>
/// <param name="HeaderText"></param>
/// <param name="DataPropertyNames"></param>
/// <param name="GrdiView"></param>
public void AutoColumn(string HeaderText, string DataPropertyNames, DataGridView GrdiView)
{
//去掉自動(dòng)生成的列
GrdiView.AutoGenerateColumns = false;
GrdiView.RowHeadersDefaultCellStyle.SelectionBackColor = Color.DarkGray;
//生成行標(biāo)題標(biāo)號(hào)的方法
GrdiView.DataSource = System.Drawing.Imaging.ImageCodecInfo.GetImageDecoders();
// 禁止用戶改變DataGridView1的所有列的列寬
GrdiView.AllowUserToResizeColumns = false;
//禁止用戶改變DataGridView1の所有行的行高
GrdiView.AllowUserToResizeRows = false;
//選擇整行
GrdiView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
GrdiView.AllowDrop = false;
//不可以添加行
GrdiView.AllowUserToAddRows = false;
//不可以刪除行
GrdiView.AllowUserToDeleteRows = false;
//不可以手動(dòng)對(duì)列重新定位
GrdiView.AllowUserToOrderColumns = false;
//不可以調(diào)整列的大小
GrdiView.AllowUserToResizeColumns = false;
//不可以調(diào)整行的大小
GrdiView.AllowUserToResizeRows = false;
//行標(biāo)題行的寬度
GrdiView.RowHeadersWidth = 32;
//不能多選
GrdiView.MultiSelect = false;
//獲取標(biāo)題樣式
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();
//綁定數(shù)據(jù)庫列名稱
d.DataPropertyName = arrayDataPropertyNames[i];
//設(shè)置列標(biāo)題的名稱
d.HeaderText = arrayHeaderText[i];
//單元格選定時(shí)的背景色
d.DefaultCellStyle.SelectionBackColor = Color.Gainsboro;
d.DefaultCellStyle.SelectionForeColor = Color.Black;
//單元格的內(nèi)容居中
d.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
GrdiView.Columns.Add(d);
}
GrdiView.DataSource = null;
}
/// <summary>
/// 找到剛剛添加成功的數(shù)據(jù)行s
/// </summary>
/// <param name="A"></param>
/// <param name="GridView"></param>
public void AutoFindRow(string A, DataGridView GridView)
{
//獲取DataGridView中的總行數(shù)
int rows = GridView.RowCount;
//找到剛剛添加成功的數(shù)據(jù)行
for (int i = 0; i < rows; i++)
{
string a = GridView.Rows[i].Cells[0].Value.ToString();
if (a == A)
{
//選中整行
GridView.Rows[i].Selected = true;
//垂直滾動(dòng)條,滾動(dòng)到當(dāng)前行索引位置
GridView.FirstDisplayedScrollingRowIndex = i;
}
else
{
//清楚整行選中
GridView.Rows[i].Selected = false;
}
}
}
/// <summary>
/// 找到剛剛添加成功的數(shù)據(jù)行
/// </summary>
/// <param name="A"></param>
/// <param name="GridView"></param>
public void AutoFindRow(int A, DataGridView GridView)
{
//獲取DataGridView中的總行數(shù)
int rows = GridView.RowCount;
//找到剛剛添加成功的數(shù)據(jù)行
for (int i = 0; i < rows; i++)
{
int a = (int)GridView.Rows[i].Cells[0].Value;
if (a == A)
{
//選中整行
GridView.Rows[i].Selected = true;
//垂直滾動(dòng)條,滾動(dòng)到當(dāng)前行索引位置
GridView.FirstDisplayedScrollingRowIndex = i;
}
else
{
//清楚整行選中
GridView.Rows[i].Selected = false;
}
}
}
}
}
挺簡單的 一下是圖書管理加載的數(shù)據(jù)方法
private void BookInfoManager_UI_Load(object sender, EventArgs e)
{
#region DataGridView1綁定
//需要添加列的列標(biāo)題字符串
string arraysHeaderText = @"圖書編號(hào),圖書名稱,登記時(shí)間,圖書類型,作者,拼音碼,翻譯,語言,頁數(shù),價(jià)格,印刷版面,存放位置,ISBS碼,版本,描述";
//需要綁定數(shù)據(jù)庫列名稱的字符串
string arraysName = @"BookId,BookName,TimeIn,BookTypeName,Author,PinYinCode,Translator,Language,BookNumber,Price,Layout,Address,ISBS,Versions,BookRemark";
//自動(dòng)生成columns
autocoumns.AutoColumn(arraysHeaderText, arraysName, dataGridView1);
dataGridView1.DataSource = bookInfo_bll.selectBookInfo1().Tables[0];
autocoumns.AddColumn("修改", dataGridView1);
autocoumns.AddColumn("刪除", dataGridView1);
//DataGridView1數(shù)據(jù)集綁定
this.dataGridView1.DataSource = bookInfo_bll.selectBookInfo1().Tables[0];
//窗體加載時(shí)默認(rèn)隱藏的列
this.dataGridView1.Columns[14].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 下拉框綁定
DataGridViewColumnCollection columns = dataGridView1.Columns;
for (int i = 0; i < columns.Count - 2; i++)
{
comboBox1.Items.Add(columns[i].HeaderText);
}
comboBox1.Items.Insert(0, "全部");
comboBox1.SelectedIndex = 0;
#endregion
#region 樹狀圖的綁定
TreeViewBand();
#endregion
#region DgvHostory綁定
string Header1 = @"圖書編號(hào),圖書名稱,讀者編號(hào),讀者名稱,借出時(shí)間,書應(yīng)歸還時(shí)間,實(shí)際歸還時(shí)間,應(yīng)付罰金,續(xù)借次數(shù),借還描述";
string PropertyNames1 = @"BookId,BookName,ReaderId,ReaderName,BorrowTime,ReturnTime,FactReturnTime,Fine,RenewCount,BorrowRemark";
//自動(dòng)生成columns
autocoumns.AutoColumn(Header1, PropertyNames1, dgvHostory);
#endregion
}
源碼下載:Csharplibrary(jb51.net).rar
關(guān)于管理系統(tǒng)的更多內(nèi)容請(qǐng)點(diǎn)擊《管理系統(tǒng)專題》進(jìn)行學(xué)習(xí)
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C#簡易圖片格式轉(zhuǎn)換器實(shí)現(xiàn)方法
這篇文章主要介紹了C#簡易圖片格式轉(zhuǎn)換器實(shí)現(xiàn)方法,涉及C#基于WinForm操作圖片的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-11-11
使用C#實(shí)現(xiàn)Windows組和用戶管理的示例代碼
這篇文章主要介紹了使用C#實(shí)現(xiàn)Windows組和用戶管理的示例代碼,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下2021-01-01
C#通過經(jīng)緯度計(jì)算2個(gè)點(diǎn)之間距離的實(shí)現(xiàn)代碼
這篇文章主要介紹了C#通過經(jīng)緯度計(jì)算2個(gè)點(diǎn)之間距離實(shí)現(xiàn)代碼,本文對(duì)實(shí)現(xiàn)原理、經(jīng)緯度基本知識(shí)等一并做了講解,需要的朋友可以參考下2014-08-08
深入分析C#鍵盤勾子(Hook)攔截器,屏蔽鍵盤活動(dòng)的詳解
本篇文章是對(duì)C#鍵盤勾子(Hook)攔截器,屏蔽鍵盤活動(dòng)進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05
C# WinForm實(shí)現(xiàn)鼠標(biāo)穿透功能
在WinForm開發(fā)時(shí),會(huì)用到這樣一個(gè)場景,給屏幕增加水印Logo,但不影響畫面的操作,這里就會(huì)用到鼠標(biāo)穿透功能,下面我們就來學(xué)習(xí)一下鼠標(biāo)穿透功能的具體實(shí)現(xiàn)吧2023-11-11
C#使用CefSharp實(shí)現(xiàn)內(nèi)嵌網(wǎng)頁詳解
這篇文章主要介紹了C# WPF里怎么使用CefSharp嵌入一個(gè)網(wǎng)頁,并給出一個(gè)簡單示例演示C#和網(wǎng)頁(JS)的交互實(shí)現(xiàn),感興趣的小伙伴可以了解一下2023-04-04
.NET中保證線程安全的高級(jí)方法Interlocked類使用介紹
這篇文章主要介紹了.NET中保證線程安全的高級(jí)方法Interlocked類使用介紹,Interlocked類可以為為多個(gè)線程共享的變量提供原子操作,需要的朋友可以參考下2014-07-07

