using BO;
|
|
using BO.BO.BaseInfo;
|
|
using BO.Utils;
|
|
using BO.Utils.BillRpc;
|
|
using BWP.WinFormControl;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace WeighAndGrading
|
|
{
|
|
public partial class BodyDiscontSetting : Form
|
|
{
|
|
List<BodyDiscontItem> list;
|
|
string fileName;
|
|
public BodyDiscontSetting()
|
|
{
|
|
InitializeComponent();
|
|
fileName = Path.Combine(GradeFrom.DATA_PATH, "Disconts.xml");
|
|
list = XmlUtil.DeserializeFromFile<List<BodyDiscontItem>>(fileName);
|
|
uDataGridView1.DataSource = list;
|
|
uDataGridView1.Refresh();
|
|
}
|
|
|
|
bool changed = false;
|
|
private void saveBtn_Click(object sender, EventArgs e)
|
|
{
|
|
var list = new List<CTuple<long, decimal?>>();
|
|
foreach (DataGridViewRow row in uDataGridView1.Rows)
|
|
{
|
|
var entity = row.DataBoundItem as BodyDiscontItem;
|
|
list.Add(new CTuple<long, decimal?>(entity.ID, entity.Discont));
|
|
}
|
|
XmlUtil.SerializerObjToFile(list, fileName);
|
|
var changeFlagPath = Path.Combine(GradeFrom.DATA_PATH, "DiscontsChanged.txt");
|
|
bool existFile = File.Exists(changeFlagPath);
|
|
|
|
var connection = LoginRpcUtil.TestConnection();
|
|
if (connection)
|
|
{
|
|
try
|
|
{
|
|
GradeAndWeightRpc.SaveBodyDiscontItem(list);
|
|
if (existFile)
|
|
File.Delete(changeFlagPath);
|
|
}
|
|
catch { }
|
|
}
|
|
else if (!existFile)
|
|
File.WriteAllText(changeFlagPath, string.Empty);
|
|
if (!changed)
|
|
changed = true;
|
|
MessageBox.Show("保存成功!");
|
|
}
|
|
|
|
private void closeBtn_Click(object sender, EventArgs e)
|
|
{
|
|
if (changed)
|
|
DialogResult = DialogResult.OK;
|
|
this.Close();
|
|
}
|
|
|
|
private void uDataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
if (e.RowIndex == -1)
|
|
return;
|
|
if (e.ColumnIndex == uDataGridView1.ColumnCount - 1)
|
|
{
|
|
var keyBoard = new NumberPad();
|
|
if (keyBoard.ShowDialog() == true)
|
|
{
|
|
if (string.IsNullOrEmpty(keyBoard.Result))
|
|
return;
|
|
decimal v;
|
|
if (decimal.TryParse(keyBoard.Result, out v))
|
|
uDataGridView1.CurrentRow.Cells["S_Discont"].Value = v;
|
|
else
|
|
throw new Exception("扣重输入不正确");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|