using Restaurant.BLL;
using Restaurant.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Restaurant.WEB
{
public partial class AddorEdit : System.Web.UI.Page
{
BLL.FoodManage manage = new BLL.FoodManage();
FoodModel model = new FoodModel();
Result result = new Result();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DDLC.DataSource = manage.Search("Category");
DDLC.DataTextField = "CategoryName";
DDLC.DataValueField = "CategoryId";
DDLC.DataBind();
string type = Request.QueryString["type"];
int id = Convert.ToInt32(Request.QueryString["FoodID"]);
if (type == "1")
{
Til.Text = "添加菜品";
}
else if (type == "0")
{
Til.Text = "修改菜品";
DataTable dt = manage.GetFoodInfo(id);
Name.Value = dt.Rows[0][2].ToString().Trim();
Price.Value = dt.Rows[0][3].ToString().Trim();
Descn.Value = dt.Rows[0][4].ToString().Trim();
Image.Value = dt.Rows[0][5].ToString().Trim();
string C = dt.Rows[0][1].ToString().Trim();
foreach (ListItem x in DDLC.Items)
{
if (x.Value == C)
{
DDLC.Items[Convert.ToInt32(C) - 1].Selected = true;
}
}
}
}
}
public bool IsNum(string str)
{
try
{
float x = 0;
x = float.Parse(str);
if (x >= 0)
return true;
else
return false;
}
catch
{
return false;
}
}
protected void Btn_Click(object sender, EventArgs e)
{
Result res = new Result();
OperManage omanage = new OperManage();
string type = Request.QueryString["type"];
model.Id = Request.QueryString["FoodID"];
model.Name = Name.Value.Trim();
model.CategoryId = Convert.ToString(Convert.ToInt32(DDLC.SelectedIndex) + 1);
model.Price = Price.Value.Trim();
model.Des = Descn.Value.Trim();
model.Image = Image.Value.Trim();
string aid = Session["id"].ToString() ;
if (IsNum(model.Price))
{
if (type == "1")
{
result = manage.Insert(model);
res = omanage.Insert(aid, result.id);
}
else if (type == "0")
{
result = manage.Update(model);
res = omanage.Insert(aid, model.Id);
}
if (result.code)
Response.Write("");
else
Response.Write("");
Response.Redirect("FoodManage.aspx");
}
else
Response.Write("");
}
}
}