using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.IO;
|
|
namespace M423project
|
{
|
//产品检测数据集合
|
public class DetectionCollection : IDisposable, IList<ProductMeasureResult>
|
{
|
private string saveFileName = string.Empty;
|
|
private List<ProductMeasureResult> productList = new List<ProductMeasureResult>();
|
|
public int Count
|
{ get { return productList.Count; } }
|
public DetectionCollection(string _saveFileName)
|
{
|
saveFileName = _saveFileName;
|
}
|
|
public void AppendProduct(string _productNo)
|
{
|
//productList.Add(new ProductMeasureResult(_productNo));
|
}
|
|
public void DeleteProduct()
|
{
|
if (productList.Count <= 0)
|
return;
|
|
ProductMeasureResult tr = productList[productList.Count - 1];
|
SaveTestResult(tr);
|
}
|
|
//设定高度数据
|
public void SetHeight(string productNo, double height, double cellHeight, MeasureState measureState)
|
{
|
var p = (from o in productList
|
where o.ProductNo == productNo
|
select o
|
).FirstOrDefault();
|
if (p == null)
|
return;
|
|
//p.CellHeight = cellHeight;
|
p.Height = height;
|
p.HeightResult = measureState.ToString();
|
}
|
|
//结果保存到文件,只有在产品长宽高都设置好时,或未完成设置但对象Dispose时
|
public void SaveTestResult(ProductMeasureResult tr)
|
{
|
using (StreamWriter sw = new StreamWriter(saveFileName))
|
{
|
sw.WriteLine("{0}:{1:F4},{2:F4},{3};{4:F4}, {5}", tr.ProductNo, tr.Length, tr.Width,
|
tr.ToString(), tr.Height, tr.ToString());
|
}
|
}
|
|
public void Dispose()
|
{
|
ProductMeasureResult tr;
|
for (int i = productList.Count - 1; i >= 0; i--)
|
{
|
tr = productList[i];
|
SaveTestResult(tr);
|
}
|
|
}
|
|
public int IndexOf(ProductMeasureResult item)
|
{
|
return productList.IndexOf(item);
|
}
|
|
public void Insert(int index, ProductMeasureResult item)
|
{
|
productList.Insert(0, item);
|
}
|
|
public void RemoveAt(int index)
|
{
|
productList.RemoveAt(index);
|
|
}
|
|
public ProductMeasureResult this[int index]
|
{
|
get
|
{
|
return productList[index];
|
}
|
set
|
{
|
productList[index] = value;
|
|
}
|
}
|
|
public void Add(ProductMeasureResult item)
|
{
|
productList.Add(item);
|
}
|
|
public void Clear()
|
{
|
productList.Clear();
|
}
|
|
public bool Contains(ProductMeasureResult item)
|
{
|
return productList.Contains(item);
|
}
|
|
public void CopyTo(ProductMeasureResult[] array, int arrayIndex)
|
{
|
;
|
|
}
|
|
public bool IsReadOnly
|
{
|
get { return false; }
|
}
|
|
public bool Remove(ProductMeasureResult item)
|
{
|
return productList.Remove(item);
|
}
|
|
public IEnumerator<ProductMeasureResult> GetEnumerator()
|
{
|
return productList.GetEnumerator();
|
}
|
|
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
{
|
return productList.GetEnumerator();
|
}
|
}
|
}
|