void edit_body(FishEntity.productsituationEntity list, Hashtable SQLString, StringBuilder strSql) { strSql = new StringBuilder(); strSql.Append("UPDATE t_productsituation SET "); strSql.Append("code=@code,"); strSql.Append("product_id=@product_id,"); strSql.Append("productname=@productname,"); strSql.Append("Funit=@Funit,"); strSql.Append("Variety=@Variety,"); strSql.Append("Quantity=@Quantity,"); strSql.Append("unitprice=@unitprice,"); strSql.Append("amonut=@amonut "); strSql.Append("WHERE Numbering=@Numbering "); MySqlParameter[] parameter = { new MySqlParameter("@code", list.Code), new MySqlParameter("@product_id", list.Product_id), new MySqlParameter("@productname", list.Productname), new MySqlParameter("@Funit", list.Funit), new MySqlParameter("@Variety", list.Variety), new MySqlParameter("@Quantity", list.Quantity), new MySqlParameter("@unitprice", list.Unitprice), new MySqlParameter("@amonut", list.Amonut), new MySqlParameter("@Numbering", list.Numbering), }; SQLString.Add(strSql, parameter); }
void add_body(FishEntity.productsituationEntity list, Hashtable SQLString, StringBuilder strSql) { strSql = new StringBuilder(); strSql.Append("INSERT INTO t_productsituation ("); strSql.Append("Numbering,code,product_id,productname,Funit,Variety,Quantity,Amonut,unitprice) "); strSql.Append("VALUES ("); strSql.Append("@Numbering,@code,@product_id,@productname,@Funit,@Variety,@Quantity,@Amonut,@unitprice)"); MySqlParameter[] parameter = { new MySqlParameter("@product_id", MySqlDbType.VarChar, 45), new MySqlParameter("@productname", MySqlDbType.VarChar, 45), new MySqlParameter("@Funit", MySqlDbType.VarChar, 45), new MySqlParameter("@Variety", MySqlDbType.VarChar, 45), new MySqlParameter("@Quantity", MySqlDbType.Decimal, 45), new MySqlParameter("@unitprice", MySqlDbType.Decimal, 45), new MySqlParameter("@Amonut", MySqlDbType.Decimal, 45), new MySqlParameter("@Numbering", MySqlDbType.VarChar, 45), new MySqlParameter("@code", MySqlDbType.VarChar, 45), }; parameter[0].Value = list.Product_id; parameter[1].Value = list.Productname; parameter[2].Value = list.Funit; parameter[3].Value = list.Variety; parameter[4].Value = list.Quantity; parameter[5].Value = list.Unitprice; parameter[6].Value = list.Amonut; parameter[7].Value = list.Numbering; parameter[8].Value = list.Code; SQLString.Add(strSql, parameter); }
public FishEntity.productsituationEntity getModel(DataRow row) { FishEntity.productsituationEntity _model = new FishEntity.productsituationEntity(); if (row != null) { if (row["id"] != null & row["id"].ToString() != "") { _model.Id = row["id"].ToString(); } if (row["Numbering"] != null) { _model.Numbering = row["Numbering"].ToString(); } if (row["code"] != null & row["code"].ToString() != "") { _model.Code = row["code"].ToString(); } if (row["product_id"] != null & row["product_id"].ToString() != "") { _model.Product_id = row["product_id"].ToString(); } if (row["productname"] != null & row["productname"].ToString() != "") { _model.Productname = row["productname"].ToString(); } if (row["Funit"] != null & row["Funit"].ToString() != "") { _model.Funit = row["Funit"].ToString(); } if (row["Variety"] != null & row["Variety"].ToString() != "") { _model.Variety = row["Variety"].ToString(); } if (row["Quantity"] != null && row["Quantity"].ToString() != "") { _model.Quantity = decimal.Parse(row["Quantity"].ToString()); } if (row["unitprice"] != null && row["unitprice"].ToString() != "") { _model.Unitprice = decimal.Parse(row["unitprice"].ToString()); } if (row["Amonut"] != null && row["Amonut"].ToString() != "") { _model.Amonut = decimal.Parse(row["Amonut"].ToString()); } } return(_model); }
public void DataView(List <FishEntity.productsituationEntity> modelList) { dataGridView1.EndEdit(); foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.IsNewRow) { continue; } _body = new FishEntity.productsituationEntity(); _body.Code = _model.ContractCode; _body.Numbering = _model.Numbering; _body.Product_id = row.Cells["product_id"].Value == null ? string.Empty : row.Cells["product_id"].Value.ToString(); _body.Productname = row.Cells["productname"].Value == null ? string.Empty : row.Cells["productname"].Value.ToString(); _body.Funit = row.Cells["Funit"].Value == null ? string.Empty : row.Cells["Funit"].Value.ToString(); _body.Variety = row.Cells["Variety"].Value == null ? string.Empty : row.Cells["Variety"].Value.ToString(); _body.Quantity = row.Cells["Quantity"].Value == null ? 0 : Math.Round(decimal.Parse(row.Cells["Quantity"].Value.ToString()), 2); _body.Unitprice = row.Cells["unitprice"].Value == null ? 0 : Math.Round(decimal.Parse(row.Cells["unitprice"].Value.ToString()), 2); _body.Amonut = row.Cells["Amonut"].Value == null ? 0 : Math.Round(decimal.Parse(row.Cells["Amonut"].Value.ToString()), 2); modelList.Add(_body); } }
/// <summary> /// 编辑一单记录 /// </summary> /// <param name="model"></param> /// <param name="modeList"></param> /// <returns></returns> public bool Update(FishEntity.SalesRContractEntity model, List <FishEntity.productsituationEntity> modeList) { Hashtable SQLString = new Hashtable(); StringBuilder strSql = new StringBuilder(); strSql.Append("update t_salesrcontract set "); strSql.Append("ContractCode=@ContractCode,"); strSql.Append("Signdate=@Signdate,"); strSql.Append("Signplace=@Signplace,"); strSql.Append("supplier=@supplier,"); strSql.Append("demand=@demand,"); strSql.Append("modifyman=@modifyman,"); strSql.Append("modifytime=@modifytime "); strSql.Append(" where id = @id"); MySqlParameter[] parameters = { new MySqlParameter("@ContractCode", model.ContractCode), new MySqlParameter("@Signdate", model.Signdate), new MySqlParameter("@Signplace", model.Signplace), new MySqlParameter("@supplier", model.Supplier), new MySqlParameter("@demand", model.Demand), new MySqlParameter("@modifyman", model.Modifyman), new MySqlParameter("@modifytime", model.Modifytime), new MySqlParameter("@id", model.Id), }; SQLString.Add(strSql.ToString(), parameters); foreach (FishEntity.productsituationEntity list in modeList) { if (Exists(list.Numbering, list.Product_id) == false) { add_body(list, SQLString, strSql); } else { edit_body(list, SQLString, strSql); } } DataSet ds = MySqlHelper.Query("SELECT product_id FROM t_productsituation WHERE code='" + model.ContractCode + "'" + " and Numbering='" + model.Numbering + "'"); DataTable dt = ds.Tables[0]; if (dt != null && dt.Rows.Count > 0) { FishEntity.productsituationEntity list = new FishEntity.productsituationEntity(); for (int i = 0; i < dt.Rows.Count; i++) { model.Product_id = list.Product_id = dt.Rows[i]["product_id"].ToString(); list = modeList.Find((k) => { return(k.Product_id.Equals(model.Product_id)); }); if (list == null) { delete_body(model.Numbering, model.Product_id, SQLString, strSql); } } } return(MySqlHelper.ExecuteSqlTran(SQLString)); }