pr010.cs

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

CS
811
字号
			// 
			// label19
			// 
			this.label19.Dock = System.Windows.Forms.DockStyle.Top;
			this.label19.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label19.Location = new System.Drawing.Point(5, 385);
			this.label19.Name = "label19";
			this.label19.Size = new System.Drawing.Size(134, 20);
			this.label19.TabIndex = 34;
			this.label19.Text = "Due Date";
			this.label19.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
			// 
			// dateTimePicker2
			// 
			this.dateTimePicker2.CustomFormat = "yyyy-MM-dd";
			this.dateTimePicker2.Dock = System.Windows.Forms.DockStyle.Top;
			this.dateTimePicker2.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
			this.dateTimePicker2.Location = new System.Drawing.Point(5, 391);
			this.dateTimePicker2.Name = "dateTimePicker2";
			this.dateTimePicker2.Size = new System.Drawing.Size(186, 20);
			this.dateTimePicker2.TabIndex = 35;
			// 
			// textBox14
			// 
			this.textBox14.Dock = System.Windows.Forms.DockStyle.Top;
			this.textBox14.Location = new System.Drawing.Point(5, 351);
			this.textBox14.Name = "textBox14";
			this.textBox14.Size = new System.Drawing.Size(186, 20);
			this.textBox14.TabIndex = 1;
			this.textBox14.Text = "textBox14";
			// 
			// textBox15
			// 
			this.textBox15.Dock = System.Windows.Forms.DockStyle.Top;
			this.textBox15.Location = new System.Drawing.Point(5, 371);
			this.textBox15.Name = "textBox15";
			this.textBox15.Size = new System.Drawing.Size(186, 20);
			this.textBox15.TabIndex = 36;
			this.textBox15.Text = "textBox15";
			// 
			// button1
			// 
			this.button1.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button1.Location = new System.Drawing.Point(5, 422);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(186, 24);
			this.button1.TabIndex = 39;
			this.button1.Text = "Payment";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// label20
			// 
			this.label20.Dock = System.Windows.Forms.DockStyle.Top;
			this.label20.Location = new System.Drawing.Point(5, 325);
			this.label20.Name = "label20";
			this.label20.Size = new System.Drawing.Size(134, 20);
			this.label20.TabIndex = 35;
			this.label20.Text = "Credit ?";
			this.label20.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
			// 
			// checkBox1
			// 
			this.checkBox1.Dock = System.Windows.Forms.DockStyle.Top;
			this.checkBox1.Location = new System.Drawing.Point(5, 327);
			this.checkBox1.Name = "checkBox1";
			this.checkBox1.Size = new System.Drawing.Size(186, 24);
			this.checkBox1.TabIndex = 40;
			this.checkBox1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// PR010
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(616, 501);
			this.Name = "PR010";
			this.Text = "single";
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			this.panel3.ResumeLayout(false);
			this.panel4.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.DsMast)).EndInit();

		}		#endregion		protected override void ReFill()
		{
			int p=0;
			
			if(BindMast!=null&&BindMast.Position>0)p=BindMast.Position;
			this.DaMast.SelectCommand =new System.Data.OleDb.OleDbCommand(BasSql+SelSql,((wmMain)this.MdiParent).db);
			System.Data.OleDb.OleDbCommandBuilder  OleDbCommandBuilder1 =new System.Data.OleDb.OleDbCommandBuilder (this.DaMast);
			this.DsMast.Clear();
			//this.DsMast.Dispose();
			//this.DsMast =new System.Data.DataSet ();
			this.DaMast.Fill(this.DsMast,"Mast");
			DsMast.Tables ["Mast"].Columns["PRICE"].DefaultValue=0;
			DsMast.Tables ["Mast"].Columns["QTY"].DefaultValue=0;
			DsMast.Tables ["Mast"].Columns["FREIGHT"].DefaultValue=0;
			DsMast.Tables ["Mast"].Columns["COMM"].DefaultValue=0;
			DsMast.Tables ["Mast"].Columns["AOE"].DefaultValue=0;
			DsMast.Tables ["Mast"].Columns["TRAN"].DefaultValue=0;
			DsMast.Tables ["Mast"].Columns["TAX"].DefaultValue=0;
			DsMast.Tables ["Mast"].Columns["PT_SUP"].DefaultValue=0;
			DsMast.Tables ["Mast"].Columns["PT_OT"].DefaultValue=0;
			DsMast.Tables ["Mast"].Columns["CR"].DefaultValue=false;

			
			//
			//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);
			
			//
			//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 (0);
			dataGrid1.TableStyles[0].GridColumnStyles.RemoveAt (0);
			dataGrid1.TableStyles[0].GridColumnStyles.RemoveAt (0);
			
			//
			//Initial TextBox;
			//
			if(this.textBox1.DataBindings.Count<=0)this.textBox1.DataBindings.Add("Text",this.DsMast,"Mast.PUR_CODE");
			if(this.textBox2.DataBindings.Count<=0)this.textBox2.DataBindings.Add("Text",this.DsMast,"Mast.PRICE");
			if(this.textBox3.DataBindings.Count<=0)this.textBox3.DataBindings.Add("Text",this.DsMast,"Mast.QTY");
			if(this.textBox4.DataBindings.Count<=0)this.textBox4.DataBindings.Add("Text",this.DsMast,"Mast.TOTAL_AMOUNT");
			if(this.textBox5.DataBindings.Count<=0)this.textBox5.DataBindings.Add("Text",this.DsMast,"Mast.FREIGHT");
			if(this.textBox6.DataBindings.Count<=0)this.textBox6.DataBindings.Add("Text",this.DsMast,"Mast.COMM");
			if(this.textBox7.DataBindings.Count<=0)this.textBox7.DataBindings.Add("Text",this.DsMast,"Mast.AOE");
			if(this.textBox8.DataBindings.Count<=0)this.textBox8.DataBindings.Add("Text",this.DsMast,"Mast.TRAN");
			if(this.textBox9.DataBindings.Count<=0)this.textBox9.DataBindings.Add("Text",this.DsMast,"Mast.GRASS_TOTAL");
			if(this.textBox10.DataBindings.Count<=0)this.textBox10.DataBindings.Add("Text",this.DsMast,"Mast.TAX");
			if(this.textBox11.DataBindings.Count<=0)this.textBox11.DataBindings.Add("Text",this.DsMast,"Mast.TOTAL");
			if(this.textBox12.DataBindings.Count<=0)this.textBox12.DataBindings.Add("Text",this.DsMast,"Mast.REMARKS");
			if(this.textBox13.DataBindings.Count<=0)this.textBox13.DataBindings.Add("Text",this.DsMast,"Mast.CERTIFIED");
			if(this.textBox14.DataBindings.Count<=0)this.textBox14.DataBindings.Add("Text",this.DsMast,"Mast.PT_SUP");
			if(this.textBox15.DataBindings.Count<=0)this.textBox15.DataBindings.Add("Text",this.DsMast,"Mast.PT_OT");
			if(this.checkBox1.DataBindings.Count <=0)this.checkBox1.DataBindings.Add ("Checked",this.DsMast,"Mast.CR"); 
			this.dateTimePicker1.Value=System.DateTime.Now;
			if(this.dateTimePicker1.DataBindings.Count<=0)this.dateTimePicker1.DataBindings.Add("Text",this.DsMast,"Mast.PUR_DATE");
			this.dateTimePicker2.Value=System.DateTime.Now;
			if(this.dateTimePicker2.DataBindings.Count<=0)this.dateTimePicker2.DataBindings.Add("Text",this.DsMast,"Mast.DUE_DATE");
			
		//	if(this.checkBox1.DataBindings.Count<=0)this.checkBox1.DataBindings.Add("Checked", this.DsMast, "Mast.CR");
			
			//
			//Initial the ComboBoxs
			//
			
			System.Data.OleDb.OleDbDataAdapter DaTm=new System.Data.OleDb.OleDbDataAdapter ();
			DaTm.SelectCommand =new System.Data.OleDb.OleDbCommand ("select * from Sup ",((wmMain)this.MdiParent).db);
			DaTm.Fill(this.DsMast,"Sup");
			this.comboBox1.DataSource=this.DsMast.Tables["Sup"];
			this.comboBox1.DisplayMember ="Sup_Name";
			this.comboBox1.ValueMember="Auto_No";
			//	this.comboBox1.DataBindings.Clear(); this.comboBox1.DataBindings.Add("SelectedValue",DsMast,"Mast.PR_ITEM");
			if(comboBox1.DataBindings.Count<=0) this.comboBox1.DataBindings.Add("SelectedValue",DsMast,"Mast.SUP_ID");
			
			DaTm.SelectCommand =new System.Data.OleDb.OleDbCommand ("select * from PR011",((wmMain)this.MdiParent).db);
			DaTm.Fill(this.DsMast,"PR");
			this.comboBox2.DataSource=this.DsMast.Tables["PR"].DefaultView;
			this.DsMast.Tables["PR"].DefaultView.Sort="FNAME";
			this.comboBox2.DisplayMember ="FNAME";
			this.comboBox2.ValueMember="AUTO_NO";
			//	this.comboBox1.DataBindings.Clear(); this.comboBox1.DataBindings.Add("SelectedValue",DsMast,"Mast.PR_ITEM");
			if(comboBox2.DataBindings.Count<=0) this.comboBox2.DataBindings.Add("SelectedValue",DsMast,"Mast.PR_ID");
			
			//
			// Initial other tables in memory
			//
			DaTm.SelectCommand =new System.Data.OleDb.OleDbCommand ("select * from PR_Item",((wmMain)this.MdiParent).db);
			DaTm.Fill(this.DsMast,"PR_Item");

			DaTm.Dispose();
			DaTm=null;


		}
		protected override void Save()
		{
			//this.textBox1.
			//	this.DsMast.AcceptChanges ();
			this.BindMast.EndCurrentEdit ();
			System.Data.OleDb.OleDbDataAdapter DaSave=new System.Data.OleDb.OleDbDataAdapter ();
			DaSave.SelectCommand =new System.Data.OleDb.OleDbCommand("select * from PUR" ,((wmMain)this.MdiParent).db);
			System.Data.OleDb.OleDbCommandBuilder  OleDbCommandBuilder1 =new System.Data.OleDb.OleDbCommandBuilder (DaSave);
			DaSave.RowUpdated += new System.Data.OleDb.OleDbRowUpdatedEventHandler(DaSave_RowUpdated);
			try
			{
				
				DaSave.Update (DsMast,"Mast");
				
			}
			catch(Exception e)
			{
				MessageBox.Show("Current records have error. The transaction will be ignore! Error:"+e.Message.ToString ());
				this.DsMast.RejectChanges();
			}
			DaSave.Dispose ();
			DaSave=null;
		//	this.Calc ();

		}
		private void DaSave_RowUpdated(object sender, System.Data.OleDb.OleDbRowUpdatedEventArgs e)
		{
			int newID = 0;
			System.Data.OleDb.OleDbCommand idCMD = new System.Data.OleDb.OleDbCommand("SELECT @@IDENTITY",((wmMain)this.MdiParent).db);
			
			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 ());
			}
			if(e.StatementType!= System.Data.StatementType.Delete)//e.StatementType == System.Data.StatementType.Insert ||e.StatementType == System.Data.StatementType.Update )
			{
				
				//newID = (int)idCMD.ExecuteScalar();
					//e.Row["AUTO_NO"] = newID;
				idCMD.CommandText="select TOTAL_AMOUNT,GRASS_TOTAL,TOTAL,Sup_Name,PR_NAME,PR_IT_ID,IT_NAME,PR_CODE from PR010 where AUTO_NO="+e.Row["AUTO_NO"];
				System.Data.OleDb.OleDbDataReader dr=idCMD.ExecuteReader();
				if(dr.Read ())
				{
					e.Row["TOTAL_AMOUNT"]=dr.GetValue(0);
					e.Row["GRASS_TOTAL"]=dr.GetValue(1);
					e.Row["TOTAL"]=dr.GetValue(2);
					e.Row["Sup_Name"]=dr.GetValue (3);
					e.Row["PR_NAME"]=dr.GetValue (4);
					e.Row["PR_IT_ID"]=dr.GetValue (5);
					e.Row["IT_NAME"]=dr.GetValue (6);
					e.Row["PR_CODE"]=dr.GetValue (7);
				}
				dr.Close ();
				dr=null;
			}
			idCMD=null;
		}
		protected override void Search()
		{
			new star.PR.PR010SE(this).ShowDialog();
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			
			this.Save ();
			if(this.BindMast.Count>0 && this.BindMast.Position>=0)
			{
				System.Data.DataRowView drv=(System.Data.DataRowView)this.BindMast.Current ;
				new PR.PR011 (((wmMain)this.MdiParent).db,Convert.ToInt32 (drv[0])).ShowDialog (this);
			}
			else
			{
				MessageBox.Show ("Please choose right purchase orders in left data list.");
			}
		}
	}}

⌨️ 快捷键说明

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