📄 frmhtbook.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using HouseBS;
using HouseBE;
namespace frmLogin
{
/// <summary>
/// frmHTBook 的摘要说明。
/// </summary>
public class frmHTBook : System.Windows.Forms.Form
{
private System.Windows.Forms.ToolBar toolBar1;
private System.Windows.Forms.ImageList imageList1;
private System.Windows.Forms.ToolBarButton toolBarButton1;
private System.Windows.Forms.ToolBarButton toolBarButton2;
private System.Windows.Forms.ToolBarButton toolBarButton3;
private System.Windows.Forms.ToolBarButton toolBarButton4;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.StatusBar statusBar1;
private DevComponents.DotNetBar.LabelX labelX1;
private DevComponents.DotNetBar.Controls.TextBoxX textBoxX1;
private DevComponents.DotNetBar.LabelX labelX2;
private DevComponents.DotNetBar.Controls.TextBoxX textBoxX2;
private System.Windows.Forms.ToolTip toolTip1;
private System.ComponentModel.IContainer components;
//用户字段
private DataSet ds=null;
private HouseBS.BargainBS BargainBS =new BargainBS();
private System.Windows.Forms.PrintPreviewDialog printPreviewDialog1;
private System.Drawing.Printing.PrintDocument printDocument1;
private System.Windows.Forms.PageSetupDialog pageSetupDialog1;
private System.Data.DataTable table=new System.Data.DataTable();
public frmHTBook()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmHTBook));
this.toolBar1 = new System.Windows.Forms.ToolBar();
this.toolBarButton1 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton2 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton3 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton4 = new System.Windows.Forms.ToolBarButton();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.panel1 = new System.Windows.Forms.Panel();
this.textBoxX2 = new DevComponents.DotNetBar.Controls.TextBoxX();
this.labelX2 = new DevComponents.DotNetBar.LabelX();
this.textBoxX1 = new DevComponents.DotNetBar.Controls.TextBoxX();
this.labelX1 = new DevComponents.DotNetBar.LabelX();
this.statusBar1 = new System.Windows.Forms.StatusBar();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
this.printPreviewDialog1 = new System.Windows.Forms.PrintPreviewDialog();
this.printDocument1 = new System.Drawing.Printing.PrintDocument();
this.pageSetupDialog1 = new System.Windows.Forms.PageSetupDialog();
this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// toolBar1
//
this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.toolBarButton1,
this.toolBarButton2,
this.toolBarButton3,
this.toolBarButton4});
this.toolBar1.ButtonSize = new System.Drawing.Size(60, 50);
this.toolBar1.DropDownArrows = true;
this.toolBar1.ImageList = this.imageList1;
this.toolBar1.Location = new System.Drawing.Point(0, 0);
this.toolBar1.Name = "toolBar1";
this.toolBar1.ShowToolTips = true;
this.toolBar1.Size = new System.Drawing.Size(536, 56);
this.toolBar1.TabIndex = 0;
this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
//
// toolBarButton1
//
this.toolBarButton1.ImageIndex = 0;
this.toolBarButton1.Text = "保存";
this.toolBarButton1.ToolTipText = "保存";
//
// toolBarButton2
//
this.toolBarButton2.ImageIndex = 1;
this.toolBarButton2.Text = "导出";
this.toolBarButton2.ToolTipText = "导出";
//
// toolBarButton3
//
this.toolBarButton3.ImageIndex = 2;
this.toolBarButton3.Text = "打印";
this.toolBarButton3.ToolTipText = "打印";
//
// toolBarButton4
//
this.toolBarButton4.ImageIndex = 3;
this.toolBarButton4.Text = "退出";
this.toolBarButton4.ToolTipText = "退出";
//
// imageList1
//
this.imageList1.ImageSize = new System.Drawing.Size(25, 25);
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
//
// panel1
//
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panel1.Controls.Add(this.textBoxX2);
this.panel1.Controls.Add(this.labelX2);
this.panel1.Controls.Add(this.textBoxX1);
this.panel1.Controls.Add(this.labelX1);
this.panel1.Controls.Add(this.statusBar1);
this.panel1.Controls.Add(this.dataGrid1);
this.panel1.Location = new System.Drawing.Point(0, 56);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(536, 328);
this.panel1.TabIndex = 1;
//
// textBoxX2
//
this.textBoxX2.AutoSize = false;
//
// textBoxX2.Border
//
this.textBoxX2.Border.Class = "TextBoxBorder";
this.textBoxX2.Location = new System.Drawing.Point(296, 16);
this.textBoxX2.Name = "textBoxX2";
this.textBoxX2.Size = new System.Drawing.Size(224, 24);
this.textBoxX2.TabIndex = 5;
//
// labelX2
//
this.labelX2.Location = new System.Drawing.Point(224, 16);
this.labelX2.Name = "labelX2";
this.labelX2.Size = new System.Drawing.Size(75, 23);
this.labelX2.TabIndex = 4;
this.labelX2.Text = "添加备注:";
//
// textBoxX1
//
this.textBoxX1.AutoSize = false;
//
// textBoxX1.Border
//
this.textBoxX1.Border.Class = "TextBoxBorder";
this.textBoxX1.Location = new System.Drawing.Point(88, 16);
this.textBoxX1.Name = "textBoxX1";
this.textBoxX1.Size = new System.Drawing.Size(120, 24);
this.textBoxX1.TabIndex = 3;
//
// labelX1
//
this.labelX1.Location = new System.Drawing.Point(16, 16);
this.labelX1.Name = "labelX1";
this.labelX1.Size = new System.Drawing.Size(75, 23);
this.labelX1.TabIndex = 2;
this.labelX1.Text = "合同编号:";
//
// statusBar1
//
this.statusBar1.Location = new System.Drawing.Point(0, 302);
this.statusBar1.Name = "statusBar1";
this.statusBar1.ShowPanels = true;
this.statusBar1.Size = new System.Drawing.Size(532, 22);
this.statusBar1.TabIndex = 1;
this.statusBar1.Text = "statusBar1";
//
// dataGrid1
//
this.dataGrid1.BackgroundColor = System.Drawing.SystemColors.ActiveCaptionText;
this.dataGrid1.CaptionBackColor = System.Drawing.Color.LightSkyBlue;
this.dataGrid1.DataMember = "";
this.dataGrid1.GridLineColor = System.Drawing.Color.Orange;
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.HotTrack;
this.dataGrid1.Location = new System.Drawing.Point(0, 48);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.ReadOnly = true;
this.dataGrid1.Size = new System.Drawing.Size(536, 256);
this.dataGrid1.TabIndex = 0;
this.dataGrid1.Click += new System.EventHandler(this.dataGrid1_Click);
this.dataGrid1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.dataGrid1_MouseMove);
//
// toolTip1
//
this.toolTip1.ShowAlways = true;
//
// printPreviewDialog1
//
this.printPreviewDialog1.AutoScrollMargin = new System.Drawing.Size(0, 0);
this.printPreviewDialog1.AutoScrollMinSize = new System.Drawing.Size(0, 0);
this.printPreviewDialog1.ClientSize = new System.Drawing.Size(400, 300);
this.printPreviewDialog1.Document = this.printDocument1;
this.printPreviewDialog1.Enabled = true;
this.printPreviewDialog1.Icon = ((System.Drawing.Icon)(resources.GetObject("printPreviewDialog1.Icon")));
this.printPreviewDialog1.Location = new System.Drawing.Point(22, 22);
this.printPreviewDialog1.MinimumSize = new System.Drawing.Size(375, 250);
this.printPreviewDialog1.Name = "printPreviewDialog1";
this.printPreviewDialog1.TransparencyKey = System.Drawing.Color.Empty;
this.printPreviewDialog1.Visible = false;
//
// printDocument1
//
this.printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDocument1_PrintPage);
//
// pageSetupDialog1
//
this.pageSetupDialog1.Document = this.printDocument1;
//
// frmHTBook
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(536, 381);
this.Controls.Add(this.panel1);
this.Controls.Add(this.toolBar1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "frmHTBook";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "合同管理";
this.Load += new System.EventHandler(this.frmHTBook_Load);
this.panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void dataGrid1_Click(object sender, System.EventArgs e)
{
string BargainNO=Convert.ToString(this.ds.Tables[0].Rows[this.dataGrid1.CurrentRowIndex][0]);
this.textBoxX1.Text=BargainNO;
}
private void frmHTBook_Load(object sender, System.EventArgs e)
{
HouseBS.BargainBS BargainBS=new BargainBS();
ds=BargainBS.select();
this.dataGrid1.DataSource=ds;
this.dataGrid1.DataMember="Bargain";
}
private void dataGrid1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.toolTip1.SetToolTip(this.dataGrid1,"单击一条记录");
}
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
switch(this.toolBar1.Buttons.IndexOf(e.Button))
{
case 0:
if(this.textBoxX1.Text=="")
{
MessageBox.Show("请单击一条记录选择合同编号");
return;
}
else if(this.textBoxX2.Text=="")
{
MessageBox.Show("没有添加数据无须保存");
return;
}
else
{
HouseBE.Bargain Bargain = new Bargain();
HouseBS.BargainBS BargainBS = new BargainBS();
Bargain.BargainNO=this.textBoxX1.Text;
Bargain.Remark=this.textBoxX2.Text;
BargainBS.bargain=Bargain;
try
{
BargainBS.update();
MessageBox.Show("保存成功");
//this.ds.Clear();
HouseBS.BargainBS BargainBS2=new BargainBS();
ds=BargainBS2.select();
this.dataGrid1.DataSource=ds;
this.dataGrid1.DataMember="Bargain";
this.textBoxX1.Text="";
this.textBoxX2.Text="";
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
break;//保存
case 1:
break;//导出
case 2:
this.printPreviewDialog1.ShowDialog();
break;//打印
case 3: this.Close();break;
}
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Font objFont = new Font("Tahoma",11,FontStyle.Underline);
Brush objBrush = Brushes.Black;
Pen objPen = new Pen(objBrush);
objPen.Width = 2;
//向打印预缆窗口中添加内容
int nLeft = this.pageSetupDialog1.PageSettings.Margins.Left;
int nTop = this.pageSetupDialog1.PageSettings.Margins.Top;
int nWidth = this.pageSetupDialog1.PageSettings.PaperSize.Width-
(this.pageSetupDialog1.PageSettings.Margins.Left +
this.pageSetupDialog1.PageSettings.Margins.Right);
int nHeight = this.pageSetupDialog1.PageSettings.PaperSize.Height-
(this.pageSetupDialog1.PageSettings.Margins.Top +
this.pageSetupDialog1.PageSettings.Margins.Bottom);
//打印出表头
e.Graphics.DrawString("合同信息",new Font("Garamond",40,FontStyle.Bold),Brushes.Blue,nLeft+200,nTop+10);
e.Graphics.DrawString("合同编号",objFont,objBrush,nLeft+10,nTop+60);
e.Graphics.DrawString("客户姓名",objFont,objBrush,nLeft+100,nTop+60);
e.Graphics.DrawString("客户电话",objFont,objBrush,nLeft+180,nTop+60);
e.Graphics.DrawString("付款方式",objFont,objBrush,nLeft+300,nTop+60);
e.Graphics.DrawString("备注",objFont,objBrush,nLeft+420,nTop+60);
//打印具体数据
try
{
this.ds=this.BargainBS.select();
int nLine=1;
foreach( DataRow rows in this.ds.Tables[0].Rows)
{
e.Graphics.DrawString(rows[0].ToString(),objFont,objBrush,nLeft+10,nTop+60+nLine*30);
e.Graphics.DrawString(rows[1].ToString(),objFont,objBrush,nLeft+100,nTop+60+nLine*30);
e.Graphics.DrawString(rows[2].ToString(),objFont,objBrush,nLeft+180,nTop+60+nLine*30);
e.Graphics.DrawString(rows[3].ToString(),objFont,objBrush,nLeft+300,nTop+60+nLine*30);
e.Graphics.DrawString(rows[4].ToString(),objFont,objBrush,nLeft+420,nTop+60+nLine*30);
nLine++;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -