예제 #1
0
        public IActionResult Delete(int id)
        {
            try
            {
                var companyToDelete = _context.Companies.FirstOrDefault(x => x.Id == id);

                _context.Companies.Remove(companyToDelete);
                _context.SaveChanges();
                return(View());
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string title    = this.txtTitle.Text.Trim();
            string filePath = this.txtFilePath.Text.Trim();
            string summary  = this.txtSummary.Text.Trim();

            try
            {
                using (var context = new PaperContext())
                {
                    var entity = new PPTTemplate
                    {
                        Title   = title,
                        Path    = filePath,
                        Summary = summary,
                        AddDate = DateTime.Now
                    };
                    context.PPTTemplates.Add(entity);
                    context.SaveChanges();
                    this.txtTitle.Text    = string.Empty;
                    this.txtFilePath.Text = string.Empty;
                    this.txtSummary.Text  = string.Empty;
                    BingGridView1Data();
                }
            }
            catch (DbEntityValidationException ex)
            {
                throw new Exception(ex.Message);
            }
        }
예제 #3
0
        protected void btnSavePaperCategory_Click(object sender, EventArgs e)
        {
            string categoryName       = this.txtPaperCategoryName.Text.Trim();
            string categorySummary    = this.txtPaperCategorySummary.Text.Trim();
            string customerCategoryId = this.ddlCustomerCategoryID.SelectedValue;

            using (var context = new PaperContext())
            {
                if (this.hidePaperCategoryAction.Value == "add")
                {
                    var entity = new PaperCategory
                    {
                        CategoryName       = categoryName,
                        CategorySummary    = categorySummary,
                        CustomerCategoryID = int.Parse(customerCategoryId)
                    };
                    context.PaperCategories.Add(entity);
                    context.SaveChanges();
                    this.hidePaperCategoryAction.Value = "add";
                }
                else
                {
                    var id         = this.hidePaperCategoryID.Value;
                    int categoryId = int.Parse(id);
                    var entity     = context.PaperCategories.Find(categoryId);
                    if (entity != null)
                    {
                        entity.CategoryName       = categoryName;
                        entity.CategorySummary    = categorySummary;
                        entity.CustomerCategoryID = int.Parse(customerCategoryId);
                        context.SaveChanges();
                        this.hidePaperCategoryID.Value     = "0";
                        this.hidePaperCategoryAction.Value = "add";
                    }
                }
                InitRepeater2();
                this.txtPaperCategoryName.Text    = string.Empty;
                this.txtPaperCategorySummary.Text = string.Empty;
                BindPaperCategory();
            }
        }
        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            int     index      = e.RowIndex;
            var     id         = this.GridView1.DataKeys[index].Values[0];
            TextBox txtTitle   = ((TextBox)this.GridView1.Rows[index].FindControl("txtTitle"));
            TextBox txtPath    = ((TextBox)this.GridView1.Rows[index].FindControl("txtPath"));
            TextBox txtSummary = ((TextBox)this.GridView1.Rows[index].FindControl("txtSummary"));

            using (var context = new PaperContext())
            {
                var entity = context.PPTTemplates.Find(id);
                if (entity != null)
                {
                    entity.Title   = txtTitle.Text;
                    entity.Path    = txtPath.Text;
                    entity.Summary = txtSummary.Text;
                    context.SaveChanges();
                }
            }
            this.GridView1.EditIndex = -1;
            BingGridView1Data();
        }
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int index = e.RowIndex;
            var id    = this.GridView1.DataKeys[index].Values[0];

            using (var context = new PaperContext())
            {
                var entity = context.PPTTemplates.Find(id);
                if (entity != null)
                {
                    string path = entity.Path;
                    context.PPTTemplates.Remove(entity);
                    try
                    {
                        context.SaveChanges();
                        if (!string.IsNullOrEmpty(path))
                        {
                            FileInfo fileInfo = new FileInfo(Server.MapPath(path));
                            if (fileInfo.Exists)
                            {
                                fileInfo.Delete();
                                MessageBox.Show(this, "模版文件删除成功");
                                BingGridView1Data(this.AspNetPager1.CurrentPageIndex);
                            }
                            else
                            {
                                MessageBox.Show(this, "模版文件不存在");
                            }
                        }
                    }
                    catch (Exception)
                    {
                        MessageBox.Show(this, "模版文件删除失败");
                    }
                }
            }
        }
