//删除 public static void Delete(EY_Scale_Value VO) { using (ISession session = SessionHelper.GetSession()) { session.Delete(VO); session.Flush(); } }
//求平行样的平均数用 public static IList<EY_Scale_Value> GetAverage(EY_Scale_Value id) { using (ISession session = SessionHelper.GetSession()) { IQuery query = session.CreateQuery(" from EY_Scale_Value as a where a.Id = :s "); query.SetParameter("s", id); return query.List<EY_Scale_Value>(); } }
public static IList<EY_Scale_Value> Create(EY_Scale_Value EY_Scale_Value_Vo) { using (ISession session = SessionHelper.GetSession()) { session.Save(EY_Scale_Value_Vo); session.Flush(); } return null; }
//修改数据 private void buttonX2_Click(object sender, EventArgs e) { int Row = dataGridViewX1.Rows.GetRowCount(DataGridViewElementStates.Displayed) - 1; if (Row < 1) { MessageBox.Show("没有数据可以修改", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } int ss = EY_Scale_Value_Status(); if (ss == 0) { try { int RowCount = dataGridViewX1.Rows.GetRowCount(DataGridViewElementStates.Displayed) - 1; for (int i = 0; i < RowCount; i++) { EY_Scale_Value EY_Scale_Value_Vo = new EY_Scale_Value(); EY_Scale_Value_PK ssss = new EY_Scale_Value_PK(); ssss.RegNo = Convert.ToString(dataGridViewX1.Rows[i].Cells[1].Value); ssss.CheckNo = Convert.ToString(dataGridViewX1.Rows[i].Cells[2].Value); EY_Scale_Value_Vo.Id = ssss; IList<EY_Scale_Value> zzz = EY_Scale_Value_Dao.GetRegNo1(ssss); foreach (EY_Scale_Value t in zzz) { EY_Scale_Value_Vo.Matrname = t.Matrname; EY_Scale_Value_Vo.Date = t.Date; EY_Scale_Value_Vo.PanWgt = Convert.ToDecimal(dataGridViewX1.Rows[i].Cells[4].Value); if (EY_Scale_Value_Vo.PanWgt != t.PanWgt) { Writelog(Convert.ToString(t.PanWgt), Convert.ToString(EY_Scale_Value_Vo.PanWgt), "盘重",ssss); EY_Scale_Value_Vo.Flag = t.Flag + 1; } EY_Scale_Value_Vo.YangWgt = Convert.ToDecimal(dataGridViewX1.Rows[i].Cells[5].Value); if (EY_Scale_Value_Vo.YangWgt != t.YangWgt) { Writelog(Convert.ToString(t.YangWgt), Convert.ToString(EY_Scale_Value_Vo.YangWgt), "样重", ssss); EY_Scale_Value_Vo.Flag = t.Flag + 1; } EY_Scale_Value_Vo.HengWgt1 = Convert.ToDecimal(dataGridViewX1.Rows[i].Cells[6].Value); if (EY_Scale_Value_Vo.HengWgt1 != t.HengWgt1) { Writelog(Convert.ToString(t.HengWgt1), Convert.ToString(EY_Scale_Value_Vo.HengWgt1), "恒重1", ssss); EY_Scale_Value_Vo.Flag = t.Flag + 1; } EY_Scale_Value_Vo.HengWgt2 = Convert.ToDecimal(dataGridViewX1.Rows[i].Cells[7].Value); if (EY_Scale_Value_Vo.HengWgt2 != t.HengWgt2) { Writelog(Convert.ToString(t.HengWgt2), Convert.ToString(EY_Scale_Value_Vo.HengWgt2), "恒重2", ssss); EY_Scale_Value_Vo.Flag = t.Flag + 1; } EY_Scale_Value_Vo.HengWgt3 = Convert.ToDecimal(dataGridViewX1.Rows[i].Cells[8].Value); if (EY_Scale_Value_Vo.HengWgt3 != t.HengWgt3) { Writelog(Convert.ToString(t.HengWgt3), Convert.ToString(EY_Scale_Value_Vo.HengWgt3), "恒重3", ssss); EY_Scale_Value_Vo.Flag = t.Flag + 1; } EY_Scale_Value_Vo.HengWgt4 = Convert.ToDecimal(dataGridViewX1.Rows[i].Cells[9].Value); if (EY_Scale_Value_Vo.HengWgt4 != t.HengWgt4) { Writelog(Convert.ToString(t.HengWgt4), Convert.ToString(EY_Scale_Value_Vo.HengWgt4), "恒重4", ssss); EY_Scale_Value_Vo.Flag = t.Flag + 1; } EY_Scale_Value_Vo.FinalValue = Convert.ToDecimal(dataGridViewX1.Rows[i].Cells[10].Value); if (EY_Scale_Value_Vo.FinalValue != t.FinalValue) { Writelog(Convert.ToString(t.FinalValue), Convert.ToString(EY_Scale_Value_Vo.FinalValue), "结果", ssss); EY_Scale_Value_Vo.Flag = t.Flag + 1; } EY_Scale_Value_Vo.Operator1 = t.Operator1; EY_Scale_Value_Vo.Operator2 = Convert.ToString(dataGridViewX1.Rows[i].Cells[12].Value); if (EY_Scale_Value_Vo.Operator2 != t.Operator2) { Writelog(Convert.ToString(t.Operator2), Convert.ToString(EY_Scale_Value_Vo.Operator2), "备注", ssss); EY_Scale_Value_Vo.Flag = t.Flag + 1; } EY_Scale_Value_Vo.Mem1 = Convert.ToString(dataGridViewX1.Rows[i].Cells[13].Value); if (EY_Scale_Value_Vo.Mem1 != t.Mem1) { Writelog(Convert.ToString(t.Mem1 ), Convert.ToString(EY_Scale_Value_Vo.Mem1), "备注", ssss); EY_Scale_Value_Vo.Flag = t.Flag + 1; } // EY_Scale_Value_Vo.ToErpFlag = "0"; //数据被修改过 EY_Scale_Value_Vo.Status = t.Status; EY_Scale_Value_Vo.ToErpFlag = t.ToErpFlag; //EY_Scale_Value_Vo.Mem1 = t.Mem1; } EY_Scale_Value_Dao.Update(EY_Scale_Value_Vo); } MessageBox.Show("修改数据成功"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("已产制报表,无法修改数据,请联系管理员"); } }
//保存数据 private void buttonX1_Click(object sender, EventArgs e) { try { int RowCount = dataGridViewX1.Rows.GetRowCount(DataGridViewElementStates.Displayed) - 1; for (int i = 0; i < RowCount; i++) { EY_Scale_Value EY_Scale_Value_Vo = new EY_Scale_Value(); EY_Scale_Value_PK spk = new EY_Scale_Value_PK(); // EY_Scale_Value_Vo.Date = Convert.ToDateTime(dataGridViewX1.Rows[i].Cells[0].Value); EY_Scale_Value_Vo.Date = Convert.ToDateTime(dataGridViewX1.Rows[i].Cells[0].Value); spk.RegNo = Convert.ToString(dataGridViewX1.Rows[i].Cells[1].Value); spk.CheckNo = Convert.ToString(dataGridViewX1.Rows[i].Cells[2].Value); // EY_Scale_Value_Vo.RegNo = Convert.ToString(dataGridViewX1.Rows[i].Cells[1].Value); // EY_Scale_Value_Vo.CheckNo = Convert.ToString(dataGridViewX1.Rows[i].Cells[2].Value); EY_Scale_Value_Vo.Id = spk; EY_Scale_Value_Vo.Matrname = Convert.ToString(dataGridViewX1.Rows[i].Cells[3].Value); EY_Scale_Value_Vo.PanWgt = Convert.ToDecimal(dataGridViewX1.Rows[i].Cells[4].Value); EY_Scale_Value_Vo.YangWgt = Convert.ToDecimal(dataGridViewX1.Rows[i].Cells[5].Value); EY_Scale_Value_Vo.HengWgt1 = Convert.ToDecimal(dataGridViewX1.Rows[i].Cells[6].Value); EY_Scale_Value_Vo.HengWgt2 = Convert.ToDecimal(dataGridViewX1.Rows[i].Cells[7].Value); EY_Scale_Value_Vo.HengWgt3 = Convert.ToDecimal(dataGridViewX1.Rows[i].Cells[8].Value); EY_Scale_Value_Vo.HengWgt4 = Convert.ToDecimal(dataGridViewX1.Rows[i].Cells[9].Value); EY_Scale_Value_Vo.FinalValue = Convert.ToDecimal(dataGridViewX1.Rows[i].Cells[10].Value); EY_Scale_Value_Vo.Operator1 = Convert.ToString(dataGridViewX1.Rows[i].Cells[11].Value); EY_Scale_Value_Vo.Operator2 = Convert.ToString(dataGridViewX1.Rows[i].Cells[12].Value); EY_Scale_Value_Vo.Mem1 = Convert.ToString(dataGridViewX1.Rows[i].Cells[13].Value); ////上传ERP标志位 //EY_Scale_Value_Vo.ToErpFlag = "0"; ////修改标志位 //EY_Scale_Value_Vo.Flag = "0"; ////产制报表后变Y后数据不可修改 //EY_Scale_Value_Vo.Status = "N"; if (EY_Scale_Value_Dao.GetRegNo1(EY_Scale_Value_Vo.Id).Count==0) { EY_Scale_Value_Vo.ToErpFlag = "0"; EY_Scale_Value_Vo.Flag = 0; EY_Scale_Value_Vo.Status = "N"; EY_Scale_Value_Dao.Create(EY_Scale_Value_Vo); }else { EY_Scale_Value_Dao.Update(EY_Scale_Value_Vo); } } MessageBox.Show("保存数据成功"); } catch(Exception ex) { MessageBox.Show("该批次已保存,请勿重复点击"); MessageBox.Show(ex.Message); } finally { SessionHelper.CloseSession(); } }
//后台保存数据用 private void saveIt() { int ss = EY_Scale_Value_Status(); if (ss == 0) { try { int RowCount = dataGridViewX1.Rows.GetRowCount(DataGridViewElementStates.Displayed) - 1; for (int i = 0; i < RowCount; i++) { EY_Scale_Value EY_Scale_Value_Vo = new EY_Scale_Value(); EY_Scale_Value_PK spk = new EY_Scale_Value_PK(); // EY_Scale_Value_Vo.Date = Convert.ToDateTime(dataGridViewX1.Rows[i].Cells[0].Value); EY_Scale_Value_Vo.Date = Convert.ToDateTime(dataGridViewX1.Rows[i].Cells[0].Value); spk.RegNo = Convert.ToString(dataGridViewX1.Rows[i].Cells[1].Value); spk.CheckNo = Convert.ToString(dataGridViewX1.Rows[i].Cells[2].Value); // EY_Scale_Value_Vo.RegNo = Convert.ToString(dataGridViewX1.Rows[i].Cells[1].Value); // EY_Scale_Value_Vo.CheckNo = Convert.ToString(dataGridViewX1.Rows[i].Cells[2].Value); EY_Scale_Value_Vo.Id = spk; EY_Scale_Value_Vo.Matrname = Convert.ToString(dataGridViewX1.Rows[i].Cells[3].Value); EY_Scale_Value_Vo.PanWgt = Convert.ToDecimal(dataGridViewX1.Rows[i].Cells[4].Value); EY_Scale_Value_Vo.YangWgt = Convert.ToDecimal(dataGridViewX1.Rows[i].Cells[5].Value); EY_Scale_Value_Vo.HengWgt1 = Convert.ToDecimal(dataGridViewX1.Rows[i].Cells[6].Value); EY_Scale_Value_Vo.HengWgt2 = Convert.ToDecimal(dataGridViewX1.Rows[i].Cells[7].Value); EY_Scale_Value_Vo.HengWgt3 = Convert.ToDecimal(dataGridViewX1.Rows[i].Cells[8].Value); EY_Scale_Value_Vo.HengWgt4 = Convert.ToDecimal(dataGridViewX1.Rows[i].Cells[9].Value); EY_Scale_Value_Vo.FinalValue = Convert.ToDecimal(dataGridViewX1.Rows[i].Cells[10].Value); EY_Scale_Value_Vo.Operator1 = Convert.ToString(dataGridViewX1.Rows[i].Cells[11].Value); EY_Scale_Value_Vo.Operator2 = Convert.ToString(dataGridViewX1.Rows[i].Cells[12].Value); EY_Scale_Value_Vo.Mem1 = Convert.ToString(dataGridViewX1.Rows[i].Cells[13].Value); EY_Scale_Value_Vo.ToErpFlag = "0"; EY_Scale_Value_Vo.Flag = 0; EY_Scale_Value_Vo.Status = "N"; if (EY_Scale_Value_Dao.GetRegNo1(EY_Scale_Value_Vo.Id).Count == 0) { //EY_Scale_Value_Vo.ToErpFlag = "0"; //EY_Scale_Value_Vo.Flag = "0"; //EY_Scale_Value_Vo.Status = "N"; EY_Scale_Value_Dao.Create(EY_Scale_Value_Vo); } else { EY_Scale_Value_Dao.Update(EY_Scale_Value_Vo); } } // MessageBox.Show("保存数据成功"); } catch (Exception ex) { MessageBox.Show("saveit方法报错"); MessageBox.Show(ex.Message); } //finally //{ // SessionHelper.CloseSession(); //} } }
//判断数据是否产制报表,如果产制报表不可修改 private int EY_Scale_Value_Status() { int flag = 0; EY_Scale_Value EY_Scale_Value = new EY_Scale_Value(); EY_Scale_Value_PK spk = new EY_Scale_Value_PK(); spk.RegNo = Convert.ToString(dataGridViewX1.CurrentRow.Cells[1].Value); spk.CheckNo = Convert.ToString(dataGridViewX1.CurrentRow.Cells[2].Value); EY_Scale_Value.Id = spk; IList<EY_Scale_Value> EY_Scale_value_Status = EY_Scale_Value_Dao.GetRegNo1(EY_Scale_Value.Id); foreach (EY_Scale_Value t in EY_Scale_value_Status) { if (t.Status == "Y") { // MessageBox.Show("已产制报表,数据不可修改,请联系管理人员"); flag = 1; } } return flag; }