Пример #1
0
        public async Task <IActionResult> PostBook([FromBody] PostBook postBook)
        {
            Author author = await this._context.Authors.FindAsync(postBook.AuthorId);

            if (author == null)
            {
                author = new Author()
                {
                    FirstName = postBook.AuthorFullName.Split(' ')[0], LastName = postBook.AuthorFullName.Split(' ')[1]
                };
                this._context.Authors.Add(author);
            }

            Book book = new Book()
            {
                Title       = postBook.Title,
                ImageSrc    = postBook.ImageSrc,
                Condition   = postBook.Condition,
                Description = postBook.Description,
                Price       = postBook.Price,
                Author      = author
            };

            _context.Books.Add(book);

            await _context.SaveChangesAsync();

            return(this.Ok(book.Id));
        }
Пример #2
0
        protected void Button_ExportExcel_Click(object sender, EventArgs e)
        {
            string   exception     = "";
            string   evaluatedID   = Request.QueryString["id"];
            string   evaluatedName = Request.QueryString["name"];
            PostBook postBook      = new PostBook();

            if (PostBookManagementCtrl.GetPostBook(ref postBook, evaluatedID, ref exception))
            {
                string filename = "";
                if (ExportManagementCtrl.ExportPostBook(ref filename, evaluatedName, postBook, ref exception))
                {
                    Response.ClearContent();
                    Response.ContentType = "application/excel";
                    Response.AddHeader("content-disposition", "attachment;filename=" + Server.UrlEncode(filename));
                    string path = Server.MapPath("..\\..\\downloadfiles\\" + filename);
                    Response.TransmitFile(path);
                }
                else
                {
                    Alert.ShowInTop("导出失败!\n原因:" + exception, MessageBoxIcon.Error);
                }
            }
            else
            {
                Alert.ShowInTop("导出失败!\n原因:" + exception, MessageBoxIcon.Error);
            }
        }
Пример #3
0
        static public Genre CheckGenre(PostBook book)
        {
            Genre genre = null;
            var   db    = new LibraryContext();

            if (!String.IsNullOrEmpty(book.GenreName))
            {
                var match = db.Genres.FirstOrDefault(x => x.DisplayName == book.GenreName);

                if (match != null)
                {
                    // Reference match in DB, set it to author.
                    genre = match;
                }
                else
                {
                    // Create author.
                    genre = new Genre
                    {
                        DisplayName = book.GenreName
                    };
                    db.Genres.Add(genre);
                    db.SaveChanges();
                }
            }
            return(db.Genres.FirstOrDefault(x => x.DisplayName == book.GenreName));
        }
Пример #4
0
        static public Author CheckAuthor(PostBook book)
        {
            Author author = null;
            var    db     = new LibraryContext();

            if (!String.IsNullOrEmpty(book.AuthorName))
            {
                var match = db.Authors.FirstOrDefault(x => x.Name == book.AuthorName);

                if (match != null)
                {
                    // Reference match in DB, set it to author.
                    author = match;
                }
                else
                {
                    // Create author.
                    author = new Author
                    {
                        Name = book.AuthorName
                    };
                    db.Authors.Add(author);
                    db.SaveChanges();
                }
            }
            return(db.Authors.FirstOrDefault(x => x.Name == book.AuthorName));
        }