예제 #6
0
        protected void lnkPaperCategoryDelete_Command(object sender, CommandEventArgs e)
        {
            var id = e.CommandArgument.ToString();

            using (var context = new PaperContext())
            {
                int categoryId = int.Parse(id);
                var entity     = context.PaperCategories.Find(categoryId);
                if (entity != null)
                {
                    var entities = context.Papers.Where(p => p.CategoryID == categoryId);
                    context.Papers.RemoveRange(entities);
                    context.PaperCategories.Remove(entity);
                    context.SaveChanges();
                    this.hidePaperCategoryID.Value     = "0";
                    this.hidePaperCategoryAction.Value = "add";
                    InitRepeater2();
                    this.txtPaperCategoryName.Text    = string.Empty;
                    this.txtPaperCategorySummary.Text = string.Empty;
                    BindPaperCategory();
                    InitRepeater1(this.AspNetPager1.CurrentPageIndex, int.Parse(this.ddlCustomer.SelectedValue), int.Parse(this.ddlCustomerCategory.SelectedValue), int.Parse(this.ddlPaperCategory.SelectedValue));
                }
            }
        }
예제 #7
0
        protected void btnDelete_Command(object sender, CommandEventArgs e)
        {
            int paperId = 0;

            int.TryParse(e.CommandArgument.ToString(), out paperId);
            using (var context = new PaperContext())
            {
                var entity = context.Papers.Find(paperId);
                if (entity != null)
                {
                    context.Papers.Remove(entity);
                    try
                    {
                        context.SaveChanges();
                        ScriptManager.RegisterStartupScript(this.UpdatePanel1, GetType(), "alert", "alert('文章删除成功')", true);
                        InitRepeater1(this.AspNetPager1.CurrentPageIndex, int.Parse(this.ddlCustomer.SelectedValue), int.Parse(this.ddlCustomerCategory.SelectedValue), int.Parse(this.ddlPaperCategory.SelectedValue));
                    }
                    catch (Exception)
                    {
                        ScriptManager.RegisterStartupScript(this.UpdatePanel1, GetType(), "alert", "alert('文章删除失败')", true);
                    }
                }
            }
        }
예제 #8
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string customerCategoryId = this.ddlCustomerCategory.SelectedValue;
            string customerId         = this.ddlCustomer.SelectedValue;
            string categoryId         = this.ddlPaperCategory.SelectedValue;
            string title         = this.txtTitle.Text.Trim();
            string publishedDate = this.txtPublishedDate.Text.Trim();
            string reprintCount  = this.txtReprintCount.Text.Trim();
            string firstSite     = this.txtFirstSite.Text.Trim();
            string reprintSite   = this.txtReprintSite.Text.Trim();
            string url           = this.txtUrl.Text.Trim();
            string summary       = this.txtSummary.Text.Trim();

            using (var context = new PaperContext())
            {
                if (this.hidePaperID.Value == "0")
                {
                    var entity = new Paper
                    {
                        CustomerID         = int.Parse(customerId),
                        CategoryID         = int.Parse(categoryId),
                        CustomerCategoryID = int.Parse(customerCategoryId),
                        Title = title,
                        PaperPublishedDate = publishedDate,
                        ReprintCount       = int.Parse(reprintCount),
                        FirstSite          = firstSite,
                        ReprintSite        = reprintSite,
                        Url     = url,
                        Summary = summary,
                        AddDate = DateTime.Now
                    };
                    context.Papers.Add(entity);
                }
                else if (this.hidePaperID.Value != "0")
                {
                    int paperId = int.Parse(this.hidePaperID.Value);
                    var entity  = context.Papers.Find(paperId);
                    entity.CustomerID         = int.Parse(customerId);
                    entity.CategoryID         = int.Parse(categoryId);
                    entity.CustomerCategoryID = int.Parse(customerCategoryId);
                    entity.Title = title;
                    entity.PaperPublishedDate = publishedDate;
                    entity.ReprintCount       = int.Parse(reprintCount);
                    entity.FirstSite          = firstSite;
                    entity.ReprintSite        = reprintSite;
                    entity.Url     = url;
                    entity.Summary = summary;
                    entity.AddDate = DateTime.Now;
                    this.ddlCustomer.SelectedIndex = -1;
                }
                context.SaveChanges();
                this.txtTitle.Text         = string.Empty;
                this.txtPublishedDate.Text = string.Empty;
                this.txtReprintCount.Text  = "0";
                this.txtFirstSite.Text     = string.Empty;
                this.txtReprintSite.Text   = string.Empty;
                this.txtUrl.Text           = string.Empty;
                this.txtSummary.Text       = string.Empty;
                this.hidePaperID.Value     = "0";
                InitRepeater1(this.AspNetPager1.CurrentPageIndex, int.Parse(this.ddlCustomer.SelectedValue), int.Parse(this.ddlCustomerCategory.SelectedValue), int.Parse(this.ddlPaperCategory.SelectedValue));
            }
        }