189 lines
5.3 KiB
C#
189 lines
5.3 KiB
C#
using DAL;
|
|
using System;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
using Telerik.WinControls.UI;
|
|
|
|
namespace NSAnalysis
|
|
{
|
|
public partial class FToleranceSetup : Telerik.WinControls.UI.ShapedForm
|
|
{
|
|
private TMeasureMSSQLDAL tmdal = new TMeasureMSSQLDAL();
|
|
public int idgvSelectRowNumber = 0;
|
|
|
|
#region 鼠标事件
|
|
|
|
private void btn_MouseHover(object sender, EventArgs e)
|
|
{
|
|
RadButton btn = sender as RadButton;
|
|
btn.BackColor = Color.FromArgb(0, 151, 186);
|
|
}
|
|
|
|
private void btn_MouseLeave(object sender, EventArgs e)
|
|
{
|
|
RadButton btn = sender as RadButton;
|
|
btn.BackColor = Color.FromArgb(19, 46, 53);
|
|
}
|
|
|
|
#endregion 鼠标事件
|
|
|
|
public FToleranceSetup()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void FToleranceSetup_Load(object sender, EventArgs e)
|
|
{
|
|
dgvTolList.ColumnHeadersDefaultCellStyle.Font = new Font("Segoe UI", 10, FontStyle.Regular);
|
|
lpcAddTol.labPicture.Click += lpcAddTol_Click;
|
|
lpcAddTol.labText.Click += lpcAddTol_Click;
|
|
rtbnSearch_Click(null, null);
|
|
}
|
|
|
|
public void rtbnSearch_Click(object sender, EventArgs e)
|
|
{
|
|
DataTable dt = tmdal.SelectAllToleranceByCondition(rtbCarModel.Text.Trim(), rtbMesPointName.Text.Trim(), rtbDimensionName.Text.Trim());
|
|
|
|
if (dt.Rows.Count > 0)
|
|
{
|
|
dgvTolList.DataSource = dt;
|
|
SetdgvRowBgColor(dgvTolList);
|
|
labSearchResult.Visible = false;
|
|
}
|
|
else
|
|
{
|
|
dgvTolList.DataSource = dt;
|
|
labSearchResult.Visible = true;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置DataGridView各行变色
|
|
/// </summary>
|
|
/// <param name="dgv">DataGridView</param>
|
|
public void SetdgvRowBgColor(DataGridView dgv)
|
|
{
|
|
if (dgv.Rows.Count > 0)
|
|
{
|
|
foreach (DataGridViewRow item in dgv.Rows)
|
|
{
|
|
if (item.Index % 2 == 0)
|
|
{
|
|
item.DefaultCellStyle.BackColor = Color.FromArgb(19, 46, 53);
|
|
}
|
|
else
|
|
{
|
|
item.DefaultCellStyle.BackColor = Color.FromArgb(27, 60, 68);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void dgvTolList_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
|
|
{
|
|
e.Row.HeaderCell.Value = string.Format("{0}", e.Row.Index + 1);
|
|
}
|
|
|
|
private void lpcAddTol_Click(object sender, EventArgs e)
|
|
{
|
|
FAddTolerance fat = new FAddTolerance(this);
|
|
fat.ShowDialog(this);
|
|
}
|
|
|
|
private void rbtnDownloadTemplate_Click(object sender, EventArgs e)
|
|
{
|
|
SaveFileDialog sfd = new SaveFileDialog
|
|
{
|
|
Filter = "CSV文件|*.csv",
|
|
FileName = "公差导入模板.csv",
|
|
Title = "保存CSV模板"
|
|
};
|
|
if (sfd.ShowDialog() != DialogResult.OK) return;
|
|
|
|
string header = "CarType,MeasurePointName,DimensionName,TolLower,TolUpper,Remark";
|
|
string example = "EHV,L-01,F,-1.5,0.5,示例备注";
|
|
System.IO.File.WriteAllText(sfd.FileName, header + "\r\n" + example + "\r\n", System.Text.Encoding.UTF8);
|
|
MessageBox.Show("模板已保存:" + sfd.FileName, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
|
|
private void rbtnImportTol_Click(object sender, EventArgs e)
|
|
{
|
|
OpenFileDialog ofd = new OpenFileDialog
|
|
{
|
|
Filter = "CSV文件|*.csv",
|
|
Title = "选择公差导入文件"
|
|
};
|
|
if (ofd.ShowDialog() != DialogResult.OK) return;
|
|
|
|
int successCount = 0, failCount = 0;
|
|
string[] lines = System.IO.File.ReadAllLines(ofd.FileName, System.Text.Encoding.UTF8);
|
|
for (int i = 1; i < lines.Length; i++) // 跳过表头
|
|
{
|
|
string line = lines[i].Trim();
|
|
if (string.IsNullOrEmpty(line)) continue;
|
|
string[] cols = line.Split(',');
|
|
if (cols.Length < 5) { failCount++; continue; }
|
|
try
|
|
{
|
|
string carType = cols[0].Trim();
|
|
string measPointName = cols[1].Trim();
|
|
string dimensionName = cols[2].Trim();
|
|
double tolLower = double.Parse(cols[3].Trim());
|
|
double tolUpper = double.Parse(cols[4].Trim());
|
|
string remark = cols.Length > 5 ? cols[5].Trim() : "";
|
|
tmdal.UpsertTolerance(carType, measPointName, dimensionName, tolLower, tolUpper, remark);
|
|
successCount++;
|
|
}
|
|
catch
|
|
{
|
|
failCount++;
|
|
}
|
|
}
|
|
MessageBox.Show($"导入完成:成功 {successCount} 条,失败 {failCount} 条。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
rtbnSearch_Click(null, null);
|
|
}
|
|
|
|
private void dgvTolList_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
string buttonText = "";
|
|
if (e.RowIndex < 0 || e.ColumnIndex < 0)
|
|
{
|
|
return;
|
|
}
|
|
try
|
|
{
|
|
buttonText = dgvTolList.Columns[e.ColumnIndex].HeaderText;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
buttonText = " ";
|
|
}
|
|
if (buttonText == "删除")
|
|
{
|
|
if (DialogResult.Yes == MessageBox.Show("您确定要删除该条公差带信息吗,注意:删除后不可恢复!", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning))
|
|
{
|
|
string iObjIDPk = dgvTolList.Rows[e.RowIndex].Cells["Id"].Value.ToString();
|
|
try
|
|
{
|
|
tmdal.DeleteOneTolerance(iObjIDPk);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show("删除公差带信息失败,原因:" + ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
return;
|
|
}
|
|
MessageBox.Show("删除公差带信息成功! ", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
rtbnSearch_Click(null, null);
|
|
}
|
|
}
|
|
|
|
if (buttonText == "修改" || buttonText == "Edit")
|
|
{
|
|
idgvSelectRowNumber = e.RowIndex;
|
|
FEditTolerance sfeditcnc = new FEditTolerance(this);
|
|
sfeditcnc.ShowDialog();
|
|
}
|
|
}
|
|
}
|
|
} |