Пример #5
0
        /// <summary>
        /// 保存岗位责任书并将其状态设置成指定状态
        /// </summary>
        /// <param name="status">指定的状态</param>
        /// <returns></returns>
        private PostBook getPostBook()
        {
            PostBook pb = new PostBook();

            pb.EvaluatedID  = Request.QueryString["id"];
            pb.Employer     = Radio_Employer.SelectedValue;
            pb.LaborUnit    = Label_Depart.Text;
            pb.LaborDepart  = TextBox_LaborDepart.Text;
            pb.PostName     = Label_PostName.Text;
            pb.PostType     = Radio_PostType.SelectedValue;
            pb.EduBg        = TextArea_EduBg.Text;
            pb.Certificate  = TextArea_Certificate.Text;
            pb.Experience   = TextArea_Experience.Text;
            pb.Skill        = TextArea_Skill.Text;
            pb.Personality  = TextArea_Personality.Text;
            pb.PhyCond      = TextArea_PhyCond.Text;
            pb.WorkOutline  = TextArea_WorkOutline.Text;
            pb.Power        = TextArea_Power.Text;
            pb.Response     = TextArea_Response.Text;
            pb.DirectLeader = TextBox_DirectLeader.Text;
            pb.Subordinate  = TextBox_Subordinate.Text;
            pb.Colleague    = TextBox_Colleague.Text;
            pb.Services     = TextBox_Services.Text;
            pb.Relations    = TextBox_Relations.Text;
            pb.WorkEnter    = TextArea_WorkEnter.Text;
            pb.PostAssess   = TextArea_PostAssess.Text;
            pb.Others       = TextArea_Others.Text;

            pb.Comment = Label_Comment.Text;

            List <string[]> wcr = new List <string[]>();

            foreach (ControlBase item in Panel6.Items)
            {
                try
                {
                    SimpleForm sf  = item as SimpleForm;
                    TextArea   ta0 = sf.Items[0] as TextArea;
                    if (ta0.Text != "")             //填写了标题即认为填写了这一项
                    {
                        TextArea ta1     = sf.Items[1] as TextArea;
                        TextArea ta2     = sf.Items[2] as TextArea;
                        TextArea ta3     = sf.Items[3] as TextArea;
                        string[] content = new string[] { ta0.Text, ta1.Text, ta2.Text, ta3.Text };
                        wcr.Add(content);
                    }
                }
                catch (Exception)
                {
                    continue;
                }
            }
            pb.WorkContentRequest = wcr;

            return(pb);
        }
Пример #6
0
        protected void Button_Submit_Click(object sender, EventArgs e)
        {
            string exception = "";

            if (!checkNull())   //检查项是否有空
            {
                Alert.ShowInTop("有未填项,请检查!", MessageBoxIcon.Error);
                return;
            }

            PostBook pb = getPostBook();

            if (pb.WorkContentRequest.Count < 6)    //工作内容与要求至少需要6项
            {
                Alert.ShowInTop("请填写至少6项工作内容与要求!");
                return;
            }
            foreach (string[] item in pb.WorkContentRequest)        //检查是否存在工作内容与要求中填写了标题却没填其他项(考核要点不检查)
            {
                if (item[0] == "" || item[1] == "" || item[2] == "")
                {
                    Alert.ShowInTop("工作内容与要求中尚有未填写项!");
                    return;
                }
            }

            List <string> tempTitleList = new List <string>();        //检查工作内容与要求中的标题是否有重复项

            foreach (string[] item in pb.WorkContentRequest)
            {
                if (tempTitleList.Contains(item[0]))
                {
                    Alert.ShowInTop("工作内容与要求中有重复项,请重新填写", MessageBoxIcon.Error);
                    return;
                }
                tempTitleList.Add(item[0]);
            }

            DocStatus curStatus  = (DocStatus)Convert.ToInt32(Request.QueryString["status"]);
            DocStatus nextStatus = GetNextDocStatus(curStatus, DocOperation.submit);

            pb.Status = nextStatus;         //填写下一个状态域

            if (PostBookManagementCtrl.UpdatePostBook(pb, ref exception))
            {
                Alert.ShowInTop("提交成功!\n窗口即将关闭", MessageBoxIcon.Information);
                PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
            }
            else
            {
                Alert.ShowInTop("提交失败!\n原因:" + exception, MessageBoxIcon.Error);
            }
        }
Пример #7
0
        protected void Button_Save_Click(object sender, EventArgs e)
        {
            string   exception = "";
            PostBook pb        = getPostBook();

            DocStatus curStatus  = (DocStatus)Convert.ToInt32(Request.QueryString["status"]);
            DocStatus nextStatus = GetNextDocStatus(curStatus, DocOperation.save);

            pb.Status = nextStatus;     //填写下一个状态域

            if (PostBookManagementCtrl.UpdatePostBook(pb, ref exception))
            {
                Alert.ShowInTop("保存成功!", MessageBoxIcon.Information);
            }
            else
            {
                Alert.ShowInTop("保存失败!\n原因:" + exception, MessageBoxIcon.Error);
            }
        }
