private void UpdatePriceType() { try { if (!this.ValidateUpdatePriceType()) { base.RegisterScript("top.ui.alert('此价格类型已经存在!');"); } else { using (pm2Entities pm2Entities = new pm2Entities()) { Res_PriceType res_PriceType = ( from pt in pm2Entities.Res_PriceType where pt.PriceTypeId == this.priceTypeId select pt).FirstOrDefault <Res_PriceType>(); if (res_PriceType != null) { res_PriceType.PriceTypeName = this.txtPriceTypeName.Text.Trim(); res_PriceType.Note = this.txtNote.Text.Trim(); pm2Entities.SaveChanges(); } } System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); stringBuilder.Append("top.ui.show( '修改成功'); \n"); stringBuilder.Append("top.ui.closeWin(); \n"); stringBuilder.Append("top.ui.reloadTab(); \n"); base.RegisterScript(stringBuilder.ToString()); } } catch { base.RegisterScript("top.ui.alert('修改失败')"); } }
public void AddPrice() { string id = this.hdGuid.Value; if (!string.IsNullOrEmpty(this.resourceId)) { id = this.resourceId; } using (pm2Entities pm2Entities = new pm2Entities()) { IQueryable <Res_Price> queryable = from m in pm2Entities.Res_Price where m.ResourceId == id select m; foreach (Res_Price current in queryable) { pm2Entities.DeleteObject(current); } pm2Entities.SaveChanges(); } System.Collections.IEnumerator enumerator2 = this.gvwPriceType.Rows.GetEnumerator(); try { while (enumerator2.MoveNext()) { GridViewRow gridViewRow = (GridViewRow)enumerator2.Current; TextBox tb = gridViewRow.FindControl("txtPrice") as TextBox; using (pm2Entities pm2Entities2 = new pm2Entities()) { Res_Price res_Price = new Res_Price(); if (!string.IsNullOrEmpty(tb.Text)) { res_Price.PriceValue = System.Convert.ToDecimal(tb.Text); } Res_PriceType res_PriceType = ( from m in pm2Entities2.Res_PriceType where m.PriceTypeId == tb.ToolTip select m).First <Res_PriceType>(); res_PriceType.Res_Price.Add(res_Price); Res_Resource res_Resource = ( from m in pm2Entities2.Res_Resource where m.ResourceId == id select m).First <Res_Resource>(); res_Resource.Res_Price.Add(res_Price); pm2Entities2.AddToRes_Price(res_Price); pm2Entities2.SaveChanges(); } } } finally { System.IDisposable disposable = enumerator2 as System.IDisposable; if (disposable != null) { disposable.Dispose(); } } }
public static void Add(ResPriceType respricetype) { using (pm2Entities entities = new pm2Entities()) { Res_PriceType type = bindEntity(respricetype, true); entities.AddToRes_PriceType(type); entities.SaveChanges(); } }
private bool IsUsedPriceType(Res_PriceType priceType) { bool result; using (pm2Entities pm2Entities = new pm2Entities()) { result = (( from p in pm2Entities.Res_Price where p.PriceTypeId == priceType.PriceTypeId select p).Count <Res_Price>() > 0); } return(result); }
public static void Upadate(ResPriceType respricetype) { using (pm2Entities entities = new pm2Entities()) { if ((from m in entities.Res_PriceType where m.PriceTypeId == respricetype.Id select m).FirstOrDefault <Res_PriceType>() == null) { throw new Exception("找不到需要更新的价格类型"); } Res_PriceType type = bindEntity(respricetype, false); entities.SaveChanges(); } }
private void InitUpdate() { using (pm2Entities pm2Entities = new pm2Entities()) { Res_PriceType res_PriceType = ( from pt in pm2Entities.Res_PriceType where pt.PriceTypeId == this.priceTypeId select pt).FirstOrDefault <Res_PriceType>(); if (res_PriceType != null) { this.txtPriceTypeName.Text = res_PriceType.PriceTypeName; this.txtNote.Text = res_PriceType.Note; } } }
public static void Delete(string id) { using (pm2Entities entities = new pm2Entities()) { Res_PriceType entity = (from m in entities.Res_PriceType where m.PriceTypeId == id select m).FirstOrDefault <Res_PriceType>(); if (entity == null) { throw new Exception("找不到需要删除的价格类型"); } entities.DeleteObject(entity); entities.SaveChanges(); } }
private static Res_PriceType bindEntity(ResPriceType respricetype, bool isAdd) { Res_PriceType type = new Res_PriceType { PriceTypeName = respricetype.Name, Note = respricetype.Note }; if (isAdd) { type.PriceTypeId = respricetype.Id; type.PriceTypeCode = respricetype.Code; type.InputUser = respricetype.InputUser; type.InputDate = respricetype.InputDate; type.UserCodes = JsonHelper.Serialize(respricetype.UserCodes.ToArray <string>()); } return(type); }
private void AddPriceType() { try { if (!this.ValidateInsertPriceType()) { base.RegisterScript("top.ui.alert('此价格类型已经存在!');"); } else { using (pm2Entities pm2Entities = new pm2Entities()) { Res_PriceType res_PriceType = new Res_PriceType(); res_PriceType.PriceTypeId = System.Guid.NewGuid().ToString(); res_PriceType.PriceTypeCode = System.DateTime.Now.ToString("yyyyMMddHHmmss"); res_PriceType.PriceTypeName = this.txtPriceTypeName.Text.Trim(); res_PriceType.Note = this.txtNote.Text.Trim(); System.Collections.Generic.List <string> list = new System.Collections.Generic.List <string>(); list.Add(base.UserCode); if (base.UserCode != "00000000") { list.Add("00000000"); } res_PriceType.UserCodes = JsonHelper.Serialize(list.ToArray()); pm2Entities.AddToRes_PriceType(res_PriceType); pm2Entities.SaveChanges(); } System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); stringBuilder.Append("top.ui.show( '添加成功'); \n"); stringBuilder.Append("top.ui.closeWin(); \n"); stringBuilder.Append("top.ui.reloadTab(); \n"); base.RegisterScript(stringBuilder.ToString()); } } catch { base.RegisterScript("top.ui.alert('添加失败')"); } }
private void DeletePriceType(System.Collections.Generic.List <string> priceTypeIds) { using (pm2Entities pm2Entities = new pm2Entities()) { foreach (string id in priceTypeIds) { Res_PriceType res_PriceType = ( from pt in pm2Entities.Res_PriceType where pt.PriceTypeId == id select pt).FirstOrDefault <Res_PriceType>(); if (res_PriceType != null) { if (this.IsUsedPriceType(res_PriceType)) { base.RegisterScript("alert('系统提示:\\n\\n此价格类型已经使用,不能删除')"); return; } pm2Entities.DeleteObject(res_PriceType); } } pm2Entities.SaveChanges(); } this.DataBindPriceType(); }
public static ResPriceType GetById(string id) { ResPriceType type = null; using (pm2Entities entities = new pm2Entities()) { Res_PriceType type2 = (from m in entities.Res_PriceType where m.PriceTypeId == id select m).FirstOrDefault <Res_PriceType>(); if (type2 != null) { type = new ResPriceType { Id = type2.PriceTypeId, Code = type2.PriceTypeCode, Name = type2.PriceTypeName, Note = type2.Note, InputUser = type2.InputUser, InputDate = type2.InputDate, UserCodes = JsonHelper.GetListFromJson(type2.UserCodes) }; } } return(type); }