正则表达式生成工具:
RegexDesigner.NET
存储过程生成工具:
CodeSmithStudio.exe
企业图库:
Enterprise
Library - January 2006
第三方控件:
Infragistics NetAdvantage 2005 Volume 3 CLR 2.0
远程控件工具:
DameWare Mini Remote Control
1.DataGridView
控件禁用点击列头排序
dataGridView1.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
2.隐藏DataGridView1的第一列
this.DataGridView1.RowHeadersVisiable = false;
3.阻止模式窗体关闭
this.DialogResult = DialogResult.None;
4.Enter
键转
Tab
键
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
switch (keyData)
{
case Keys.Enter:
if (ActiveControl is Button)
{
((Button)ActiveControl).PerformClick();
}
else
{
SendKeys.Send("{TAB}");
}
return true;
case Keys.Left://按'向左键',光标往回跳.
if (ActiveControl is TextBox)
{
TextBox tb = (TextBox)ActiveControl;
if (tb.SelectionStart == 0)
{
SendKeys.Send("+{tab}");
return true;
}
}
if (ActiveControl is ComboBox)
{
ComboBox cb = (ComboBox)ActiveControl;
if (cb.SelectionStart == 0)
{
SendKeys.Send("+{tab}");
return true;
}
}
if (ActiveControl is SinGao.Common.Control.ComboBoxSC)
{
SinGao.Common.Control.ComboBoxSC auto = (SinGao.Common.Control.ComboBoxSC)ActiveControl;
if (auto.ComboBox.SelectionStart == 0)
{
SendKeys.Send("+{tab}");
return true;
}
}
break;
case Keys.Right://按'向右键',光标往前跳.
if (ActiveControl is TextBox)
{
TextBox tb = (TextBox)ActiveControl;
if (tb.SelectionStart == tb.Text.Length)
{
SendKeys.Send("{tab}");
return true;
}
}
if (ActiveControl is ComboBox)
{
ComboBox cb = (ComboBox)ActiveControl;
if (cb.SelectionStart == cb.Text.Length)
{
SendKeys.Send("{tab}");
return true;
}
}
if (ActiveControl is SinGao.Common.Control.ComboBoxSC)
{
SinGao.Common.Control.ComboBoxSC auto = (SinGao.Common.Control.ComboBoxSC)ActiveControl;
if (auto.ComboBox.SelectionStart == auto.Text.Length)
{
SendKeys.Send("{tab}");
return true;
}
}
break;
}
return base.ProcessCmdKey(ref msg, keyData);
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Enter)
{
if (ActiveControl is Button)
{
((Button)ActiveControl).PerformClick();
}
else
{
SendKeys.Send("{TAB}");
}
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
protected
override
bool
ProcessCmdKey(
ref
Message
msg,
Keys
keyData)
{
if
(keyData ==
Keys
.Enter)
{
if
(ActiveControl
is
Button
)
{
((
Button
)ActiveControl).PerformClick();
}
else
{
SendKeys
.Send("{TAB}");
}
return
true
;
}
return
base
.ProcessCmdKey(ref msg, keyData);
}
5.
项目字体设置
字体:Courier New,大小:11
把显示项列表中的条目全部设置成“粗体”。
System.TimeSpan sp = new TimeSpan(0,100,0);//100分钟
sp.ToString();//输出"01:40:00"
项目黙认字体一般设为10号字体,以适应不同的分辨率。
//
从
Excel
读取数据
static
public
DataTable
ImputExcel(
string
TableName,
string
FileName)
{
String
sConnectionString=
"provider=Microsoft.Jet.OLEDB.4.0; "
+
"data source="
;
sConnectionString += FileName +
";"
+
"Extended Properties=Excel 8.0;"
;
string
sql=
string
.Empty;
sql =
"SELECT * FROM ["
+TableName+"$]";
OleDbConnection
conn;
try
{
conn =
new
OleDbConnection
(sConnectionString);
}
catch
(
Exception
ex)
{
MessageBox
.Show(ex.Message, "
连接字符串错误
"
,
MessageBoxButtons
.OK, MessageBoxIcon.Error);
return
null
;
}
OleDbCommand
cmd =
new
OleDbCommand
(sql,conn);
OleDbDataAdapter
dataAdapter =
new
OleDbDataAdapter
();
dataAdapter.SelectCommand = cmd;
DataTable
dataTable=
new
DataTable
();
try
{
dataAdapter.Fill(dataTable);
}
catch
(
Exception
ex)
{
MessageBox
.Show(ex.Message, "
读取
Excel
错误
"
,
MessageBoxButtons
.OK, MessageBoxIcon.Error);
return
null
;
}
return
dataTable;
}
//
把数据导出到
Excel
中
static
public
void
OutputExcel(
DataTable
OutputDataTable,
string
saveFileName)
{
bool
fileSaved =
false
;
string
mySql =
string
.Empty;
string
helpSql =
string
.Empty;
string
FileName = OutputDataTable.TableName;
Excel.
Application
xlApp =
new
Excel.
Application
();
if
(xlApp ==
null
)
{
MessageBox
.Show("
无法创建
Excel
对象,可能您的机子未安装
Excel"
);
return
;
}
Excel.
Workbooks
workbooks = xlApp.Workbooks;
Excel.
Workbook
workbook = workbooks.Add(Excel.
XlWBATemplate
.xlWBATWorksheet);
Excel.
Worksheet
worksheet = (Excel.
Worksheet
)workbook.Worksheets[1];
//
取得
sheet1
workbooks.OpenXML(saveFileName, Excel.
XlSheetType
.xlWorksheet, LoadOption.Upsert);
worksheet.Name = FileName;
//
写入字段
for
(
int
i = 0; i < OutputDataTable.Columns.Count; i++)
{
string
columnName = OutputDataTable.Columns[i].ColumnName;
worksheet.Cells[1, i + 1] = columnName;
mySql += columnName +
","
;
helpSql +=
"?,"
;
}
mySql = mySql.Substring(0, mySql.Length - 1);
helpSql = helpSql.Substring(0, helpSql.Length - 1);
string
sqlInsert =
"INSERT INTO ["
+ FileName +
"$]"
+
"("
+ mySql +
")"
+
" values "
+
"("
+helpSql+
")"
;
//INSERT INTO [Sheet1$] (F1, F2) values (?, ?)
//
保存
Excel
try
{
workbook.Saved =
true
;
workbook.SaveCopyAs(saveFileName);
fileSaved =
true
;
}
catch
(
Exception
ex)
{
fileSaved =
false
;
MessageBox
.Show("
导出文件时出错
,
文件可能正被打开!
/n"
+ ex.Message);
}
xlApp.Quit();
//
关闭
EXCEL
GC
.Collect();
//
读取
Excel
架构
if
(fileSaved ==
true
)
{
String
sConnectionString =
"provider=Microsoft.Jet.OLEDB.4.0; "
+
"data source="
;
sConnectionString += saveFileName +
";"
+
"Extended Properties=Excel 8.0;"
;
string
sql =
string
.Empty;
sql =
"SELECT * FROM ["
+ FileName +
"$]"
;
OleDbConnection
conn;
try
{
conn =
new
OleDbConnection
(sConnectionString);
}
catch
(
Exception
ex)
{
MessageBox
.Show(ex.Message, "
连接字符串错误
"
,
MessageBoxButtons
.OK, MessageBoxIcon.Error);
return
;
}
OleDbCommand
cmd =
new
OleDbCommand
(sql, conn);
OleDbDataAdapter
dataAdapter =
new
OleDbDataAdapter
();
dataAdapter.SelectCommand = cmd;
OleDbCommand
cmd2 =
new
OleDbCommand
(sqlInsert, conn);
dataAdapter.InsertCommand = cmd2;
DataTable
dataTable =
new
DataTable
();
try
{
dataAdapter.Fill(dataTable);
}
catch
(
Exception
ex)
{
MessageBox
.Show(ex.Message, "
读取
Excel
错误
"
,
MessageBoxButtons
.OK, MessageBoxIcon.Error);
return
;
}
conn.Open();
foreach
(
DataRow
dr
in
OutputDataTable.Rows)
{
foreach
(
DataColumn
dc
in
dataTable.Columns)
{
cmd2.Parameters.AddWithValue(dc.ColumnName, dr[dc.ColumnName]);
}
//cmd2.ExecuteNonQuery();
}
conn.Close();
}
}
///
<summary>
///
全角转半角
///
</summary>
///
<param name="input"></param>
///
<returns></returns>
public
static
string
全角转半角
(
string
input)
{
char
[] c = input.ToCharArray();
for
(
int
i = 0; i < c.Length; i++)
{
if
(c[i] == 12288)
{
c[i] = (
char
)32;
continue
;
}
if
(c[i] > 65280 && c[i] < 65375)
{
c[i] = (
char
)(c[i] - 65248);
}
}
return
new
string
(c);
}
///
<summary>
///
验证身份证
///
</summary>
///
<returns></returns>
static
public
bool
IsValidateSfz(
string
身份证
)
{
string
modul =
@"^[1-9]([0-9]{16}|[0-9]{13})[xX0-9]$"
;
bool
bl=!
Regex
.IsMatch(
身份证
,modul);
return
bl;
}
权限设计
货物管理
|-------出货管理
|-------进货管理
|-------库存管理
|-------滞货管理
运输管理
|-------发车管理
|-------配车管理
|-------购车管理
出货管理: A浏览 B增加 C修改 D删除
操作表——A浏览 B增加 C修改 D删除 ……
栏目表——出货管理 进货管理 ……
授权表——栏目表与操作表记录的组合 [出货管理-A浏览] [出货管理-B增加]
角色表——一个角色包含若干授权表记录,一个授权表记录包含于若干角色中,多对多关系
用户表——用户与角色多对多关系
设置数据库
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Text;
using
System.Windows.Forms;
using
System.Configuration;
namespace
SinGao.
人事
{
public
partial
class
数据库设置
:
Form
{
public
数据库设置
()
{
InitializeComponent();
}
Configuration
config;
private
void
数据库设置
_Load(
object
sender,
EventArgs
e)
{
config =
ConfigurationManager
.OpenExeConfiguration(ConfigurationUserLevel.None);
string
conn=config.ConnectionStrings.ConnectionStrings[1].ConnectionString;
int
start,end;
start=conn.IndexOf(
'='
)+1;
end=conn.IndexOf(
';'
);
txt
数据库
.Text = conn.Substring(start, end - start);
start = conn.IndexOf(
'='
, end)+1;
end = conn.IndexOf(
';'
, end + 1);
txt
服务器
.Text = conn.Substring(start, end - start);
start = conn.IndexOf(
'='
, end)+1;
end = conn.IndexOf(
';'
, end + 1);
txt
用户名
.Text = conn.Substring(start, end - start);
start = conn.IndexOf(
'='
, end)+1;
end = conn.IndexOf(
';'
, end + 1);
txt
密码
.Text = conn.Substring(start, end - start);
//"Database=newsinco;Server=192.168.0.66;uid=sa;pwd=aaa;Connection Reset=FALSE"
}
private
void
btn
确定
_Click(
object
sender,
EventArgs
e)
{
if
(
验证文本
() ==
true
)
{
string
conn =
"Database="
+ txt
数据库
.Text +
";Server="
+ txt
服务器
.Text +
";uid="
+ txt
用户名
.Text +
";pwd="
+ txt
密码
.Text +
";Connection Reset=FALSE"
;
config.ConnectionStrings.ConnectionStrings[1].ConnectionString = conn;
config.Save();
MessageBox
.Show("
数据库已成功配置
,
重新启动后生效
"
,
"
数据库配置
"
,
MessageBoxButtons
.OK, MessageBoxIcon.Information);
}
}
private
bool
验证文本
()
{
txt
服务器
.Text = txt
服务器
.Text.Trim();
txt
数据库
.Text=txt
数据库
.Text.Trim();
txt
用户名
.Text = txt
用户名
.Text.Trim();
txt
密码
.Text = txt
密码
.Text.Trim();
bool
bl =
false
;
if
(txt
服务器
.Text ==
string
.Empty)
{
MessageBox
.Show("
请输入服务器名称
"
,
"
验证失败
"
,
MessageBoxButtons
.OK, MessageBoxIcon.Error);
txt
服务器
.Focus();
return
bl;
}
if
(txt
数据库
.Text ==
string
.Empty)
{
MessageBox
.Show("
请输入数据库名称
"
,
"
验证失败
"
,
MessageBoxButtons
.OK, MessageBoxIcon.Error);
txt
数据库
.Focus();
return
bl;
}
if
(txt
用户名
.Text ==
string
.Empty)
{
MessageBox
.Show("
请输入用户名
"
,
"
验证失败
"
,
MessageBoxButtons
.OK, MessageBoxIcon.Error);
txt
用户名
.Focus();
return
bl;
}
if
(txt
密码
.Text ==
string
.Empty)
{
MessageBox
.Show("
请输入密码
"
,
"
验证失败
"
,
MessageBoxButtons
.OK, MessageBoxIcon.Error);
txt
密码
.Focus();
return
bl;
}
bl =
true
;
return
bl;
}
protected
override
bool
ProcessCmdKey(
ref
Message
msg,
Keys
keyData)
{
if
(keyData ==
Keys
.Enter)
{
if
(ActiveControl
is
Button
)
{
((
Button
)ActiveControl).PerformClick();
}
else
{
SendKeys
.Send("{TAB}");
}
return
true
;
}
return
base
.ProcessCmdKey(ref msg, keyData);
}
}
}
VS.NET2005
捆绑的
crystal report
有什么限制?
是否需要付费买许可
有限制,有并发数限制,要在部暑的服务器里的注册表做修改,否则访问过量就出错误页
具体为修改下面两个键的值。
HKEY_LOCAL_MACHINE;SOFTWARE;Crystal Decisions;10.0;Report Application
Server;InprocServer;PrintJobLimit
修改为1000
还有一个HKEY_LOCAL_MACHINE;SOFTWARE;Crystal Decisions;10.0;Report Application
Server;Server;PrintJobLimit 也修改为1000
让DevExpress.XtraGrid.GridControl显示行号
private
void
view_CustomDrawRowIndicator(
object
sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
{
e.Appearance.TextOptions.HAlignment=DevExpress.Utils.HorzAlignment.Far;
if
(e.Info.IsRowIndicator)
{
if
(e.RowHandle>=0)
{
e.Info.DisplayText=e.RowHandle.ToString();
}
else
if
(e.RowHandle<0 && e.RowHandle>-1000)
{
e.Info.Appearance.BackColor=System.Drawing.Color.AntiqueWhite;
e.Info.DisplayText="G"+e.RowHandle.ToString();
}
}
摘录:《程序员秘书》--源代码--数据库--图片文件写入数据库并读出
9、在Form1.cs的视图设计器中,选中button2,在属性框中选中事件,双击Click,在Form1.cs的代码设计器中,添加修改如下代码
private void button2_Click(object sender, EventArgs e)
{
try
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string FileName = Path.GetFileName(openFileDialog1.FileName);
if (listBox1.Items.IndexOf(FileName) == -1)
{
Stream myStream = openFileDialog1.OpenFile();
int length = (int)myStream.Length;
byte[] bytes = new byte[length];
myStream.Read(bytes, 0, length);
myStream.Close();
dataset.Tables[0].Rows.Add(new object[] { FileName, bytes });
adapter.Update(dataset, "Pic_Table");//保存到数据库
listBox1.Items.Add(dataset.Tables[0].Rows[dataset.Tables[0].Rows.Count - 1][0].ToString());
listBox1.SelectedIndex = listBox1.Items.Count-1;
MessageBox.Show(this, "已经添加了一个图片。", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
MessageBox.Show(this, "添加的图片名称已经存在。", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception Mye)
{
MessageBox.Show(this, Mye.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
你可以先将PictureBox的图片保存为一个临时文件,再用上面的方法处理就OK了。
启用SQLCLR
EXEC sp_configure 'clr enabled' 1
reconfigure with override
开启远程调试:
SQL Server 外围应用配置器—服务和连接外围配置—database englie—远程连接—启用(远程连接的TCP/IP和named pipes)
SQL Server Configuration Manager—SQL2005网络配置—启用TCP/IP和named pipes