コード例 #1
0
 public ActionResult btnCreate_Click(BasicType model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             if (!string.IsNullOrEmpty(model.Name))
             {
                 if (!CheckRepeat(model))
                 {
                     Alert.Show("已有相同记录存在!", MessageBoxIcon.Warning);
                 }
                 else
                 {
                     var max = (int)(Rep.Max(t => t.Rid) ?? 0);
                     model.Rid = max + 1;
                     Rep.Add(model);
                     // 关闭本窗体(触发窗体的关闭事件)
                     PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
                 }
             }
             else
             {
                 Alert.Show("名称不能为空!", MessageBoxIcon.Warning);
             }
         }
         catch (Exception ex)
         {
             Alert.Show(ex.Message, MessageBoxIcon.Warning);
         }
     }
     return(UIHelper.Result());
 }
コード例 #2
0
 public ActionResult AddOrEdit(ServiceList model)
 {
     if (!ModelState.IsValid)
     {
         return(UIHelper.Result());
     }
     try
     {
         if (model._id == 0)
         {
             if (!CheckRepeat(model))
             {
                 Alert.Show("已有相同记录存在!", MessageBoxIcon.Warning);
             }
             else
             {
                 model._id         = (int)(Rep.Max(t => t._id) ?? 0) + 1;
                 model.PrimaryId   = (int)(Rep.Max(t => t.PrimaryId) ?? 0) + 1;
                 model.SecondaryId = (int)(Rep.Max(t => t.SecondaryId) ?? 0) + 1;
                 SetRegContent(model);
                 Rep.Add(model);
                 // 关闭本窗体(触发窗体的关闭事件)
                 PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
             }
         }
         else
         {
             SetRegContent(model);
             Rep.Update(t => t._id == Convert.ToInt32(model._id), Builders <ServiceList> .Update.Set(t => t.ServiceName, model.ServiceName)
                        .Set(t => t.SecondaryName, model.SecondaryName)
                        .Set(t => t.Host, model.Host)
                        .Set(t => t.Version, model.Version)
                        .Set(t => t.Remark, model.Remark));
             // 关闭本窗体(触发窗体的关闭事件)
             PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
         }
     }
     catch (Exception ex)
     {
         Alert.Show(ex.Message, MessageBoxIcon.Warning);
     }
     return(UIHelper.Result());
 }