#002 对分发任务的 数据对象,操作对象,查询,新增,编辑,与删除功能进行开发
This commit is contained in:
@@ -1,144 +1,199 @@
|
||||
using System;
|
||||
using DAL;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
|
||||
using Telerik.WinControls.UI;
|
||||
using DAL;
|
||||
|
||||
namespace NSAnalysis
|
||||
{
|
||||
public partial class FToleranceSetup : Telerik.WinControls.UI.ShapedForm
|
||||
{
|
||||
private TMeasureMSSQLDAL tmdal = new TMeasureMSSQLDAL();
|
||||
public int idgvSelectRowNumber = 0;
|
||||
public partial class FToleranceSetup : Telerik.WinControls.UI.ShapedForm
|
||||
{
|
||||
private TMeasureMSSQLDAL tmdal = new TMeasureMSSQLDAL();
|
||||
public int idgvSelectRowNumber = 0;
|
||||
|
||||
#region 鼠标事件
|
||||
#region 鼠标事件
|
||||
|
||||
private void btn_MouseHover(object sender, EventArgs e)
|
||||
{
|
||||
RadButton btn = sender as RadButton;
|
||||
btn.BackColor = Color.FromArgb(0, 151, 186);
|
||||
}
|
||||
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);
|
||||
}
|
||||
private void btn_MouseLeave(object sender, EventArgs e)
|
||||
{
|
||||
RadButton btn = sender as RadButton;
|
||||
btn.BackColor = Color.FromArgb(19, 46, 53);
|
||||
}
|
||||
|
||||
#endregion 鼠标事件
|
||||
#endregion 鼠标事件
|
||||
|
||||
public FToleranceSetup()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
public FToleranceSetup()
|
||||
{
|
||||
InitializeComponent();
|
||||
InitStatusComboBox();
|
||||
SQLHelper.connStr = DatabaseDfn.SqlConnectStr();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
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());
|
||||
// 初始化ComboBox数据源
|
||||
private void InitStatusComboBox()
|
||||
{
|
||||
var statusList = new List<KeyValuePair<string, string>>();
|
||||
statusList.Add(new KeyValuePair<string, string>("全部", "all"));
|
||||
statusList.Add(new KeyValuePair<string, string>("启动", "start"));
|
||||
statusList.Add(new KeyValuePair<string, string>("停止", "stop"));
|
||||
|
||||
//if (dt.Rows.Count > 0)
|
||||
//{
|
||||
// dgvTolList.DataSource = dt;
|
||||
// SetdgvRowBgColor(dgvTolList);
|
||||
// labSearchResult.Visible = false;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// dgvTolList.DataSource = dt;
|
||||
// labSearchResult.Visible = true;
|
||||
//}
|
||||
}
|
||||
CB_TaskStatus.DataSource = statusList;
|
||||
CB_TaskStatus.DisplayMember = "Key";
|
||||
CB_TaskStatus.ValueMember = "Value";
|
||||
|
||||
/// <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 string GetSelectedStatus()
|
||||
{
|
||||
if (CB_TaskStatus.SelectedIndex < 0)
|
||||
return string.Empty;
|
||||
|
||||
private void lpcAddTol_Click(object sender, EventArgs e)
|
||||
{
|
||||
FAddTolerance fat = new FAddTolerance(this);
|
||||
fat.ShowDialog(this);
|
||||
}
|
||||
return CB_TaskStatus.SelectedValue.ToString();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
public void rtbnSearch_Click(object sender, EventArgs e)
|
||||
{
|
||||
DataTable dt = tmdal.SelectTaskByCondition(rtbCarName.Text.Trim(), rtbCarModel.Text.Trim(), GetSelectedStatus());
|
||||
|
||||
if (buttonText == "修改" || buttonText == "Edit")
|
||||
{
|
||||
idgvSelectRowNumber = e.RowIndex;
|
||||
FEditTolerance sfeditcnc = new FEditTolerance(this);
|
||||
sfeditcnc.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
dgvTolList.AutoGenerateColumns = false;
|
||||
dgvTolList.DataSource = dt;
|
||||
SetdgvRowBgColor(dgvTolList);
|
||||
labSearchResult.Visible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
dgvTolList.AutoGenerateColumns = false;
|
||||
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 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 modelName = dgvTolList.Rows[e.RowIndex].Cells["modelsName"].Value.ToString();
|
||||
string modelsCode = dgvTolList.Rows[e.RowIndex].Cells["modelsCode"].Value.ToString();
|
||||
|
||||
if (string.IsNullOrEmpty(modelsCode) || string.IsNullOrEmpty(modelName))
|
||||
{
|
||||
MessageBox.Show("分发配置代码或名称不能为空,无法删除!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
tmdal.UpdateIsDelete(modelName,modelsCode);
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
private void dgvTolList_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
|
||||
{
|
||||
if (dgvTolList.Columns
|
||||
.Cast<DataGridViewColumn>()
|
||||
.Any(c => c.DataPropertyName == "status" && c.Index == e.ColumnIndex))
|
||||
|
||||
{
|
||||
switch (e.Value.ToString())
|
||||
{
|
||||
case "start": e.Value = "启动"; break;
|
||||
case "stop": e.Value = "停止"; break;
|
||||
}
|
||||
}
|
||||
|
||||
if (dgvTolList.Columns
|
||||
.Cast<DataGridViewColumn>()
|
||||
.Any(c => c.DataPropertyName == "readType" && c.Index == e.ColumnIndex))
|
||||
{
|
||||
switch (e.Value.ToString())
|
||||
{
|
||||
case "1": e.Value = "文件名称"; break;
|
||||
case "2": e.Value = "文件内容"; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user