📄 generaterevenue.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
namespace Car_Inventory_Control
{
/// <summary>
/// Summary description for GenerateRevenue.
/// </summary>
public class frmGenerateRevenue : System.Windows.Forms.Form
{
private System.Windows.Forms.Label lblttrvn;
private System.Windows.Forms.Label lblTotalRevenueDetail;
private System.Windows.Forms.ListBox lstSaleDetail;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private FileStream fsMaster,fsSale;
BinaryReader masterReader, saleReader;
public frmGenerateRevenue()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lblttrvn = new System.Windows.Forms.Label();
this.lblTotalRevenueDetail = new System.Windows.Forms.Label();
this.lstSaleDetail = new System.Windows.Forms.ListBox();
this.SuspendLayout();
//
// lblttrvn
//
this.lblttrvn.Location = new System.Drawing.Point(56, 373);
this.lblttrvn.Name = "lblttrvn";
this.lblttrvn.Size = new System.Drawing.Size(99, 25);
this.lblttrvn.TabIndex = 0;
this.lblttrvn.Text = "生成的总利益:";
//
// lblTotalRevenueDetail
//
this.lblTotalRevenueDetail.Location = new System.Drawing.Point(211, 370);
this.lblTotalRevenueDetail.Name = "lblTotalRevenueDetail";
this.lblTotalRevenueDetail.Size = new System.Drawing.Size(106, 25);
this.lblTotalRevenueDetail.TabIndex = 1;
//
// lstSaleDetail
//
this.lstSaleDetail.ItemHeight = 12;
this.lstSaleDetail.Items.AddRange(new object[] {
"汽车型号\t\t 利润"});
this.lstSaleDetail.Location = new System.Drawing.Point(29, 32);
this.lstSaleDetail.Name = "lstSaleDetail";
this.lstSaleDetail.Size = new System.Drawing.Size(269, 304);
this.lstSaleDetail.TabIndex = 2;
//
// frmGenerateRevenue
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.AutoScroll = true;
this.ClientSize = new System.Drawing.Size(336, 410);
this.Controls.Add(this.lstSaleDetail);
this.Controls.Add(this.lblTotalRevenueDetail);
this.Controls.Add(this.lblttrvn);
this.Name = "frmGenerateRevenue";
this.Text = "生成收益";
this.Load += new System.EventHandler(this.GenerateRevenue_Load);
this.ResumeLayout(false);
}
#endregion
//loads sold car details in to ListBox
private void GenerateRevenue_Load(object sender, System.EventArgs e)
{
string saleFile = "D:\\CarSaleRecord.txt";
Hashtable objCarMasterDetails, objCarSaleDetails, profitDetails;
double mstPurchaseRate, salepurchase, saleRate;
string mstModelNum,saleModelNum;
double sum = 0.00;
double profit=0.00;
try
{
fsSale = File.Open(saleFile,FileMode.Open,FileAccess.Read);
}
catch(FileNotFoundException ex)
{
MessageBox.Show(ex.Message.ToString()+ "尚未售出");
}
profitDetails = new Hashtable();
saleReader = new BinaryReader(fsSale);
try
{
while(true)
{
//读取存储在 salesrecord 中的所有详细信息
saleModelNum = saleReader.ReadString();
salepurchase = saleReader.ReadDouble();
saleRate = saleReader.ReadDouble();
//将型号和相应的利润添加到散列表中
//如果型号已存在,则更新利润
if(profitDetails.ContainsKey(saleModelNum))
{
foreach(DictionaryEntry carprofit in profitDetails)
{
if(string.Compare(carprofit.Key.ToString(),saleModelNum,false)==0)
profit = double.Parse(carprofit.Value.ToString());
}
profitDetails.Remove(saleModelNum);
profit += saleRate - salepurchase;
profitDetails.Add(saleModelNum,profit);
}
// 如果型号不在散列表中,则将新键添加到散列表
else
{
profit = saleRate - salepurchase;
profitDetails.Add(saleModelNum,profit);
}
}
}
catch(EndOfStreamException ex)
{
}
//遍历散列表中的所有项并将详细信息显示在列表框中
foreach(DictionaryEntry carprofit in profitDetails)
{
this.lstSaleDetail.Items.Add(" ");
this.lstSaleDetail.Items.Add(carprofit.Key.ToString()+"\t\t\t" + carprofit.Value.ToString());
sum += double.Parse(carprofit.Value.ToString());
}
this.lblTotalRevenueDetail.Text = sum.ToString();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -