⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmorderdetailsdata.cs

📁 Winform_OnlineTraning 我们培训机构的在线培训部分
💻 CS
📖 第 1 页 / 共 2 页
字号:
			this.picPicture.Location = new System.Drawing.Point(224, 16);
			this.picPicture.Name = "picPicture";
			this.picPicture.Size = new System.Drawing.Size(496, 240);
			this.picPicture.TabIndex = 13;
			this.picPicture.TabStop = false;
			// 
			// pdocOrderDetails
			// 
			this.pdocOrderDetails.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.pdocOrderDetails_PrintPage);
			// 
			// ppdlgOrderDetails
			// 
			this.ppdlgOrderDetails.AutoScrollMargin = new System.Drawing.Size(0, 0);
			this.ppdlgOrderDetails.AutoScrollMinSize = new System.Drawing.Size(0, 0);
			this.ppdlgOrderDetails.ClientSize = new System.Drawing.Size(400, 300);
			this.ppdlgOrderDetails.Document = this.pdocOrderDetails;
			this.ppdlgOrderDetails.Enabled = true;
			this.ppdlgOrderDetails.Icon = ((System.Drawing.Icon)(resources.GetObject("ppdlgOrderDetails.Icon")));
			this.ppdlgOrderDetails.Location = new System.Drawing.Point(148, 15);
			this.ppdlgOrderDetails.MinimumSize = new System.Drawing.Size(375, 250);
			this.ppdlgOrderDetails.Name = "ppdlgOrderDetails";
			this.ppdlgOrderDetails.TransparencyKey = System.Drawing.Color.Empty;
			this.ppdlgOrderDetails.Visible = false;
			// 
			// pageSetupDialog1
			// 
			this.pageSetupDialog1.Document = this.pdocOrderDetails;
			// 
			// btnSetup
			// 
			this.btnSetup.Location = new System.Drawing.Point(432, 288);
			this.btnSetup.Name = "btnSetup";
			this.btnSetup.TabIndex = 14;
			this.btnSetup.Text = "打印设置";
			this.btnSetup.Click += new System.EventHandler(this.btnSetup_Click);
			// 
			// 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.pdocOrderDetails;
			this.printPreviewDialog1.Enabled = true;
			this.printPreviewDialog1.Icon = ((System.Drawing.Icon)(resources.GetObject("printPreviewDialog1.Icon")));
			this.printPreviewDialog1.Location = new System.Drawing.Point(443, 11);
			this.printPreviewDialog1.MinimumSize = new System.Drawing.Size(375, 250);
			this.printPreviewDialog1.Name = "printPreviewDialog1";
			this.printPreviewDialog1.TransparencyKey = System.Drawing.Color.Empty;
			this.printPreviewDialog1.Visible = false;
			// 
			// btnPrintPrev
			// 
			this.btnPrintPrev.Location = new System.Drawing.Point(344, 288);
			this.btnPrintPrev.Name = "btnPrintPrev";
			this.btnPrintPrev.TabIndex = 15;
			this.btnPrintPrev.Text = "打印预览";
			this.btnPrintPrev.Click += new System.EventHandler(this.btnPrintPrev_Click);
			// 
			// printDialog2
			// 
			this.printDialog2.Document = this.pdocOrderDetails;
			// 
			// frmOrderDetailsData
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
			this.ClientSize = new System.Drawing.Size(728, 341);
			this.Controls.Add(this.btnPrintPrev);
			this.Controls.Add(this.btnSetup);
			this.Controls.Add(this.picPicture);
			this.Controls.Add(this.txtOrderDetailID);
			this.Controls.Add(this.txtOrderID);
			this.Controls.Add(this.txtProductID);
			this.Controls.Add(this.txtQuantity);
			this.Controls.Add(this.txtUnitPrice);
			this.Controls.Add(this.txtTotal);
			this.Controls.Add(this.lblUnitPrice);
			this.Controls.Add(this.lblQuantity);
			this.Controls.Add(this.lblProductID);
			this.Controls.Add(this.lblOrderID);
			this.Controls.Add(this.lblOrderDetailID);
			this.Controls.Add(this.lblTotal);
			this.Controls.Add(this.btnPrint);
			this.Controls.Add(this.btnExit);
			this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Name = "frmOrderDetailsData";
			this.Text = "订单细目数据";
			this.Load += new System.EventHandler(this.frmOrderDetailsData_Load);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new frmOrderDetailsData());
		}

		private void btnExit_Click(object sender, System.EventArgs e)
		{
			objSqlConnection.Close();
			this.Close();
		}

		private void btnPrint_Click(object sender, System.EventArgs e)
		{
		 if(this.printDialog2.ShowDialog()==DialogResult.OK )
			{
				this.pdocOrderDetails.Print();
			}
		}

		private void pdocOrderDetails_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
		{
			//设置字体和画刷
			Font objFont = new Font("Tahoma",11,FontStyle.Regular);
			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.DrawLine(objPen,nLeft,nTop,nLeft+nWidth,nTop);
			e.Graphics.DrawLine(objPen,nLeft,nTop+nHeight,nLeft+nWidth,nTop+nHeight);
			e.Graphics.DrawLine(objPen,nLeft,nTop,nLeft,nTop+nHeight);
			e.Graphics.DrawLine(objPen,nLeft+nWidth,nTop,nLeft+nWidth,nTop+nHeight);


			

			e.Graphics.DrawString("订单细目数据",new Font("Garamond",20,FontStyle.Bold),objBrush,nLeft+200,nTop+10);
			
		
			e.Graphics.DrawString("订单细目编号",objFont,objBrush,nLeft+20,nTop+60);
			e.Graphics.DrawString("订单编号",objFont,objBrush,nLeft+140,nTop+60);
			e.Graphics.DrawString("产品编号",objFont,objBrush,nLeft+260,nTop+60);
			e.Graphics.DrawString("数量",objFont,objBrush,nLeft+340,nTop+60);
			e.Graphics.DrawString("单价",objFont,objBrush,nLeft+420,nTop+60);
			e.Graphics.DrawString("总计",objFont,objBrush,nLeft+520,nTop+60);
			


			try
			{
				objSqlConnection = new SqlConnection("Server = (local); database = Inventory; uid = sa; password=;");
				objSqlConnection.Open();
				objSqlCommand = new SqlCommand("Select * from OrderDetails",objSqlConnection);
				objSqlDataReader = objSqlCommand.ExecuteReader();
	
				
				int nLine=1;
				while(objSqlDataReader.Read())
				{
					e.Graphics.DrawString(objSqlDataReader["OrderDetailsID"].ToString(),objFont,objBrush,nLeft+20,nTop+60+nLine*30);
					e.Graphics.DrawString(objSqlDataReader["OrderID"].ToString(),objFont,objBrush,nLeft+140,nTop+60+nLine*30);
					e.Graphics.DrawString(objSqlDataReader["ProductID"].ToString(),objFont,objBrush,nLeft+260,nTop+60+nLine*30);
					e.Graphics.DrawString(objSqlDataReader["Quantity"].ToString(),objFont,objBrush,nLeft+340,nTop+60+nLine*30);
					e.Graphics.DrawString( objSqlDataReader["UnitPrice"].ToString(),objFont,objBrush,nLeft+420,nTop+60+nLine*30);
					e.Graphics.DrawString(objSqlDataReader["Total"].ToString(),objFont,objBrush,nLeft+520,nTop+60+nLine*30);
					nLine++;
				}
			}
			catch(SqlException ex)
			{
				MessageBox.Show(ex.Message);
			}

			//打印图片
			e.Graphics.DrawImage(this.picPicture.Image,150,300,500,400);
			
		}

		private void frmOrderDetailsData_Load(object sender, System.EventArgs e)
		{
			try
			{
				objSqlConnection = new SqlConnection("Server = (local); database = Inventory; uid = sa; password=;");
				objSqlConnection.Open();
				objSqlCommand = new SqlCommand("Select * from OrderDetails",objSqlConnection);
				objSqlDataReader = objSqlCommand.ExecuteReader();
	
				
				
				while(objSqlDataReader.Read())
				{
					this.txtOrderDetailID.Text = objSqlDataReader["OrderDetailsID"].ToString();
					this.txtOrderID.Text = objSqlDataReader["OrderID"].ToString();
					this.txtProductID.Text = objSqlDataReader["ProductID"].ToString();
					this.txtQuantity.Text = objSqlDataReader["Quantity"].ToString();
					this.txtUnitPrice.Text = objSqlDataReader["UnitPrice"].ToString();
					this.txtTotal.Text = objSqlDataReader["Total"].ToString();
				}
			}
			catch(SqlException ex)
			{
				MessageBox.Show(ex.Message);
			}
			this.picPicture.Image = Image.FromFile("Sample.jpg");
		}

		private void btnSetup_Click(object sender, System.EventArgs e)
		{
			this.pageSetupDialog1.ShowDialog();
		}

		private void btnPrintPrev_Click(object sender, System.EventArgs e)
		{
			this.printPreviewDialog1.ShowDialog();
		}

	
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -