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

📄 editorder.cs

📁 企业管理系统
💻 CS
📖 第 1 页 / 共 4 页
字号:
						MessageBox.Show("信息编号有重复,不能保存!");
						return;
					}

					sql  = "Insert into StockOrder (pageSign,soSign,pactSign,offerSign,offerName,writeDate,offerContactEr,thisExecuteEr,rgPlace,rgMeansName,rgDate,payMeansName,tsExes,allExes,content,addEr,addDate,fplx,hphm,yhzf,jhrType,fc1,fc2)";
					sql += " values ('"+ this.pageSign.Text +"','"+ this.sign.Text +"','"+ this.packSign.Text +"','"+ Public.CutCorString(this.stocker.Text,1) +"','"+ Public.CutCorString(this.stocker.Text,0) +"','"+ this.writeDate.Text +"','"+ this.stockContactEr.Text +"','"+ this.thisExecuteEr.Text +"','"+ this.rgPlace.Text +"','"+ this.rgMeans.Text +"','"+ this.rgDate.Text +"','"+ this.payMeans.Text +"',"+ this.txExes.Text +","+ this.allExes.Text +",'"+ this.memo.Text +"','"+ Public.userID +"','"+ DateTime.Now.ToString() +"','"+ this.fplx.Text +"','"+ this.hphm.Text +"','"+ this.yhzf.Text +"','"+ this.jht.Text +"','"+ this.payStat.Text +"','"+ this.fc2.Text +"')";

					Public.CloseConn();
					Public.conn.Open();
					OleDbCommand cmd = new OleDbCommand(sql,Public.conn);
					cmd.ExecuteNonQuery();
					Public.conn.Close();
					
				}catch(Exception ex){
					MessageBox.Show(ex.Message.ToString());
					return;
				}
			}

			//保存明细
			if(((DataTable)this.list.DataSource).Rows.Count > 0){
				foreach(DataRow row in ((DataTable)this.list.DataSource).Rows){
					sql  = "Insert into StockList (stockSign,stockClass,spec,proName,unitName,price,nums,makePlace,bandName,modelName,packIntro,content,allExes)";
					sql += " values ('"+ this.sign.Text +"','ORDER','"+ row["编号"].ToString() +"','"+ row["品名"].ToString() +"','"+ row["单位"].ToString() +"',"+ row["单价"].ToString() +","+ row["数量"].ToString() +",'','','"+ row["规格"].ToString() +"','','"+ row["备注"].ToString() +"',"+ row["总额"].ToString() +")";
					
					Public.CloseConn();
					Public.conn.Open();
					OleDbCommand cmd = new OleDbCommand(sql,Public.conn);
					cmd.ExecuteNonQuery();
					Public.conn.Close();
				}
			}else{
				//保存一条空数据
				sql  = "Insert into StockList (stockSign,stockClass,spec,proName,unitName,price,nums,makePlace,bandName,modelName,packIntro,content,allExes)";
				sql += " values ('"+ this.sign.Text +"','ORDER','','','',0,0,'','','','','',0)";
					
				Public.CloseConn();
				Public.conn.Open();
				OleDbCommand cmd = new OleDbCommand(sql,Public.conn);
				cmd.ExecuteNonQuery();
				Public.conn.Close();
			}

			if(this.scl != null) scl.LoadList();

			//提示
			//提示
			if(this.autoID == null &&  MessageBox.Show("保存操作成功,是否继续新建采购单?","操作成功",MessageBoxButtons.OKCancel,MessageBoxIcon.Question) == DialogResult.OK){
				if(_sl != null) this._sl.button6_Click(null,null);
				this.Close();
			}else{
				this.Close();
			}
		}

		/// <summary>
		/// 删除
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void button3_Click(object sender, System.EventArgs e) {
			if(this.autoID != null && MessageBox.Show("删除后不可恢复,确定删除吗?","删除确认",MessageBoxButtons.OKCancel,MessageBoxIcon.Question) == DialogResult.OK){
				try{
					string sql = "delete from StockOrder where soSign='"+ this.sign.Text +"'";
					Public.CloseConn();
					Public.conn.Open();
					OleDbCommand cmd = new OleDbCommand(sql,Public.conn);
					cmd.ExecuteNonQuery();
					Public.conn.Close();

					sql = "delete from StockList where stockSign='"+ this.sign.Text +"'";
					Public.CloseConn();
					Public.conn.Open();
					cmd = new OleDbCommand(sql,Public.conn);
					cmd.ExecuteNonQuery();
					Public.conn.Close();


					MessageBox.Show("操作成功,请刷新列表查看!");
					this.Close();

				}catch(Exception ex){
					MessageBox.Show(ex.Message.ToString());
					return;
				}
			}
		}

		/// <summary>
		/// 编辑
		/// </summary>
		/// <param name="_autoID"></param>
		public void SetAutoID(string _autoID){
			if(this.autoID == null){
				this.autoID = _autoID;
				this.LoadInfo();
				this.LoadItemCol();
			}
		}

		private void stocker_SelectedIndexChanged(object sender, System.EventArgs e) {
			if(this.autoID == null) this.button2.Enabled = true;

			DataRow row = Public.GetCorpRow(Public.CutCorString(this.stocker.Text,1));
			if(row != null){
				this.stockContactEr.Text  = row["corContactEr"].ToString();
				this.rgPlace.Text         = row["jhdz"].ToString();
				this.rgMeans.Text         = row["jhfs"].ToString();
				this.payMeans.Text        = row["hkfs"].ToString();
				this.yhzf.Text            = row["yhzf"].ToString();
				this.fplx.Text            = row["fplx"].ToString();
			}else{
				this.LoadBuyer();
			}
		}

		/// <summary>
		/// 初始化网格
		/// </summary>
		private void InitDataGrid(){

			DataGridTextBoxColumn dgtb = (DataGridTextBoxColumn)this.list.TableStyles[0].GridColumnStyles[0]; 

   		ComboBox cmbFunctionArea      = new ComboBox();
			cmbFunctionArea               = Public.GetProList(cmbFunctionArea);
   		cmbFunctionArea.Cursor        = Cursors.Arrow;
   		cmbFunctionArea.DropDownStyle = ComboBoxStyle.DropDownList;
   		cmbFunctionArea.Dock          = DockStyle.Fill;

   		cmbFunctionArea.SelectionChangeCommitted += new EventHandler(cmbFunctionArea_SelectionChangeCommitted); 
   		dgtb.TextBox.Controls.Add(cmbFunctionArea);
			dgtb.Width = 220;

			dgtb = (DataGridTextBoxColumn)this.list.TableStyles[0].GridColumnStyles[1]; 
			dgtb.Width = 60;
			dgtb = (DataGridTextBoxColumn)this.list.TableStyles[0].GridColumnStyles[2]; 
			dgtb.Width = 60;
			dgtb = (DataGridTextBoxColumn)this.list.TableStyles[0].GridColumnStyles[3]; 
			dgtb.Width = 40;
			dgtb = (DataGridTextBoxColumn)this.list.TableStyles[0].GridColumnStyles[4]; 
			dgtb.Width = 60;
			dgtb = (DataGridTextBoxColumn)this.list.TableStyles[0].GridColumnStyles[5]; 
			dgtb.Width = 40;
			dgtb = (DataGridTextBoxColumn)this.list.TableStyles[0].GridColumnStyles[6]; 
			dgtb.Width = 60;
		}

  	private void GetFocus(int row,int col) {
   		this.list.Focus(); 
   		DataGridCell dgc = new DataGridCell(row,col); 
   		this.list.CurrentCell = dgc; 
   		DataGridTextBoxColumn dgtb = (DataGridTextBoxColumn)list.TableStyles[0].GridColumnStyles[col]; 
   		dgtb.TextBox.Focus();
  	} 

 		private void cmbFunctionArea_SelectionChangeCommitted(object sender, EventArgs e){

			if(((DataTable)this.list.DataSource).Rows.Count == 0 || this.list.CurrentRowIndex == ((DataTable)this.list.DataSource).Rows.Count)
				((DataTable)this.list.DataSource).Rows.Add(((DataTable)this.list.DataSource).NewRow());

			string selectVal = ((ComboBox)sender).SelectedItem.ToString().Trim().Replace("|- ","");
			this.list[this.list.CurrentCell] = Public.CutProString(selectVal,0);

			//载入其它信息
			try{
				string sql = "select * from ProductCatalog where treeID='"+ Public.CutProString(selectVal,1) +"'";
				OleDbDataAdapter ad = new OleDbDataAdapter(sql,Public.conn);
				DataSet ds = new DataSet();
				ad.Fill(ds,"list");
				if(ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count == 1){
					DataRow row = ds.Tables[0].Rows[0];

					this.list[this.list.CurrentRowIndex,1] = row["gg"].ToString();
					this.list[this.list.CurrentRowIndex,7] = row["treeID"].ToString();
					
					this.list[this.list.CurrentRowIndex,3] = row["unitName"].ToString();
					this.list[this.list.CurrentRowIndex,4] = row["price"].ToString();
					
					this.MoneyTotal();

				}else{
					MessageBox.Show("产品目录中找不到选中的产品或目录名称,或者是产品目录库中有多个相同的编号存在,请确认后重新选择!");
					return;
				}

			}catch(Exception ex){
				MessageBox.Show(ex.Message.ToString());
				return;
			}
 		} 

 		private void buttonFocus_Click(object sender, System.EventArgs e){
  		GetFocus(2,0);
 		}

		//当更改过数量后重新计算总额
		private void NumsChangeed(object sender, System.EventArgs e){
			this.MoneyTotal();
		}

		private void MoneyTotal(){
			if(((DataTable)this.list.DataSource).Rows.Count>0){

				//计算行总额 = 数量X单价

				if(this.list[this.list.CurrentRowIndex,2].ToString() == ""){
					this.list[this.list.CurrentRowIndex,2] = "0";
				}

				if(this.list[this.list.CurrentRowIndex,4].ToString() == ""){
					this.list[this.list.CurrentRowIndex,4] = "0.00";
				}

				Decimal n,p;

				try{
					n = Decimal.Parse(this.list[this.list.CurrentRowIndex,2].ToString());
					p = Decimal.Parse(this.list[this.list.CurrentRowIndex,4].ToString());
				}catch(Exception ex){
					MessageBox.Show("系统判断出输入的数量["+ this.list[this.list.CurrentRowIndex,2].ToString() +"]或单价["+ this.list[this.list.CurrentRowIndex,4].ToString() +"]非数字格式!\n\n系统返回错误:" + ex.Message.ToString());
					return;
				}

				Decimal ze =  n * p;
				this.list[this.list.CurrentRowIndex,5] = ze.ToString();

				//计算总额到基本信息窗
				DataTable table = ((DataTable)this.list.DataSource);
				Decimal t = 0;
				for(int i=0;i<table.Rows.Count;i++){
					DataRow row = table.Rows[i];
					string z_ = row["总额"].ToString();
					if(z_ == null || z_.Trim() == "") z_ = "0";
					t += Decimal.Parse(z_);
				}
				this.allExes.Text = t.ToString();

			}
		}

		/// <summary>
		/// 方便计算总额用
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void list_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e) {
			this.MoneyTotal();
		}

		private void list_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) {
			this.MoneyTotal();
		}

		/// <summary>
		/// 事件一
		/// </summary>
		private void ClickInDG(object sender,MouseEventArgs e){

			try{
				if(((DataTable)this.list.DataSource).Rows.Count > 0){
					if(this.currentIndex != -1) this.list.UnSelect(this.currentIndex);

					Point p = new Point(e.X,e.Y);
					DataGrid.HitTestInfo hti = this.list.HitTest(p);
					if(hti.Type == DataGrid.HitTestType.Cell){
						this.list.CurrentCell = new DataGridCell(hti.Row,hti.Column);
						this.list.Select(hti.Row);
						this.currentIndex = hti.Row;
						if(this.list.CurrentCell.RowNumber < this.ds.Tables[0].Rows.Count + 1){
							//
						}else{
							if(this.currentIndex != -1){
								this.list.UnSelect(this.currentIndex);
								this.currentIndex = -1;
							}
						}
					}
				}else{
					this.currentIndex = -1;
				}

				//如果相等,则表示选中的是空行
				if(this.currentIndex == ((DataTable)this.list.DataSource).Rows.Count){
					this.currentIndex = -1;
				}

				if(this.currentIndex > -1){
					this.menuItem1.Enabled = true;
					this.menuItem2.Enabled = true;
				}else{
					this.menuItem1.Enabled = false;
					this.menuItem2.Enabled = false;
				}

				//MessageBox.Show("当前选中:" + this.currentIndex.ToString() + ",当前autoID="+ this.autoID +",共有"+ ((DataTable)this.list.DataSource).Rows.Count.ToString() +"条记录。");

			}catch{}
		}

		/// <summary>
		/// 事件二
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void UPInDG(object sender,MouseEventArgs e){

			if(this.currentIndex > -1){
				this.menuItem1.Enabled = true;
				this.menuItem2.Enabled = true;
			}else{
				this.menuItem1.Enabled = false;
				this.menuItem2.Enabled = false;
			}
		}

		/// <summary>
		/// 删除本条
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void menuItem1_Click(object sender, System.EventArgs e) {
			if(this.currentIndex > -1){
				if(MessageBox.Show("删除后不可恢复,确定删除吗?","删除确认",MessageBoxButtons.OKCancel,MessageBoxIcon.Question) == DialogResult.OK) ((DataTable)this.list.DataSource).Rows.RemoveAt(this.currentIndex);
			}
		}

		/// <summary>
		/// 删除全部
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void menuItem2_Click(object sender, System.EventArgs e) {
			if(MessageBox.Show("删除后不可恢复,确定删除吗?","删除确认",MessageBoxButtons.OKCancel,MessageBoxIcon.Question) == DialogResult.OK){
				((DataTable)this.list.DataSource).Rows.Clear();
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void button5_Click(object sender, System.EventArgs e) {
			this.jht.Text = this.rgDate.Text;
		}

		public void SetPackSign(){
			this.packSign.Text = this.sign.Text;
		}

		private void menuItem4_Click(object sender, System.EventArgs e) {
			//Eboer.MIS.MF.WinForm.SelectPC spc = new SelectPC(this);
			//spc.ShowDialog();
		}

		/// <summary>
		/// 检查单位框的可输入
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void timer1_Tick(object sender, System.EventArgs e) {
			if(this.stocker.Text.Trim() != ""){
				this.stocker.Enabled = false;
			}else{
				this.stocker.Enabled = true;
				this.timer1.Stop();
			}
		}
	}
}

⌨️ 快捷键说明

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