/// <summary> /// 更新一条数据 /// </summary> /// <param name="model">model</param> public bool ModifyRecord(LCustTagData model) { bool ret = false; StringBuilder strSql = new StringBuilder(); strSql.Append("update LCustTag set "); strSql.Append("custNo=@custNo,"); strSql.Append("materialNo=@materialNo,"); strSql.Append("bigTagFileId=@bigTagFileId,"); strSql.Append("smallTagFileId=@smallTagFileId,"); strSql.Append("bigTagSql=@bigTagSql,"); strSql.Append("smallTagSql=@smallTagSql,"); strSql.Append("eachPrintBigTagNum=@eachPrintBigTagNum,"); strSql.Append("eachPrintSmallTagNum=@eachPrintSmallTagNum,"); strSql.Append("unit=@unit,"); strSql.Append("isDel=@isDel,"); strSql.Append("isrtEmpId=@isrtEmpId,"); strSql.Append("isrtDt=@isrtDt,"); strSql.Append("updtEmpId=@updtEmpId,"); strSql.Append("updtDt=@updtDt,"); strSql.Append("units=@units,"); strSql.Append("bigTagId_304=@bigTagId_304,"); strSql.Append("smallTagId_304=@smallTagId_304,"); strSql.Append("bigTagId_316=@bigTagId_316,"); strSql.Append("smallTagId_316=@smallTagId_316"); strSql.Append(" where id = @id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int), new SqlParameter("@custNo", SqlDbType.VarChar,20), new SqlParameter("@materialNo", SqlDbType.VarChar,20), new SqlParameter("@bigTagFileId", SqlDbType.Int), new SqlParameter("@smallTagFileId", SqlDbType.Int), new SqlParameter("@bigTagSql", SqlDbType.NVarChar,0), new SqlParameter("@smallTagSql", SqlDbType.NVarChar,0), new SqlParameter("@eachPrintBigTagNum", SqlDbType.Float), new SqlParameter("@eachPrintSmallTagNum", SqlDbType.Float), new SqlParameter("@unit", SqlDbType.VarChar,50), new SqlParameter("@isDel", SqlDbType.Bit), new SqlParameter("@isrtEmpId", SqlDbType.Int), new SqlParameter("@isrtDt", SqlDbType.DateTime), new SqlParameter("@updtEmpId", SqlDbType.Int), new SqlParameter("@updtDt", SqlDbType.DateTime), new SqlParameter("@units", SqlDbType.VarChar,20), new SqlParameter("@bigTagId_304", SqlDbType.Int), new SqlParameter("@smallTagId_304", SqlDbType.Int), new SqlParameter("@bigTagId_316", SqlDbType.Int), new SqlParameter("@smallTagId_316", SqlDbType.Int) }; parameters[0].Value = model.id; parameters[1].Value = model.custNo; parameters[2].Value = model.materialNo; parameters[3].Value = model.bigTagFileId; parameters[4].Value = model.smallTagFileId; parameters[5].Value = model.bigTagSql; parameters[6].Value = model.smallTagSql; parameters[7].Value = model.eachPrintBigTagNum; parameters[8].Value = model.eachPrintSmallTagNum; parameters[9].Value = model.unit; parameters[10].Value = model.isDel; parameters[11].Value = model.isrtEmpId; parameters[12].Value = model.isrtDt == string.Empty ? null : model.isrtDt; parameters[13].Value = model.updtEmpId; parameters[14].Value = model.updtDt == string.Empty ? null : model.updtDt; parameters[15].Value = model.units; parameters[16].Value = model.bigTagId_304; parameters[17].Value = model.smallTagId_304; parameters[18].Value = model.bigTagId_316; parameters[19].Value = model.smallTagId_316; try { SqlHelper.ExecuteNonQuery(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); ret = true; } catch (Exception ex) { throw ex; } return ret; }
/// <summary> /// 增加一条数据 /// </summary> /// <param name="model">model</param> public int AddRecord(LCustTagData model) { StringBuilder strSql = new StringBuilder(); strSql.Append("set nocount on; "); strSql.Append("insert into LCustTag("); strSql.Append(@"custNo,materialNo,bigTagFileId,smallTagFileId,bigTagSql,smallTagSql,eachPrintBigTagNum,eachPrintSmallTagNum,unit,isDel, isrtEmpId,isrtDt,updtEmpId,updtDt,units,bigTagId_304,smallTagId_304,bigTagId_316,smallTagId_316)"); strSql.Append(" values ("); strSql.Append(@"@custNo,@materialNo,@bigTagFileId,@smallTagFileId,@bigTagSql,@smallTagSql,@eachPrintBigTagNum,@eachPrintSmallTagNum,@unit,@isDel, @isrtEmpId,@isrtDt,@updtEmpId,@updtDt,@units,@bigTagId_304,@smallTagId_304,@bigTagId_316,@smallTagId_316)"); strSql.Append("; select @@identity; set nocount off; "); SqlParameter[] parameters = { new SqlParameter("@custNo", SqlDbType.VarChar,20), new SqlParameter("@materialNo", SqlDbType.VarChar,20), new SqlParameter("@bigTagFileId", SqlDbType.Int), new SqlParameter("@smallTagFileId", SqlDbType.Int), new SqlParameter("@bigTagSql", SqlDbType.NVarChar,0), new SqlParameter("@smallTagSql", SqlDbType.NVarChar,0), new SqlParameter("@eachPrintBigTagNum", SqlDbType.Float), new SqlParameter("@eachPrintSmallTagNum", SqlDbType.Float), new SqlParameter("@unit", SqlDbType.VarChar,50), new SqlParameter("@isDel", SqlDbType.Bit), new SqlParameter("@isrtEmpId", SqlDbType.Int), new SqlParameter("@isrtDt", SqlDbType.DateTime), new SqlParameter("@updtEmpId", SqlDbType.Int), new SqlParameter("@updtDt", SqlDbType.DateTime), new SqlParameter("@units", SqlDbType.VarChar,20), new SqlParameter("@bigTagId_304", SqlDbType.Int), new SqlParameter("@smallTagId_304", SqlDbType.Int), new SqlParameter("@bigTagId_316", SqlDbType.Int), new SqlParameter("@smallTagId_316", SqlDbType.Int) }; parameters[0].Value = model.custNo; parameters[1].Value = model.materialNo; parameters[2].Value = model.bigTagFileId; parameters[3].Value = model.smallTagFileId; parameters[4].Value = model.bigTagSql; parameters[5].Value = model.smallTagSql; parameters[6].Value = model.eachPrintBigTagNum; parameters[7].Value = model.eachPrintSmallTagNum; parameters[8].Value = model.unit; parameters[9].Value = model.isDel; parameters[10].Value = model.isrtEmpId; parameters[11].Value = model.isrtDt == string.Empty ? null : model.isrtDt; parameters[12].Value = model.updtEmpId; parameters[13].Value = model.updtDt == string.Empty ? null : model.updtDt; parameters[14].Value = model.units; parameters[15].Value = model.bigTagId_304; parameters[16].Value = model.smallTagId_304; parameters[17].Value = model.bigTagId_316; parameters[18].Value = model.smallTagId_316; int id = 0; try { object ret = SqlHelper.ExecuteScalar(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); if (ret != null && ret != DBNull.Value) { id = Convert.ToInt32(ret); } } catch (Exception ex) { throw ex; } return id; }
/// <summary> /// 得到一个model /// </summary> /// <param name="id">主键值</param> /// <returns>model</returns> public LCustTagData GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append(@"select id,custNo,materialNo,bigTagFileId,smallTagFileId,bigTagSql,smallTagSql,eachPrintBigTagNum,eachPrintSmallTagNum,unit,isDel, isrtEmpId,isrtDt,updtEmpId,updtDt,units,bigTagId_304,smallTagId_304,bigTagId_316,smallTagId_316 from LCustTag"); strSql.Append(" where id = @id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int) }; parameters[0].Value = id; LCustTagData model = new LCustTagData(); DataSet ds = SqlHelper.ExecuteDataset(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { DataRow row = ds.Tables[0].Rows[0]; if (row["id"] != DBNull.Value) { model.id = Convert.ToInt32(row["id"]); } if (row["custNo"] != DBNull.Value) { model.custNo = Convert.ToString(row["custNo"]); } if (row["materialNo"] != DBNull.Value) { model.materialNo = Convert.ToString(row["materialNo"]); } if (row["bigTagFileId"] != DBNull.Value) { model.bigTagFileId = Convert.ToInt32(row["bigTagFileId"]); } if (row["smallTagFileId"] != DBNull.Value) { model.smallTagFileId = Convert.ToInt32(row["smallTagFileId"]); } if (row["bigTagSql"] != DBNull.Value) { model.bigTagSql = Convert.ToString(row["bigTagSql"]); } if (row["smallTagSql"] != DBNull.Value) { model.smallTagSql = Convert.ToString(row["smallTagSql"]); } if (row["eachPrintBigTagNum"] != DBNull.Value) { model.eachPrintBigTagNum = Convert.ToDouble(row["eachPrintBigTagNum"]); } if (row["eachPrintSmallTagNum"] != DBNull.Value) { model.eachPrintSmallTagNum = Convert.ToDouble(row["eachPrintSmallTagNum"]); } if (row["unit"] != DBNull.Value) { model.unit = Convert.ToString(row["unit"]); } if (row["isDel"] != DBNull.Value) { model.isDel = Convert.ToBoolean(row["isDel"]); } if (row["isrtEmpId"] != DBNull.Value) { model.isrtEmpId = Convert.ToInt32(row["isrtEmpId"]); } if (row["isrtDt"] != DBNull.Value) { model.isrtDt = Convert.ToString(row["isrtDt"]); } if (row["updtEmpId"] != DBNull.Value) { model.updtEmpId = Convert.ToInt32(row["updtEmpId"]); } if (row["updtDt"] != DBNull.Value) { model.updtDt = Convert.ToString(row["updtDt"]); } if (row["units"] != DBNull.Value) { model.units = Convert.ToString(row["units"]); } if (row["bigTagId_304"] != DBNull.Value) { model.bigTagId_304 = Convert.ToInt32(row["bigTagId_304"]); } if (row["smallTagId_304"] != DBNull.Value) { model.smallTagId_304 = Convert.ToInt32(row["smallTagId_304"]); } if (row["bigTagId_316"] != DBNull.Value) { model.bigTagId_316 = Convert.ToInt32(row["bigTagId_316"]); } if (row["smallTagId_316"] != DBNull.Value) { model.smallTagId_316 = Convert.ToInt32(row["smallTagId_316"]); } return model; } else { return null; } }
/// <summary> /// 数据保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { LCustTagData model = new LCustTagData(); LCustTagBB custTagBB = new LCustTagBB(); try { if (this.State == "1") { this.SetModel(ref model); model.isrtDt = DateTime.Now.ToString(); model.isrtEmpId = this.currentUser.empId; model.smallTagSql = this.smallSQL.Text.ToString(); model.bigTagSql = this.bigSQL.Text.ToString(); this.IdValue = custTagBB.AddRecord(model); this.State = "1"; } else if (this.State == "2") { model = custTagBB.GetModel(this.IdValue); this.SetModel(ref model); model.updtDt = DateTime.Now.ToString(); model.updtEmpId = this.currentUser.empId; model.smallTagSql = this.smallSQL.Text.ToString(); model.bigTagSql = this.bigSQL.Text.ToString(); custTagBB.ModifyRecord(model); } } catch (Exception ex) { this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true); return; } finally { custTagBB.Dispose(); } Response.Redirect("LCustTagList.aspx?&itemno=" + this.itemNo + "&pTypeNo=main", false); }
/// <summary> /// 实体类赋值 /// </summary> /// <param name="model">实体类实例</param> private void SetModel(ref LCustTagData model) { model.custNo = this.hidCustNo.Value; model.materialNo = this.hidMaterialNo.Value; if (this.bigTagFileId.Value != "") { model.bigTagFileId = Convert.ToInt32(this.bigTagFileId.Value); } else { model.bigTagFileId = 0; } if (this.smallTagFileId.Value != "") { model.smallTagFileId = Convert.ToInt32(this.smallTagFileId.Value); } else { model.smallTagFileId = 0; } model.eachPrintBigTagNum = Convert.ToInt32(this.tbEachPrintBigTagNum.Text.Trim());//一次打印大标签个数 model.eachPrintSmallTagNum = Convert.ToInt32(this.tbEachPrintSmallTagNum.Text.Trim());//一次打印小标签个数 model.unit = this.tbUnit.Text.Trim();//单体单位 model.units = this.tbUnits.Text.Trim();//单体复数单位 }
/// <summary> /// 更新一条数据 /// </summary> /// <param name="model">model</param> public bool ModifyRecord(LCustTagData model) { return this.custTagDB.ModifyRecord(model); }
/// <summary> /// 增加一条数据 /// </summary> /// <param name="model">model</param> public int AddRecord(LCustTagData model) { return this.custTagDB.AddRecord(model); }