protected void rpItems_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) { Repeater rpDisplayL = e.Item.FindControl("rpDisplayL") as Repeater; Repeater rpDisplayW = e.Item.FindControl("rpDisplayW") as Repeater; Repeater rpDisplayD = e.Item.FindControl("rpDisplayD") as Repeater; MachItem machItem = e.Item.DataItem as MachItem; string longMachList = machItem.LongMachList; string widthMachList = machItem.WidthMachList; string deepthMachList = machItem.DeepthMachList; var machLookupList = Utility.GetMachLookupList(); if (!string.IsNullOrEmpty(longMachList)) { var longResult = longMachList.Split('|').Where(r => !string.IsNullOrEmpty(r)); var result = from c in machLookupList join r in longResult on c.Mach_Id equals int.Parse(r) select c; Utility.BindDataToRepeater(rpDisplayL, result); } if (!string.IsNullOrEmpty(widthMachList)) { var widthResult = widthMachList.Split('|').Where(r => !string.IsNullOrEmpty(r)); var result = from c in machLookupList join r in widthResult on c.Mach_Id equals int.Parse(r) select c; Utility.BindDataToRepeater(rpDisplayW, result); } if (!string.IsNullOrEmpty(deepthMachList)) { var deepResult = deepthMachList.Split('|').Where(r => !string.IsNullOrEmpty(r)); var result = from c in machLookupList join r in deepResult on c.Mach_Id equals int.Parse(r) select c; Utility.BindDataToRepeater(rpDisplayD, result); } } }
protected void rpItems_ItemCommand(object source, RepeaterCommandEventArgs e) { MachItemDAL dal = new MachItemDAL(); if (e.CommandName == "Add") { MachItem item = new MachItem(); TextBox txtIntroAdd = e.Item.FindControl("txtIntroAdd") as TextBox; TextBox txtProductAdd = e.Item.FindControl("txtProductAdd") as TextBox; TextBox txtCodeAdd = e.Item.FindControl("txtCodeAdd") as TextBox; TextBox txtLongAdd = e.Item.FindControl("txtLongAdd") as TextBox; TextBox txtWidthAdd = e.Item.FindControl("txtWidthAdd") as TextBox; TextBox txtDeepAdd = e.Item.FindControl("txtDeepAdd") as TextBox; TextBox txtQtyAdd = e.Item.FindControl("txtQtyAdd") as TextBox; TextBox txtRemarkAdd = e.Item.FindControl("txtRemarkAdd") as TextBox; int longValue = !string.IsNullOrEmpty(txtLongAdd.Text) ? int.Parse(txtLongAdd.Text) : 0; int width = !string.IsNullOrEmpty(txtWidthAdd.Text) ? int.Parse(txtWidthAdd.Text) : 0; int deepth = !string.IsNullOrEmpty(txtDeepAdd.Text) ? int.Parse(txtDeepAdd.Text) : 0; int qty = !string.IsNullOrEmpty(txtQtyAdd.Text) ? int.Parse(txtQtyAdd.Text) : 0; item.Mach_Id = MachId; item.Intro = txtIntroAdd.Text; item.Product_Code = txtProductAdd.Text; item.Code = txtCodeAdd.Text; item.Long = longValue; item.Width = width; item.Deepth = deepth; item.Quantity = qty; item.Square = ((double)(longValue * width * qty)) / (1000 * 1000); item.MachIntro = txtRemarkAdd.Text; dal.AddMachItem(item); dal.Save(); } if (e.CommandName == "Save") { HiddenField hdId = e.Item.FindControl("hdId") as HiddenField; var item = dal.GetMachItemById(int.Parse(hdId.Value)); TextBox txtIntro = e.Item.FindControl("txtIntro") as TextBox; TextBox txtProduct = e.Item.FindControl("txtProduct") as TextBox; TextBox txtCode = e.Item.FindControl("txtCode") as TextBox; TextBox txtLong = e.Item.FindControl("txtLong") as TextBox; TextBox txtWidth = e.Item.FindControl("txtWidth") as TextBox; TextBox txtDeep = e.Item.FindControl("txtDeep") as TextBox; TextBox txtQty = e.Item.FindControl("txtQty") as TextBox; TextBox txtRemark = e.Item.FindControl("txtRemark") as TextBox; int longValue = !string.IsNullOrEmpty(txtLong.Text) ? int.Parse(txtLong.Text) : 0; int width = !string.IsNullOrEmpty(txtWidth.Text) ? int.Parse(txtWidth.Text) : 0; int deepth = !string.IsNullOrEmpty(txtDeep.Text) ? int.Parse(txtDeep.Text) : 0; int qty = !string.IsNullOrEmpty(txtQty.Text) ? int.Parse(txtQty.Text) : 0; item.Mach_Id = MachId; item.Intro = txtIntro.Text; item.Product_Code = txtProduct.Text; item.Code = txtCode.Text; item.Long = longValue; item.Width = width; item.Deepth = deepth; item.Quantity = qty; item.Square = ((double)(longValue * width * qty)) / (1000 * 1000); item.MachIntro = txtRemark.Text; dal.Save(); } if (e.CommandName == "Delete") { HiddenField hdId = e.Item.FindControl("hdId") as HiddenField; dal.DeleteMachItem(int.Parse(hdId.Value)); } BindControl(); SetFocus(btnExport); }
public void AddMachItem(MachItem item) { Db.MachItem.AddObject(item); }