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

📄 sreportfrm.cs

📁 本代码设计了一个销售管理系统
💻 CS
📖 第 1 页 / 共 2 页
字号:
				MessageBox.Show("请输入查询条件");
			}
			else{
				string AddSql="";
				if(ActionTime!="")AddSql+=" and ActionTime like '%"+ActionTime+"%'";
				if((MinCode!="")&&(MaxCode!=""))AddSql+=" and ID>="+MinCode+" and ID<="+MaxCode; 
				SqlDataAdapter sda=new SqlDataAdapter("select top 1000 * from D_"+FPara.ShopCode+" where MyAction<>'' "+AddSql+" order by id desc",FPara.connStr);
				DataSet ds=new DataSet();
				sda.Fill(ds,"find");
				Rds=ds;
				dataGrid1.DataSource=ds.Tables["find"].DefaultView;
				dataGrid1.SetDataBinding(ds, "find");
			}
		}

		private void dataGrid1_CurrentCellChanged(object sender,System.EventArgs e)
		{
			NowID=dataGrid1[dataGrid1.CurrentCell.RowNumber,0].ToString().Trim();
			NowAction=dataGrid1[dataGrid1.CurrentCell.RowNumber,1].ToString().Trim();
			if(NowAction=="H")
			{
				hireback.Enabled=true;
			}
			else{
				hireback.Enabled=false;
			}
		}

		private void delbtn_Click(object sender, System.EventArgs e)
		{
			Change_Click("D",sender,e);
		}
		private void hireback_Click(object sender, System.EventArgs e)
		{
			Change_Click("B",sender,e);
		}
		private void Change_Click(string TypeStr,object sender, System.EventArgs e){
			string TotalGoodsName="",AddInfo="",Bok="0",AddSpace="          ";;
			SqlDataReader sdr= FPara.SqlReader("Select top 1 * from D_"+FPara.ShopCode+" where ID="+NowID,FPara.connStr);
			if(sdr!=null)
			{
				if(sdr.Read())
				{
					AddInfo=sdr["Info"].ToString();
					if(TypeStr=="B")
					{
						if(AddInfo.IndexOf("归还")>-1)
						{
							MessageBox.Show("该商品似乎已归还,请检查\\n提示信息:"+AddInfo);
							Bok="1";
						}
					}
					if(Bok=="0")
					{
						string[] AGoodsName,AGoodsCode,AGoodsPrice,AGoodsNum;
						AGoodsName=sdr["GoodsName"].ToString().Split(new char[] {';'});
						AGoodsCode=sdr["GoodsCode"].ToString().Split(new char[] {';'});
						AGoodsPrice=sdr["GoodsPrice"].ToString().Split(new char[] {';'});
						AGoodsNum=sdr["GoodsNum"].ToString().Split(new char[] {';'});
						for(int dnum=0;dnum<AGoodsCode.Length-1;dnum++)
						{
							try
							{
								TotalGoodsName+=AGoodsCode[dnum]+AddSpace+(AGoodsNum[dnum]+"        ").Substring(0,8)+AddSpace+(AGoodsPrice[dnum]+"          ").Substring(0,10)+AddSpace+((double.Parse(AGoodsPrice[dnum].ToString())*double.Parse(AGoodsNum[dnum].ToString())).ToString()+"      ").Substring(0,6)+"\r";
								int AddNum=int.Parse(AGoodsNum[dnum]);
								FPara.SqlCmd("update Goods_"+NowAction+" set KCNum=KCNum+"+AddNum+" where DepartMent='"+FPara.ShopCode+"' and GoodsName='"+AGoodsName[dnum]+"' and BarCode='"+AGoodsCode[dnum]+"'",FPara.connStr);
							}
							catch(Exception ex){}
						}
					}
				}
				sdr.Close();
			}
			string ErrorStr="";
			if(TypeStr=="D")
			{
				ErrorStr=FPara.SqlCmd("delete from D_"+FPara.ShopCode+" where ID="+NowID,FPara.connStr);
				if(ErrorStr==null)MessageBox.Show("删除成功,并已经把改动数量恢复到库存中");
			}
			if((TypeStr=="B")&&(Bok=="0")){
				ErrorStr=FPara.SqlCmd("update D_"+FPara.ShopCode+" set Info='"+AddInfo+"已于"+String.Format("{0:yyyy-MM-dd}",System.DateTime.Today)+"日归还' where ID="+NowID,FPara.connStr);
				string PrintContStr="欢迎光临浪淘沙音像店\r于"+String.Format("{0:yyyy-MM-dd}",System.DateTime.Today)+"日归还:\r";
				PrintContStr+="商品编号     "+AddSpace+"数量    "+AddSpace+"单价      "+AddSpace+"金额\r";
				PrintContStr+=TotalGoodsName;
				PrintContStr+="并退回押金\r";
				PrintContStr+="注意:"+AddInfo;
				streamToPrint = new StringReader(PrintContStr);
				//
				FileStream fs=new FileStream("txt/HB"+String.Format("{0:yyyy-MM-dd}",System.DateTime.Today)+".txt",FileMode.OpenOrCreate,FileAccess.Write);
				StreamWriter wfile=new StreamWriter(fs);
				wfile.BaseStream.Seek(0,SeekOrigin.End);
				wfile.WriteLine(PrintContStr);
				wfile.Flush();
				wfile.Close();
				//
				try //打印主体
				{
					printFont = new Font("Arial", 11);
					PrintDocument printDocument1 = new PrintDocument();
					printDocument1.PrintPage += new PrintPageEventHandler(this.printDocument1_PrintPage);
					printDocument1.Print();
				}  
				finally 
				{
					streamToPrint.Close();
				}
				if(ErrorStr==null)MessageBox.Show("归还成功,并已经把改动数量恢复到库存中");
			}
		}

		private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs ev)
		{
			float linesPerPage = 0;
			float yPos = 0;
			int count = 0;

			int leftmargin=15;//左边距
			int topmargin=5;//上边距
			//int totalline=5;//总行数
			
			float leftMargin = leftmargin;
			float topMargin = topmargin;
			string line = null;

			//Calculate the number of lines per page.
			linesPerPage = ev.MarginBounds.Height/printFont.GetHeight(ev.Graphics);
			//if (linesPerPage>totalline) linesPerPage=totalline;
			

			// Print each line of the file.
			while((count<linesPerPage)&&((line=streamToPrint.ReadLine()) != null)) 
			{
				yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
				ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, new StringFormat());
				count++;
			}
			//If more lines exist, print another page.
			if(line != null)
			{
				ev.HasMorePages = true;
			}
			else
			{
				ev.HasMorePages = false;
			}
		}

		private void reportbtn_Click(object sender, System.EventArgs e)
		{
			string ActionTime=actiontime.Text.ToString().Trim();
			string MinCode=mincode.Text.ToString().Trim();
			string MaxCode=maxcode.Text.ToString().Trim();
			int GoodsNum=0;
			double TotalMoney=0;
			if((ActionTime=="")&&((MinCode=="")||(MaxCode=="")))
			{
				MessageBox.Show("请输入查询条件");
			}
			else
			{				
				string AddSql="";
				if(ActionTime!="")AddSql+=" and ActionTime like '%"+ActionTime+"%'";
				if((MinCode!="")&&(MaxCode!=""))AddSql+=" and ID>="+MinCode+" and ID<="+MaxCode; 
				SqlDataReader rsdr=FPara.SqlReader("select top 1000 * from D_"+FPara.ShopCode+" where MyAction<>'' "+AddSql+" order by id desc",FPara.connStr);
				while(rsdr.Read()){
					GoodsNum+=int.Parse(rsdr["ActionNum"].ToString());
					TotalMoney+=double.Parse(rsdr["TotalMoney"].ToString());
				}
				rsdr.Close();
				if((ActionTime.Length==10)&&(MinCode=="0"))
				{
					string message = "是否生成本月报表?";
					string caption = "本月报表";
					MessageBoxButtons buttons = MessageBoxButtons.YesNo;
					DialogResult result;
					result = MessageBox.Show(this, message, caption, buttons,MessageBoxIcon.Question, MessageBoxDefaultButton.Button1,MessageBoxOptions.RightAlign);
					if(result == DialogResult.Yes)
					{
						PrintReport(GoodsNum,TotalMoney);
					}
					MessageBox.Show("本月销售商品数:"+GoodsNum.ToString()+"\n本月销售额:"+TotalMoney.ToString());
				}
				else{
					MessageBox.Show("不符合报表条件\n请输入统计日期,如:2004-02-01\n并将起始号设为0");
				}
			}
			
		}
		private void PrintReport(int Gnum,double Tmoney){
			string ActionTime=actiontime.Text.ToString().Trim();
			SqlDataReader rsdr0=FPara.SqlReader("select top 1 * from ReCord where R_Time='"+ActionTime+"' and Part='"+FPara.ShopCode+"' order by R_Time desc",FPara.connStr);
			string NowAction="0";
			if(rsdr0!=null)
			{
				if(rsdr0.Read())
				{
					NowAction="U";
				}
				else
				{
					NowAction="I";
				}
				rsdr0.Close();
			}			
			if(NowAction=="U")
			{
				FPara.SqlCmd("update Record set Goods="+Gnum+",Total="+Tmoney+" where R_Time='"+ActionTime+"' and Part='"+FPara.ShopCode+"'",FPara.connStr);
			}
			else if(NowAction=="I"){
				FPara.SqlCmd("insert into Record values('"+FPara.ShopCode+"','"+ActionTime+"',"+Gnum+","+Tmoney+",'"+String.Format("{0:yyyy-MM-dd}",System.DateTime.Today)+"')",FPara.connStr);
			}
			MessageBox.Show("数据已经更新到数据库");
		}

		private void dataGrid1_Navigate(object sender, System.Windows.Forms.NavigateEventArgs ne)
		{
		
		}
	}
}

⌨️ 快捷键说明

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