pr011.cs

来自「C#简单练习进销存代码」· CS 代码 · 共 488 行 · 第 1/2 页

CS
488
字号
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label6
			// 
			this.label6.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.label6.Location = new System.Drawing.Point(5, 262);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(134, 20);
			this.label6.TabIndex = 5;
			this.label6.Text = "Sum of Payment to OT:";
			this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label7
			// 
			this.label7.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.label7.Location = new System.Drawing.Point(5, 242);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(134, 20);
			this.label7.TabIndex = 6;
			this.label7.Text = "Payable to Others";
			this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label8
			// 
			this.label8.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.label8.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label8.Location = new System.Drawing.Point(5, 222);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(134, 20);
			this.label8.TabIndex = 7;
			this.label8.Text = "Balance to Supplier";
			this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label9
			// 
			this.label9.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.label9.Location = new System.Drawing.Point(5, 202);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(134, 20);
			this.label9.TabIndex = 8;
			this.label9.Text = "Sum of Payment to Sup:";
			this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label10
			// 
			this.label10.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.label10.Location = new System.Drawing.Point(5, 182);
			this.label10.Name = "label10";
			this.label10.Size = new System.Drawing.Size(134, 20);
			this.label10.TabIndex = 9;
			this.label10.Text = "Payable to Supplier:";
			this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// textBox4
			// 
			this.textBox4.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.textBox4.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.textBox4.Location = new System.Drawing.Point(5, 282);
			this.textBox4.Name = "textBox4";
			this.textBox4.ReadOnly = true;
			this.textBox4.Size = new System.Drawing.Size(138, 20);
			this.textBox4.TabIndex = 4;
			this.textBox4.Text = "textBox4";
			this.textBox4.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox5
			// 
			this.textBox5.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.textBox5.Location = new System.Drawing.Point(5, 262);
			this.textBox5.Name = "textBox5";
			this.textBox5.ReadOnly = true;
			this.textBox5.Size = new System.Drawing.Size(138, 20);
			this.textBox5.TabIndex = 5;
			this.textBox5.Text = "textBox5";
			// 
			// textBox6
			// 
			this.textBox6.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.textBox6.Location = new System.Drawing.Point(5, 242);
			this.textBox6.Name = "textBox6";
			this.textBox6.ReadOnly = true;
			this.textBox6.Size = new System.Drawing.Size(138, 20);
			this.textBox6.TabIndex = 6;
			this.textBox6.Text = "textBox6";
			// 
			// textBox7
			// 
			this.textBox7.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.textBox7.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.textBox7.Location = new System.Drawing.Point(5, 222);
			this.textBox7.Name = "textBox7";
			this.textBox7.ReadOnly = true;
			this.textBox7.Size = new System.Drawing.Size(138, 20);
			this.textBox7.TabIndex = 7;
			this.textBox7.Text = "textBox7";
			this.textBox7.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// textBox8
			// 
			this.textBox8.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.textBox8.Location = new System.Drawing.Point(5, 202);
			this.textBox8.Name = "textBox8";
			this.textBox8.ReadOnly = true;
			this.textBox8.Size = new System.Drawing.Size(138, 20);
			this.textBox8.TabIndex = 8;
			this.textBox8.Text = "textBox8";
			// 
			// textBox9
			// 
			this.textBox9.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.textBox9.Location = new System.Drawing.Point(5, 182);
			this.textBox9.Name = "textBox9";
			this.textBox9.ReadOnly = true;
			this.textBox9.Size = new System.Drawing.Size(138, 20);
			this.textBox9.TabIndex = 9;
			this.textBox9.Text = "textBox9";
			// 
			// PR011
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(504, 357);
			this.Name = "PR011";
			this.Text = "single";
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			this.panel3.ResumeLayout(false);
			this.panel4.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.DsMast)).EndInit();

		}		#endregion
		//
		//3. load database
		//
		protected override void ReFill()
		{
			//3.1 Mast
			int p=0;
			this.SelSql=" where PUR_ID="+this.purId;
			if(BindMast!=null&&BindMast.Position>0)p=BindMast.Position;
			this.DaMast.SelectCommand =new System.Data.OleDb.OleDbCommand(BasSql+SelSql,dbCon);
			System.Data.OleDb.OleDbCommandBuilder  OleDbCommandBuilder1 =new System.Data.OleDb.OleDbCommandBuilder (this.DaMast);
			this.DsMast.Clear();
			//MessageBox.Show (this.BasSql +this.SelSql );
			this.DaMast.Fill(this.DsMast,"Mast");
			DsMast.Tables ["Mast"].Columns["PT_SUP"].DefaultValue=0;
			DsMast.Tables ["Mast"].Columns["PT_OT"].DefaultValue=0;
			//DsMast.Tables ["Mast"].Columns.Add("TOT_SUP",System.Type.GetType("System.Decimal"),"Sum(PT_SUP)");
			//DsMast.Tables ["Mast"].Columns.Add("TOT_OT",System.Type.GetType("System.Decimal"),"Sum(PT_OT)");
			this.Ref_OV ();
			
			//
			//3.2 Initial CurrencyManager;
			//
			
			this.BindMast =(CurrencyManager)this.BindingContext[DsMast,"Mast"];
			this.BindMast.Position =p;
			//this.BindMast.PositionChanged-=new EventHandler(BindMast_PositionChanged);
			//this.BindMast.PositionChanged+=new EventHandler(BindMast_PositionChanged);
			
			//
			//3.3 Initial DataGrid;
			//
			this.dataGrid1.TableStyles.Clear();
			this.dataGrid1.SetDataBinding (this.DsMast,"Mast");
			this.dataGrid1.TableStyles.Add (new DataGridTableStyle());
			dataGrid1.TableStyles[0].MappingName="Mast";
			dataGrid1.TableStyles[0].GridColumnStyles.RemoveAt (0);
			dataGrid1.TableStyles[0].GridColumnStyles.RemoveAt (2);
			//dataGrid1.TableStyles[0].GridColumnStyles.RemoveAt (4);
			//dataGrid1.TableStyles[0].GridColumnStyles.RemoveAt (4);
			//
			//3.4 Initial Textbox
			//
			this.dateTimePicker1.Value=System.DateTime.Now;
			if(this.textBox1.DataBindings.Count<=0)this.textBox1.DataBindings.Add("Text",this.DsMast,"Mast.CODE");
			if(this.textBox2.DataBindings.Count<=0)this.textBox2.DataBindings.Add("Text",this.DsMast,"Mast.PT_SUP");
			if(this.textBox3.DataBindings.Count<=0)this.textBox3.DataBindings.Add("Text",this.DsMast,"Mast.PT_OT");
			if(this.textBox4.DataBindings.Count<=0)this.textBox4.DataBindings.Add("Text",this.DsMast,"OV.BL_OT");
			if(this.textBox5.DataBindings.Count<=0)this.textBox5.DataBindings.Add("Text",this.DsMast,"OV.PT_OTED");
			if(this.textBox6.DataBindings.Count<=0)this.textBox6.DataBindings.Add("Text",this.DsMast,"OV.PT_OT");
			if(this.textBox7.DataBindings.Count<=0)this.textBox7.DataBindings.Add("Text",this.DsMast,"OV.BL_SUP");
			if(this.textBox8.DataBindings.Count<=0)this.textBox8.DataBindings.Add("Text",this.DsMast,"OV.PT_SUPED");
			if(this.textBox9.DataBindings.Count<=0)this.textBox9.DataBindings.Add("Text",this.DsMast,"OV.PT_SUP");
			if(this.dateTimePicker1.DataBindings.Count<=0)this.dateTimePicker1.DataBindings.Add("Text",this.DsMast,"Mast.C_DATE");
			

		}
		//
		//4. Save to Database
		//
		protected override void Save()
		{
			this.BindMast.EndCurrentEdit ();

			try
			{
				this.DaMast.Update (DsMast,"Mast");
			}
			catch(Exception e)
			{
				MessageBox.Show("Current records have error. The transaction will be ignore! Error:"+e.Message.ToString ());
				this.DsMast.RejectChanges();
			}
		}
		//
		// 5. this function includes the additional action when save the database.
		//

		private void DaMast_RowUpdated(object sender, System.Data.OleDb.OleDbRowUpdatedEventArgs e)
		{
			int newID = 0;
			System.Data.OleDb.OleDbCommand idCMD = new System.Data.OleDb.OleDbCommand("SELECT @@IDENTITY",dbCon);
			
			if (e.StatementType == System.Data.StatementType.Insert)
			{
				// Retrieve the identity value and store it in the CategoryID column.
				newID = (int)idCMD.ExecuteScalar();
				e.Row["AUTO_NO"] = newID;
				//	MessageBox.Show (newID.ToString ());
			}
			this.Ref_OV ();
		}
		//
		// 6. Override the AddNew records
		//
		protected override void AddNew()
		{
			base.AddNew ();
			System.Data.DataRowView drv=(System.Data.DataRowView)this.BindMast.Current ;
			drv["PUR_ID"]=this.purId;
		}
		private void Ref_OV()
		{
			System.Data.OleDb.OleDbDataAdapter tmda=new System.Data.OleDb.OleDbDataAdapter ("select * from PUR_CF_OV where AUTO_NO="+this.purId,this.dbCon );
			if(this.DsMast.Tables.Contains ("OV"))this.DsMast.Tables["OV"].Clear ();
			tmda.Fill(this.DsMast,"OV");
			tmda.Dispose ();
			tmda=null;
		}
		
	}}

⌨️ 快捷键说明

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