Exemplo n.º 1
0
 protected void btnDel_Click(object sender, System.EventArgs e)
 {
     System.Collections.IEnumerator enumerator = this.gvResource.Rows.GetEnumerator();
     try
     {
         while (enumerator.MoveNext())
         {
             GridViewRow gridViewRow = (GridViewRow)enumerator.Current;
             CheckBox    cb          = gridViewRow.FindControl("cbBox") as CheckBox;
             if (cb != null && cb.Checked)
             {
                 using (pm2Entities pm2Entities = new pm2Entities())
                 {
                     if (base.Request["num"] == "1")
                     {
                         Res_Template res_Template = (
                             from m in pm2Entities.Res_Template
                             where m.TemplateId == cb.ToolTip
                             select m).FirstOrDefault <Res_Template>();
                         if (res_Template != null)
                         {
                             res_Template.IsValid = new bool?(false);
                             pm2Entities.SaveChanges();
                         }
                     }
                     else
                     {
                         IQueryable <Res_TemplateItem> queryable =
                             from m in pm2Entities.Res_TemplateItem
                             where m.Res_Template.TemplateId == cb.ToolTip
                             select m;
                         foreach (Res_TemplateItem current in queryable)
                         {
                             pm2Entities.DeleteObject(current);
                         }
                         Res_Template res_Template2 = (
                             from m in pm2Entities.Res_Template
                             where m.TemplateId == cb.ToolTip
                             select m).FirstOrDefault <Res_Template>();
                         if (res_Template2 != null)
                         {
                             pm2Entities.DeleteObject(res_Template2);
                             pm2Entities.SaveChanges();
                         }
                     }
                 }
             }
         }
     }
     finally
     {
         System.IDisposable disposable = enumerator as System.IDisposable;
         if (disposable != null)
         {
             disposable.Dispose();
         }
     }
     base.RegisterScript("location.href=location.href;");
 }
Exemplo n.º 2
0
 public static void Add(ResTemplate restemplate)
 {
     using (pm2Entities entities = new pm2Entities())
     {
         Res_Template template = bindEntity(restemplate, true);
         entities.AddToRes_Template(template);
         entities.SaveChanges();
     }
 }
Exemplo n.º 3
0
 public static void Add(ResTemplateItem restemplateitem)
 {
     using (pm2Entities entities = new pm2Entities())
     {
         Res_TemplateItem entity   = bindEntity(restemplateitem);
         Res_Template     template = (from m in entities.Res_Template
                                      where m.TemplateId == restemplateitem.Template.Id
                                      select m).FirstOrDefault <Res_Template>();
         entity.Res_Template = template;
         template.Res_TemplateItem.Add(entity);
         entities.SaveChanges();
     }
 }
Exemplo n.º 4
0
 public static void Update(ResTemplate restemplate)
 {
     using (pm2Entities entities = new pm2Entities())
     {
         if ((from m in entities.Res_Template
              where m.TemplateId == restemplate.Id
              select m).FirstOrDefault <Res_Template>() == null)
         {
             throw new Exception("找不到需要修改的模板");
         }
         Res_Template template = bindEntity(restemplate, false);
         entities.SaveChanges();
     }
 }
Exemplo n.º 5
0
 public static void Delete(string id)
 {
     using (pm2Entities entities = new pm2Entities())
     {
         Res_Template entity = (from m in entities.Res_Template
                                where m.TemplateId == id
                                select m).FirstOrDefault <Res_Template>();
         if (entity == null)
         {
             throw new Exception("找不到需要删除的模板");
         }
         entities.DeleteObject(entity);
         entities.SaveChanges();
     }
 }
Exemplo n.º 6
0
        private static Res_Template bindEntity(ResTemplate restemplate, bool isAdd)
        {
            Res_Template template = new Res_Template();

            if (isAdd)
            {
                template.TemplateId    = restemplate.Id;
                template.TemplateName  = restemplate.Name;
                template.StartRowIndex = restemplate.StartRowIndex;
                template.InputDate     = restemplate.InputDate;
                template.InputUser     = restemplate.InputUser;
            }
            template.IsValid = restemplate.IsValid;
            return(template);
        }
Exemplo n.º 7
0
        public static ResTemplate GetById(string id)
        {
            ResTemplate template = null;

            using (pm2Entities entities = new pm2Entities())
            {
                Res_Template template2 = (from m in entities.Res_Template
                                          where m.TemplateId == id
                                          select m).FirstOrDefault <Res_Template>();
                if (template2 != null)
                {
                    template = new ResTemplate {
                        Id            = template2.TemplateId,
                        Name          = template2.TemplateName,
                        IsValid       = template2.IsValid,
                        InputDate     = template2.InputDate,
                        InputUser     = template2.InputUser,
                        StartRowIndex = template2.StartRowIndex
                    };
                }
            }
            return(template);
        }
Exemplo n.º 8
0
 protected void btnReturn_Click(object sender, System.EventArgs e)
 {
     System.Collections.IEnumerator enumerator = this.gvResource.Rows.GetEnumerator();
     try
     {
         while (enumerator.MoveNext())
         {
             GridViewRow gridViewRow = (GridViewRow)enumerator.Current;
             CheckBox    cb          = gridViewRow.FindControl("cbBox") as CheckBox;
             if (cb != null && cb.Checked)
             {
                 using (pm2Entities pm2Entities = new pm2Entities())
                 {
                     Res_Template res_Template = (
                         from m in pm2Entities.Res_Template
                         where m.TemplateId == cb.ToolTip
                         select m).FirstOrDefault <Res_Template>();
                     if (res_Template != null)
                     {
                         res_Template.IsValid = new bool?(true);
                         pm2Entities.SaveChanges();
                     }
                 }
             }
         }
     }
     finally
     {
         System.IDisposable disposable = enumerator as System.IDisposable;
         if (disposable != null)
         {
             disposable.Dispose();
         }
     }
     base.RegisterScript("location.href=location.href;");
 }