Skip to content

Commit

Permalink
修正合并,并修正基础数据的查询语句
Browse files Browse the repository at this point in the history
  • Loading branch information
katway committed Dec 11, 2012
1 parent 3223da3 commit 46bcb2b
Show file tree
Hide file tree
Showing 15 changed files with 2,020 additions and 500 deletions.
2 changes: 1 addition & 1 deletion Application/Code/SqlHelper.cs
Expand Up @@ -14,7 +14,7 @@ namespace WorkStation
/// </summary>
public sealed class SqlHelper
{
private static string sqlConnectionStr = "Data Source=192.168.1.221;Initial Catalog=PatrolCheck;User Id=sa;Password=sa123";
private static string sqlConnectionStr = "Data Source=192.168.1.221;Initial Catalog=Patrol;User Id=sa;Password=sa123";

#region 私有构造函数和方法
private SqlHelper()
Expand Down
11 changes: 3 additions & 8 deletions Application/WorkStation.csproj
Expand Up @@ -109,7 +109,7 @@
<Compile Include="frmMainTool.Designer.cs">
<DependentUpon>frmMainTool.cs</DependentUpon>
</Compile>
<Compile Include="frmReportAnalysisByEmployee.cs">
<Compile Include="frmReportAnalysisByEmployee.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="frmReportAnalysisByEmployee.Designer.cs">
Expand All @@ -128,7 +128,6 @@
<DependentUpon>frmPlanExamine.cs</DependentUpon>
</Compile>
<Compile Include="frmPlanToTask.cs">
<Compile Include="frmPlanToTask.Designer.cs">
<DependentUpon>frmPlanToTask.cs</DependentUpon>
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -260,7 +259,7 @@
<Compile Include="MyReport\ReportSearchByPlan.Designer.cs">
<DependentUpon>ReportSearchByPlan.cs</DependentUpon>
</Compile>
<Compile Include="frmReportAnalysisByPlan.cs">
<Compile Include="frmReportAnalysisByPlan.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="frmReportAnalysisByPlan.Designer.cs">
Expand All @@ -278,7 +277,7 @@
<EmbeddedResource Include="frmMainTool.resx">
<DependentUpon>frmMainTool.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="frmReportAnalysisByEmployee.resx">
<EmbeddedResource Include="frmReportAnalysisByEmployee.resx">
<DependentUpon>frmReportAnalysisByEmployee.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="frmPlan.resx">
Expand Down Expand Up @@ -329,8 +328,6 @@
<EmbeddedResource Include="frmPostEditDelete.resx">
<DependentUpon>frmPostEditDelete.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="frmEmployeeNew.resx">
<DependentUpon>frmEmployeeNew.cs</DependentUpon>
<EmbeddedResource Include="frmEmployeeNew.resx">
<DependentUpon>frmEmployeeNew.cs</DependentUpon>
</EmbeddedResource>
Expand Down Expand Up @@ -377,8 +374,6 @@
</None>
<None Include="MyDataSet\ReportSearchByPoint.xss">
<DependentUpon>ReportSearchByPoint.xsd</DependentUpon>
</None>
<DependentUpon>HflDataSet_Plan.xsd</DependentUpon>
</None>
<None Include="Properties\Settings.settings">
<Generator>PublicSettingsSingleFileGenerator</Generator>
Expand Down
2 changes: 1 addition & 1 deletion Application/frmEmployeeEditDelete.cs
Expand Up @@ -174,7 +174,7 @@ private void frmEditOrDeleteEmployee_Load(object sender, EventArgs e)
/// </summary>
public void BindEmployee()
{
string selectEmployee = "select Employee.ID,Employee.Name emName,Employee.Alias alias,Rfid.Name Name,Post.Name postName,(select meaning from codes where code=Employee.validstate and purpose='validstate') as ValidState from Employee,Rfid,Post,Post_Employee where Employee.ID=Post_Employee.Employee_ID and Employee.Rfid_ID=Rfid.ID and Post_Employee.ID=Post.ID";
string selectEmployee = "select Employee.ID,Employee.Name emName,Employee.Alias alias,Rfid.Name Name,Post.Name postName,(select meaning from codes where code=Employee.validstate and purpose='validstate') as ValidState from Employee,Rfid,Post,Post_Employee where Employee.ID=Post_Employee.Employee_ID and Employee.Rfid_ID=Rfid.ID and Post_Employee.Post_ID=Post.ID";
DataSet ds = SqlHelper.ExecuteDataset(selectEmployee);
ds.Tables[0].Columns.Add(new DataColumn("check", typeof(System.Boolean)));
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
Expand Down
16 changes: 11 additions & 5 deletions Application/frmEmployeeNew.cs
Expand Up @@ -15,7 +15,7 @@ public frmEmployeeNew()
{
InitializeComponent();
}
private static string sqlConnectionStr = "Data Source=192.168.1.221;Initial Catalog=PatrolCheck;User ID=sa;Password=sa123";

/// <summary>
/// 保存
/// </summary>
Expand Down Expand Up @@ -61,7 +61,8 @@ private void btnSave_Click(object sender, EventArgs e)
par[1].Value = this.txtAlias.Text;
par[2].Value = this.cboCard.SelectedValue.ToString();
par[3].Value = this.cboState.SelectedValue.ToString();
string id = SqlHelper.ExecuteScalar(sqlConnectionStr, CommandType.Text, insertEmpoyee, par).ToString();
// string id = SqlHelper.ExecuteScalar( CommandType.Text, insertEmpoyee, par).ToString();
int id = SqlHelper.ExecuteNonQuery(insertEmpoyee,par);
if (id != null)
{
MessageBox.Show("保存成功!");
Expand All @@ -75,7 +76,7 @@ private void btnSave_Click(object sender, EventArgs e)

par1[0].Value = id;
par1[1].Value = this.cboPost.SelectedValue.ToString();
int i = SqlHelper.ExecuteNonQuery(sqlConnectionStr, CommandType.Text, insertEmpoyeePost, par1);
int i = SqlHelper.ExecuteNonQuery( insertEmpoyeePost, par1);
}
BindEmployee();

Expand All @@ -85,8 +86,13 @@ private void btnSave_Click(object sender, EventArgs e)
/// </summary>
public void BindEmployee()
{
string selectEmployee = "select Employee.ID,Employee.Name emName,Employee.Alias alias,Rfid.Name Name,Post.Name postName,(select meaning from codes where code=Employee.validstate and purpose='validstate') as ValidState from Employee,Rfid,Post,Post_Employee where Employee.ID=Post_Employee.Employee_ID and Employee.Rfid_ID=Rfid.ID and Post_Employee.ID=Post.ID";
DataSet ds = SqlHelper.ExecuteDataset(sqlConnectionStr, CommandType.Text, selectEmployee);
string selectEmployee = @"select
ID,Name as emName,Alias,
(select name from rfid where id=Rfid_ID) as Name,
(select name from post where id=(SELECT post_id from Post_Employee where Employee_ID=ID)) as postname,
(select meaning from codes where code=Employee.validstate and purpose='validstate') as ValidState
from Employee";
DataSet ds = SqlHelper.ExecuteDataset(selectEmployee);
this.gridControl1.DataSource = ds.Tables[0];
}
/// <summary>
Expand Down
213 changes: 213 additions & 0 deletions Application/frmItem.cs
@@ -0,0 +1,213 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WorkStation
{
public partial class frmItem : Form
{
public frmItem()
{
InitializeComponent();
}

private void frmAddItem_Load(object sender, EventArgs e)
{
this.labID.Text = "";
bkwItem.RunWorkerAsync();
bindDgvItems();
}

private void btnSave_Click(object sender, EventArgs e)
{
if (txtName.Text == "" || txtRemarks.Text == "")
{
MessageBox.Show("请确保没有空值");
return;
}
if (SqlHelper.ExecuteScalar("Select count(1) From CheckItem Where Name='" + this.txtName.Text.Trim() + "'").ToString() != "0")
{
MessageBox.Show("请确保名称的唯一性");
return;
}
string str_insert = "Insert into CheckItem([Name],Alias,Comment";
string str_value="Values(@name,@alias,@comment";
SqlParameter[] pars = new SqlParameter[]{
new SqlParameter("@name",SqlDbType.NVarChar),
new SqlParameter("@alias",SqlDbType.NVarChar),
new SqlParameter("@machineid",SqlDbType.Int),
new SqlParameter("@valuetype",SqlDbType.Int),
new SqlParameter("@pointid",SqlDbType.Int),
new SqlParameter("@comment",SqlDbType.NText)
};
if (((BoxItem)(cboMachine.SelectedItem)).Value.ToString() != "-1")
{
str_insert += ",Machine_ID";
str_value += ",@machineid";

}
if (((BoxItem)cboPoint.SelectedItem).Value.ToString() != "-1")
{
str_insert += ",ValueType";
str_value += ",@valuetype";
}
if (((BoxItem)cboValue.SelectedItem).Value.ToString() != "-1")
{
str_insert += ",Phy_ID";
str_insert += ",@pointid";
}

pars[0].Value = this.txtName.Text.ToString().Trim();
pars[1].Value = this.txtAlias.Text.ToString().Trim();
pars[2].Value = (this.cboMachine.SelectedItem as BoxItem).Value;
pars[3].Value = (this.cboValue.SelectedItem as BoxItem).Value;
pars[4].Value = (this.cboPoint.SelectedItem as BoxItem).Value;
pars[5].Value = this.txtRemarks.Text;

string sql_insert = str_insert + ") " + str_value + ")";
int _ret = SqlHelper.ExecuteNonQuery(sql_insert, pars);
if (_ret == 1)
{
MessageBox.Show("保存成功");
}
bindDgvItems();
}

private void bindDgvItems()
{
string str_select = @"select
c.ID,
c.Name,
c.Alias,
(select meaning from codes where code=c.valuetype and purpose='valuetype') as ValueTypeMeaning,
c.ValueType,
m.ID as MachineID,
m.name as MachineName,
p.ID as PointID,
p.name as PointName,
c.Comment
from checkitem c left join Machine m on c.machine_id=m.id
left join PhysicalCheckPoint p on c.Phy_ID=p.id";
DataSet ds = SqlHelper.ExecuteDataset(str_select);
ds.Tables[0].Columns.Add(new DataColumn("isCheck",typeof(System.Boolean)));
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
ds.Tables[0].Rows[i]["isCheck"] = false;
}
gridControlItems.DataSource = ds.Tables[0];
}

private void btnUpdate_Click(object sender, EventArgs e)
{
if (labID.Text == "")
{
return;
}
if (txtName.Text == "" || txtRemarks.Text == "" || cboMachine.SelectedIndex < 0 || cboPoint.SelectedIndex < 0 || cboValue.SelectedIndex < 0)
{
MessageBox.Show("请确保没有空值");
return;
}
if (SqlHelper.ExecuteScalar("Select count(1) From CheckItem Where id!=" + labID.Text.Trim() + " and name='" + this.txtName.Text.Trim() + "'").ToString() != "0")
{
MessageBox.Show("请确保名称的唯一性" );
return;
}
string str_insert = "Update CheckItem set [Name]=@name,Alias=@alias,Machine_ID=@machineid,ValueType=@valuetype,Phy_ID=@phyid,Comment=@comment where ID=" + labID.Text.Trim();
SqlParameter[] pars = new SqlParameter[]{
new SqlParameter("@name",SqlDbType.NVarChar),
new SqlParameter("@alias",SqlDbType.NVarChar),
new SqlParameter("@machineid",SqlDbType.Int),
new SqlParameter("@valuetype",SqlDbType.Int),
new SqlParameter("@phyid",SqlDbType.Int),
new SqlParameter("@comment",SqlDbType.NText)
};
pars[0].Value = this.txtName.Text.ToString().Trim();
pars[1].Value = this.txtAlias.Text.ToString().Trim();
pars[2].Value = (this.cboMachine.SelectedItem as BoxItem).Value;
pars[3].Value = (this.cboValue.SelectedItem as BoxItem).Value;
pars[4].Value = (this.cboPoint.SelectedItem as BoxItem).Value;
pars[5].Value = this.txtRemarks.Text;

int _ret = SqlHelper.ExecuteNonQuery(str_insert, pars);
if (_ret == 1)
{
MessageBox.Show("保存成功");
}
bindDgvItems();
}
private void btnDel_Click(object sender, EventArgs e)
{
string Del = "";
string strsql = "Delete From CheckItem Where ID in(";
for (int i = 0; i < gvItems.RowCount; i++)
{
Del += gvItems.GetRowCellValue(i,"ID")+",";
}
if (Del != "")
{
Del = Del.Substring(0, Del.Length - 1);
strsql += Del + ")";
SqlHelper.ExecuteNonQuery(strsql);
bindDgvItems();
}
else
{
MessageBox.Show("请选择要删除的项");
}
}

DataSet dsMachine, dsValueType, dsPoint;
private void bkwItem_DoWork(object sender, DoWorkEventArgs e)
{
dsMachine = SqlHelper.ExecuteDataset("select ID,Name From Machine where validstate=1");
dsValueType = SqlHelper.ExecuteDataset("Select Code,Meaning From Codes where Purpose='ValueType'");
dsPoint = SqlHelper.ExecuteDataset("select ID,Name From PhysicalCheckPoint where validstate=1");
}

private void bkwItem_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
DataRow dr = dsMachine.Tables[0].NewRow();
dr[0] = "-1"; dr[1] = "全部";
dsMachine.Tables[0].Rows.InsertAt(dr,0);
cboMachine.ValueMember = "ID";
cboMachine.DisplayMember = "Name";
cboMachine.DataSource = dsMachine.Tables[0];
dsMachine.Dispose();

DataRow dr1 = dsPoint.Tables[0].NewRow();
dr1[0] = "-1"; dr1[1] = "全部";
dsPoint.Tables[0].Rows.InsertAt(dr1, 0);
cboPoint.ValueMember = "ID";
cboPoint.DisplayMember = "Name";
cboPoint.DataSource = dsPoint.Tables[0];
dsPoint.Dispose();

DataRow dr2 = dsPoint.Tables[0].NewRow();
dr2[0] = "-1"; dr2[1] = "全部";
dsPoint.Tables[0].Rows.InsertAt(dr2, 0);
cboValue.ValueMember = "Code";
cboValue.DisplayMember = "Meaning";
cboValue.DataSource = dsValueType.Tables[0];
dsValueType.Dispose();
}

private void gvItem_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
{
if (e.RowHandle < 0) return;
labID.Text = gvItems.GetRowCellValue(e.RowHandle,"ID").ToString();
txtName.Text = gvItems.GetRowCellValue(e.RowHandle, "Name").ToString();
txtAlias.Text = gvItems.GetRowCellValue(e.RowHandle, "Alias").ToString();
cboValue.SelectedValue = gvItems.GetRowCellValue(e.RowHandle, "ValueType");
cboMachine.SelectedValue = gvItems.GetRowCellValue(e.RowHandle, "MachineID") ;
cboPoint.SelectedValue = gvItems.GetRowCellValue(e.RowHandle, "PointID");
txtRemarks.Text = gvItems.GetRowCellValue(e.RowHandle, "Comment").ToString();
}
}
}

0 comments on commit 46bcb2b

Please sign in to comment.