/// <summary> /// 增加一条数据 /// </summary> public int Add(FishEntity.ContractDetailEntity model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into t_contractdetail("); strSql.Append("contractid,no,productid,productno,productname,specification,weight,quantity, unitprice,money,getweight,getquantity,isfinished,nature,remark )"); strSql.Append(" values ("); strSql.Append("@contractid,@no,@productid,@productno,@productname,@specification,@weight,@quantity,@unitprice,@money,@getweight,@getquantity,@isfinished,@nature,@remark );"); strSql.Append("select LAST_INSERT_ID();"); MySqlParameter[] parameters = { new MySqlParameter("@contractid", MySqlDbType.Int32, 11), new MySqlParameter("@no", MySqlDbType.Int32, 11), new MySqlParameter("@productid", MySqlDbType.Int32, 11), new MySqlParameter("@productno", MySqlDbType.VarChar, 45), new MySqlParameter("@productname", MySqlDbType.VarChar, 255), new MySqlParameter("@specification", MySqlDbType.VarChar, 255), new MySqlParameter("@weight", MySqlDbType.Decimal, 8), new MySqlParameter("@quantity", MySqlDbType.Int32, 6), new MySqlParameter("@unitprice", MySqlDbType.Decimal, 10), new MySqlParameter("@money", MySqlDbType.Decimal, 10), new MySqlParameter("@nature", MySqlDbType.VarChar, 225), new MySqlParameter("@remark", MySqlDbType.VarChar, 200), new MySqlParameter("@getweight", MySqlDbType.Decimal, 8), new MySqlParameter("@getquantity", MySqlDbType.Int32, 6), new MySqlParameter("@isfinished", MySqlDbType.Int32, 2) }; parameters[0].Value = model.contractid; parameters[1].Value = model.no; parameters[2].Value = model.productid; parameters[3].Value = model.productno; parameters[4].Value = model.productname; parameters[5].Value = model.specification; parameters[6].Value = model.weight; parameters[7].Value = model.quantity; parameters[8].Value = model.unitprice; parameters[9].Value = model.money; parameters[10].Value = model.nature; parameters[11].Value = model.remark; int id = MySqlHelper.ExecuteSqlReturnId(strSql.ToString(), parameters); return(id); }
/// <summary> /// 得到一个对象实体 /// </summary> public FishEntity.ContractDetailEntity GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select id,contractid,no,productid,productno,productname,specification,weight,quantity,unitprice,money,getweight,getquantity,isfinished from t_contractdetail "); strSql.Append(" where id=@id"); MySqlParameter[] parameters = { new MySqlParameter("@id", MySqlDbType.Int32) }; parameters[0].Value = id; FishEntity.ContractDetailEntity model = new FishEntity.ContractDetailEntity(); DataSet ds = MySqlHelper.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
protected void AddDetail(int contractid, bool isAdd) { dataGridView1.EndEdit(); List <FishEntity.ContractDetailEntity> listNews = new List <FishEntity.ContractDetailEntity>(); foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.IsNewRow) { continue; } FishEntity.ContractDetailEntity item = new FishEntity.ContractDetailEntity(); int id = 0; int.TryParse(row.Cells["id"].Value == null ? "0" : row.Cells["id"].Value.ToString(), out id); item.id = id; int no = 0; int.TryParse(row.Cells["no"].Value == null ? "0" : row.Cells["no"].Value.ToString(), out no); item.no = no; int productid = 0; int.TryParse(row.Cells["productid"].Value == null ? "0" : row.Cells["productid"].Value.ToString(), out productid); item.productid = productid; item.productno = row.Cells["productno"].Value == null ? string.Empty : row.Cells["productno"].Value.ToString(); item.productname = row.Cells["productname"].Value == null ? string.Empty : row.Cells["productname"].Value.ToString(); item.specification = row.Cells["specification"].Value == null ? string.Empty : row.Cells["specification"].Value.ToString(); item.remark = row.Cells["ctlremark"].Value == null ? string.Empty : row.Cells["ctlremark"].Value.ToString(); item.nature = row.Cells["nature"].Value == null ? string.Empty : row.Cells["nature"].Value.ToString(); decimal weight = 0; if (row.Cells["weight"].Value == null) { weight = 0; } else { decimal.TryParse(row.Cells["weight"].Value.ToString(), out weight); } item.weight = weight; int quantity = 0; if (row.Cells["quantity"].Value == null) { quantity = 0; } else { int.TryParse(row.Cells["quantity"].Value.ToString(), out quantity); } item.quantity = quantity; decimal unitprice = 0; decimal.TryParse(row.Cells["unitprice"].Value == null ? "0.00" : row.Cells["unitprice"].Value.ToString(), out unitprice); item.unitprice = unitprice; decimal money = 0; decimal.TryParse(row.Cells["money"].Value == null ? "0.00" : row.Cells["money"].Value.ToString(), out money); item.money = money; item.contractid = contractid; listNews.Add(item); } if (isAdd == false) { List <FishEntity.ContractDetailEntity> listsource = _detailbll.GetModelList(" contractid=" + contractid); if (listsource != null) { foreach (FishEntity.ContractDetailEntity item in listsource) { bool isExist = listNews.Exists((i) => { return(i.id == item.id); }); if (isExist == false) { bool isDelete = _detailbll.Delete(item.id); } } } } foreach (FishEntity.ContractDetailEntity item in listNews) { if (item.id == 0) { int id = _detailbll.Add(item); if (id > 0) { item.id = id; } } else { _detailbll.Update(item); } } _details = listNews; SetDetail(); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(FishEntity.ContractDetailEntity model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(FishEntity.ContractDetailEntity model) { return(dal.Add(model)); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(FishEntity.ContractDetailEntity model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update t_contractdetail set "); strSql.Append("contractid=@contractid,"); strSql.Append("no=@no,"); strSql.Append("productid=@productid,"); strSql.Append("productno=@productno,"); strSql.Append("productname=@productname,"); strSql.Append("specification=@specification,"); strSql.Append("weight=@weight,"); strSql.Append("quantity=@quantity,"); strSql.Append("unitprice=@unitprice,"); strSql.Append("money=@money,"); strSql.Append("getweight=@getweight,"); strSql.Append("getquantity=@getquantity,"); strSql.Append("isfinished=@isfinished, "); strSql.Append("nature=@nature, "); strSql.Append("remark=@remark "); strSql.Append(" where id=@id "); MySqlParameter[] parameters = { new MySqlParameter("@contractid", MySqlDbType.Int32, 11), new MySqlParameter("@no", MySqlDbType.Int32, 11), new MySqlParameter("@productid", MySqlDbType.Int32, 11), new MySqlParameter("@productno", MySqlDbType.VarChar, 45), new MySqlParameter("@productname", MySqlDbType.VarChar, 255), new MySqlParameter("@specification", MySqlDbType.VarChar, 255), new MySqlParameter("@weight", MySqlDbType.Decimal, 8), new MySqlParameter("@quantity", MySqlDbType.Int32, 6), new MySqlParameter("@unitprice", MySqlDbType.Decimal, 10), new MySqlParameter("@money", MySqlDbType.Decimal, 10), new MySqlParameter("@getweight", MySqlDbType.Decimal, 8), new MySqlParameter("@getquantity", MySqlDbType.Int32, 6), new MySqlParameter("@isfinished", MySqlDbType.Int16, 2), new MySqlParameter("@nature", MySqlDbType.VarChar, 225), new MySqlParameter("@remark", MySqlDbType.VarChar, 200), new MySqlParameter("@id", MySqlDbType.Int32, 11) }; parameters[0].Value = model.contractid; parameters[1].Value = model.no; parameters[2].Value = model.productid; parameters[3].Value = model.productno; parameters[4].Value = model.productname; parameters[5].Value = model.specification; parameters[6].Value = model.weight; parameters[7].Value = model.quantity; parameters[8].Value = model.unitprice; parameters[9].Value = model.money; parameters[10].Value = model.getweight; parameters[11].Value = model.getquantity; parameters[12].Value = model.isfinished; parameters[13].Value = model.nature; parameters[14].Value = model.remark; parameters[15].Value = model.id; int rows = MySqlHelper.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public FishEntity.ContractDetailEntity DataRowToModel(DataRow row) { FishEntity.ContractDetailEntity model = new FishEntity.ContractDetailEntity(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["contractid"] != null && row["contractid"].ToString() != "") { model.contractid = int.Parse(row["contractid"].ToString()); } if (row["no"] != null && row["no"].ToString() != "") { model.no = int.Parse(row["no"].ToString()); } if (row["productid"] != null && row["productid"].ToString() != "") { model.productid = int.Parse(row["productid"].ToString()); } if (row["productno"] != null) { model.productno = row["productno"].ToString(); } if (row["productname"] != null) { model.productname = row["productname"].ToString(); } if (row["specification"] != null) { model.specification = row["specification"].ToString(); } if (row["weight"] != null && row["weight"].ToString() != "") { model.weight = decimal.Parse(row["weight"].ToString()); } if (row["quantity"] != null && row["quantity"].ToString() != "") { model.quantity = int.Parse(row["quantity"].ToString()); } if (row["unitprice"] != null && row["unitprice"].ToString() != "") { model.unitprice = decimal.Parse(row["unitprice"].ToString()); } if (row["money"] != null && row["money"].ToString() != "") { model.money = decimal.Parse(row["money"].ToString()); } if (row["getweight"] != null && row["getweight"].ToString() != "") { model.getweight = decimal.Parse(row["getweight"].ToString()); } if (row["getquantity"] != null && row["getquantity"].ToString() != "") { model.getquantity = int.Parse(row["getquantity"].ToString()); } if (row["isfinished"] != null && row["isfinished"].ToString() != "") { model.isfinished = int.Parse(row["isfinished"].ToString()); } if (row["nature"] != null) { model.nature = row["nature"].ToString(); } if (row["remark"] != null) { model.remark = row["remark"].ToString(); } } return(model); }