Пример #8
0
        public IHttpActionResult CreateBook(PostBook book)
        {
            Author author = DataChecks.CheckAuthor(book);
            Genre  genre  = DataChecks.CheckGenre(book);

            // The null value of DateTime is 0001, 01, 01.
            if (book.DueBackDate == new DateTime(0001, 01, 01))
            {
                book.DueBackDate = new DateTime(1990, 01, 01);
            }

            var newBook = new Book
            {
                Title         = book.BookTitle,
                YearPublished = book.YearPublished,
                Condition     = book.Condition,

                // Get Author name.
                AuthorID = author.ID,

                // Get Genre.
                GenreID = genre.ID,

                ISBN         = book.ISBN,
                IsCheckedOut = book.IsCheckedOut,
                DueBackDate  = book.DueBackDate
            };

            var db = new LibraryContext();

            db.Books.Add(newBook);
            db.SaveChanges();
            // Tack properties on to the newBook and then return.
            newBook.Author = author;
            newBook.Genre  = genre;
            return(Ok(newBook));
        }
Пример #9
0
        //Add a new Book
        //Need to add null checking (Author and Genre)
        public Book Post(PostBook bookData)
        {
            var db = new DataContext();

            Author author = db.Authors.First(x => x.Name == bookData.AuthorName);
            Genre  genre  = db.Genres.First(x => x.Name == bookData.GenreName);

            var newBook = new Book
            {
                Title         = bookData.Title,
                YearPublished = bookData.YearPublished,
                Condition     = bookData.Condition,
                AuthorID      = author.ID,
                GenreID       = genre.ID,
                ISBN          = bookData.ISBN,
                IsCheckedOut  = bookData.IsCheckedOut,
            };

            db.Books.Add(newBook);
            db.SaveChanges();
            newBook.Author = author;
            newBook.Genre  = genre;
            return(newBook);
        }
Пример #10
0
        /// <summary>
        /// 载入岗位责任书
        /// </summary>
        private void loadPostBook(string id)
        {
            string exception   = "";
            string evaluatedID = "";

            if (id == "" || id == "0")
            {
                evaluatedID = Request.QueryString["id"];
            }
            else
            {
                evaluatedID = id;
            }
            string name = Request.QueryString["name"];

            Panel1.Title = name + "的岗位责任书";
            PostBook pb = new PostBook();

            Label_Depart.Text            = Request.QueryString["depart"];
            Radio_PostType.SelectedValue = Request.QueryString["posttype"];
            Radio_Employer.SelectedValue = Request.QueryString["company"];
            if (PostBookManagementCtrl.GetPostBook(ref pb, evaluatedID, ref exception))
            {
                foreach (string[] content in pb.WorkContentRequest)
                {
                    if (content.Length != 4)
                    {
                        return;
                    }
                }
                string evaluatedName = Request.QueryString["name"];
                Label_Comment.Text = pb.Comment;

                TextBox_LaborDepart.Text  = pb.LaborDepart;
                Label_PostName.Text       = pb.PostName;
                TextArea_EduBg.Text       = pb.EduBg;
                TextArea_Certificate.Text = pb.Certificate;
                TextArea_Experience.Text  = pb.Experience;
                TextArea_Skill.Text       = pb.Skill;
                TextArea_Personality.Text = pb.Personality;
                TextArea_PhyCond.Text     = pb.PhyCond;
                TextArea_WorkOutline.Text = pb.WorkOutline;
                TextArea_Power.Text       = pb.Power;
                TextArea_Response.Text    = pb.Response;
                TextBox_DirectLeader.Text = pb.DirectLeader;
                TextBox_Subordinate.Text  = pb.Subordinate;
                TextBox_Colleague.Text    = pb.Colleague;
                TextBox_Services.Text     = pb.Services;
                TextBox_Relations.Text    = pb.Relations;
                TextArea_WorkEnter.Text   = pb.WorkEnter;
                TextArea_PostAssess.Text  = pb.PostAssess;
                TextArea_Others.Text      = pb.Others;

                addWorkContentRequest(pb.WorkContentRequest);
            }
            else
            {
                TextBox_LaborDepart.Text = Request.QueryString["labordepart"];
                Label_PostName.Text      = Request.QueryString["postname"];
            }
        }