/// <summary> /// DataTable 转对象 /// </summary> /// <param name="sql"></param> /// <returns></returns> public static MarerialKind ConvertDataTableToModel(string sql) { error = string.Empty; DataTable dt = SqlHelper.GetTable(sql, ref error); DataRow dr = dt.Rows[0]; MarerialKind mareriakind = new MarerialKind(); mareriakind.Kind = dr["Kind"] == null ? "" : dr["Kind"].ToString(); return(mareriakind); }
protected void btnSubmit_Click(object sender, EventArgs e) { string error = string.Empty; Model.MarerialKind marerialkind = new MarerialKind(); marerialkind.Kind = this.txtKind.Text.Trim(); if (string.IsNullOrEmpty(marerialkind.Kind)) { lbSubmit.Text = "请将带*号的内容填写完整!"; return; } else { if (btnSubmit.Text.Equals("添加")) { if (MarerialKindManager.IsExit(marerialkind.Kind)) { lbSubmit.Text = "已存在该原材料种类!请重新填写!!!"; } if (MarerialKindManager.AddMarerialKind(marerialkind, ref error)) { lbSubmit.Text = "添加成功!"; return; } else { lbSubmit.Text = "添加失败,原因:" + error; return; } } else { string kind = Server.UrlDecode(ToolManager.GetQueryString("Kind")); if (MarerialKindManager.EditMarerialKind(marerialkind, kind, ref error)) { lbSubmit.Text = "修改成功!"; return; } else { lbSubmit.Text = "修改失败:原因:" + error; return; } } } }
private void LoadPage() { //this.trId.Visible = false; string sql = string.Empty; string error = string.Empty; if (ToolManager.CheckQueryString("Kind")) { sql = string.Format(@" select * from MarerialKind where kind='{0}' ", Server.UrlDecode(ToolManager.GetQueryString("Kind"))); MarerialKind marerialkind = MarerialKindManager.ConvertDataTableToModel(sql); this.txtKind.Text = marerialkind.Kind; btnSubmit.Text = "修改"; } }
/// <summary> /// 编辑原材料种类 /// </summary> /// <param name="user"></param> /// <param name="error"></param> /// <returns></returns> public static bool EditMarerialKind(MarerialKind mareialkind, string kind, ref string error) { sql = string.Format(@" update MarerialKind set Kind='{0}' where Kind='{1}' ", mareialkind.Kind, kind); return(SqlHelper.ExecuteSql(sql, ref error)); }