public ActionResult Create(Article article) { if (ModelState.IsValid) { try { article.ArtPostTime = DateTime.Now; article.ArtStatus = "New"; ListAccount accountManager = new ListAccount(); bool isAdmin = accountManager.getRole(article.ArtUsername); if (isAdmin) { article.ArtStatus = "Active"; db.Articles.Add(article); db.SaveChanges(); return(RedirectToAction("Index", "Admin")); } db.Articles.Add(article); db.SaveChanges(); return(RedirectToAction("Profile", "Accounts")); } catch (Exception e) { CommonUse.WriteLogError(e); } } return(View(article)); }
// GET: Articles/Details/5 public ActionResult Details(int?id) { ViewModelResult model = new ViewModelResult(); try { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CommentList cmtList = new CommentList(); var comments = cmtList.getListComment(id); ArticleList art = new ArticleList(); var details = art.getDetailArticle(id); model = new ViewModelResult { articleDetail = details, listComment = comments }; } catch (Exception e) { CommonUse.WriteLogError(e); } return(View(model)); }
public ActionResult Register(Account account) { bool isInsert = false; if (account.FullName.Equals("UserBlocked")) { ViewBag.Message = "Please input real Full Name"; return(View()); } try { // TODO: Add insert logic here ListAccount listAccount = new ListAccount(); isInsert = listAccount.RegisterNewAccount(account); if (isInsert) { Session["Msg_reg_succ"] = "Register Success"; return(RedirectToAction("Login")); } else { ViewBag.Message = "This Username has been exist! Please choose another one"; } } catch (Exception e) { ViewBag.Message = "This Username has been exist! Please choose another one"; CommonUse.WriteLogError(e); } return(View()); }
private void 添加人员ToolStripMenuItem_Click(object sender, EventArgs e) { CommonUse commUse = new CommonUse(); var x = (ToolStripMenuItem)sender; commUse.ShowForm(x.Tag.ToString(), this.main); }
private void Main_Load(object sender, EventArgs e) { laUser.Text = PropetyClass.User; CommonUse commUse = new CommonUse(); var x = (Form)sender; commUse.ShowForm(x.Tag.ToString(), this); }
public ActionResult DeleteConfirmed(int id) { try { Article article = db.Articles.Find(id); db.Articles.Remove(article); db.SaveChanges(); } catch (Exception e) { CommonUse.WriteLogError(e); } return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "ArtID,ArtTittle,ArtContent,ArtPostTime,ArtAuthor,ArtStatus,ViewCount,LikeCount")] Article article) { if (ModelState.IsValid) { try { db.Entry(article).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception e) { CommonUse.WriteLogError(e); } } return(View(article)); }
private void btnDelete_Click(object sender, EventArgs e) { string strSql = null; string strDepartmentCode = null; DataBase db = new DataBase(); if (tvDepartment.SelectedNode != null) { if (tvDepartment.SelectedNode.Tag != null) { strDepartmentCode = tvDepartment.SelectedNode.Tag.ToString(); //判断当前记录的主键值是否存在外键约束 if (commUse.IsExistConstraint("BSDepartment", strDepartmentCode)) { MessageBox.Show("已发生业务关系,无法删除", "软件提示"); return; } if (MessageBox.Show("确定要删除吗?", "软件提示", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { strSql = "DELETE FROM BSDepartment WHERE DepartmentCode = '" + strDepartmentCode + "'"; try { if (db.ExecDataBySql(strSql) > 0) { MessageBox.Show("删除成功!", "软件提示"); commUse = new CommonUse(); commUse.BuildTree(tvDepartment, imageList1, "部门分类", "BSDepartment", "DepartmentCode", "DepartmentName"); } else { MessageBox.Show("删除失败!", "软件提示"); } } catch (Exception ex) { MessageBox.Show(ex.Message, "软件提示"); } } } } }
public ActionResult Index() { List <Account> list = new List <Account>(); try { ListAccount accountList = new ListAccount(); list = accountList.getListAccount(); } catch (Exception e) { CommonUse.WriteLogError(e); } return(View(list)); }
// GET: Articles/Create public ActionResult Create() { try { object username = Session["USER_NAME"]; if (username == null) { Session["Redirect_to_PostArticle"] = "You need Login to Post article"; return(RedirectToAction("Login", "Accounts")); } } catch (Exception e) { CommonUse.WriteLogError(e); } return(View()); }
// GET: Admin public ActionResult Index(string searchVal) { List <Article> list = new List <Article>(); try { ArticleList articleList = new ArticleList(); list = articleList.getListManagerArticle(); if (searchVal != null) { list.Clear(); list = articleList.searchManagerArticle(searchVal); } } catch (Exception e) { CommonUse.WriteLogError(e); } return(View(list)); }
public ActionResult Login(Account account) { try { if (ModelState.IsValid) { ListAccount Accounts = new ListAccount(); string fullname = Accounts.checkLogin(account.Username, account.Password, account.Role); if (fullname != null) { if (fullname.Equals("UserBlocked")) { ViewBag.Message = "Your account was blocked ! "; } else { account.FullName = fullname; Session["FULL_NAME"] = account.FullName.ToUpper(); Session["USER_NAME"] = account.Username; Session["ROLE"] = account.Role; return(RedirectToAction("Index", "Home")); } } else { ViewBag.Message = "Invalid username or password"; } } } catch (Exception e) { CommonUse.WriteLogError(e); } return(View()); }
// GET: Account public ActionResult Login() { try { if (Session["Msg_reg_succ"] != null) { ViewBag.Msg = Session["Msg_reg_succ"].ToString(); Session.Remove("Msg_reg_succ"); } if (Session["Redirect_to_PostArticle"] != null) { ViewBag.Message = Session["Redirect_to_PostArticle"].ToString(); Session.Remove("Redirect_to_PostArticle"); } } catch (Exception e) { CommonUse.WriteLogError(e); } return(View()); }
// GET: Articles/Edit/5 public ActionResult Edit(int?id) { Article article = null; try { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } article = db.Articles.Find(id); if (article == null) { return(HttpNotFound()); } } catch (Exception e) { CommonUse.WriteLogError(e); } return(View(article)); }
private string GetServerCookie() { if (String.IsNullOrEmpty(Config.UserName)) { return(""); } String postUrl = Config.CookieUrl; LoginInfoSyncRequest infoSyncRequest = new LoginInfoSyncRequest(); infoSyncRequest.channelKey = Config.UserName; String postData = JsonConvert.SerializeObject(infoSyncRequest); String result = ""; try { result = CommonUse.Post(postUrl, postData, null, 60, "application/json", false); } catch (Exception ex) { throw new Exception(String.Format("获取工号登录信息失败,请与管理员联系!\r\n\r\n({0})", ex.Message)); } return(result); }
// GET: Articles //View all article/search public ActionResult Index(string searchVal) { List <Article> list = new List <Article>(); try { ArticleList articleList = new ArticleList(); list = articleList.getListActiveArticle(); if (searchVal != null) { list.Clear(); if (Session["ROLE"] != null) { if (Session["ROLE"].ToString().Equals("Admin")) { return(RedirectToAction("Index", "Admin", new { searchVal })); } else { list = articleList.searchActiveArticle(searchVal); } } else { list = articleList.searchActiveArticle(searchVal); } } }catch (Exception e) { CommonUse.WriteLogError(e); } return(View(list)); }
private void btnOk_Click(object sender, EventArgs e) { string strCode = null; SqlDataReader sdr = null; CommonUse commUse = null; errorInfo.Clear(); if (String.IsNullOrEmpty(txtTypeCode.Text.Trim())) { errorInfo.SetError(txtTypeCode, "类别编码不许为空!"); return; } if (String.IsNullOrEmpty(txtTypeName.Text.Trim())) { errorInfo.SetError(txtTypeName, "类别名称不许为空!"); return; } if (this.Tag.ToString() == "Add") //添加操作 { strCode = "select * from BSCostType where CostTypeCode = '" + txtTypeCode.Text.Trim() + "'"; try { sdr = db.GetDataReader(strCode); sdr.Read(); if (!sdr.HasRows) { sdr.Close(); strCode = "INSERT INTO BSCostType(CostTypeCode,CostTypeName) VALUES('" + txtTypeCode.Text.Trim() + "','" + txtTypeName.Text.Trim() + "')"; if (db.ExecDataBySql(strCode) > 0) { MessageBox.Show("保存成功!", "软件提示"); commUse = new CommonUse(); commUse.BuildTree(formCostType.tvCostType, formCostType.imageList1, "费用分类", "BSCostType", "CostTypeCode", "CostTypeName"); btnQuit_Click(sender, e); } else { MessageBox.Show("保存失败!", "软件提示"); } } else { MessageBox.Show("编码重复,请重新设置", "软件提示"); txtTypeCode.Focus(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "软件提示"); throw ex; } finally { sdr.Close(); } } else //修改操作 { //类别代码被修改过 if (formCostType.tvCostType.SelectedNode.Tag.ToString() != txtTypeCode.Text.Trim()) { strCode = "select * from BSCostType where CostTypeCode = '" + txtTypeCode.Text.Trim() + "'"; try { sdr = db.GetDataReader(strCode); sdr.Read(); if (sdr.HasRows) { MessageBox.Show("编码重复,请重新设置", "软件提示"); txtTypeCode.Focus(); sdr.Close(); return; } } catch (Exception ex) { MessageBox.Show(ex.Message, "软件提示"); throw ex; } finally { sdr.Close(); } } //更新数据库 try { strCode = "UPDATE BSCostType SET CostTypeCode = '" + txtTypeCode.Text.Trim() + "',CostTypeName = '" + txtTypeName.Text.Trim() + "' WHERE CostTypeCode = '" + formCostType.tvCostType.SelectedNode.Tag.ToString() + "'"; if (db.ExecDataBySql(strCode) > 0) { MessageBox.Show("保存成功!", "软件提示"); commUse = new CommonUse(); commUse.BuildTree(formCostType.tvCostType, formCostType.imageList1, "费用分类", "BSCostType", "CostTypeCode", "CostTypeName"); btnQuit_Click(sender, e); } else { MessageBox.Show("保存失败!", "软件提示"); } } catch (Exception ex) { MessageBox.Show(ex.Message, "软件提示"); throw ex; } } }
private void 人员管理ToolStripMenuItem_Click(object sender, EventArgs e) { CommonUse commUse = new CommonUse(); commUse.ShowForm((ToolStripMenuItem)sender, this); }
protected void btnUpload_Click(object sender, EventArgs e) { CurrentLocation = ConfigurationManager.AppSettings["RootPath"]; // The file Extension string fileExtension = string.Empty; // The choosed file name string fileName = string.Empty; // The new file name in the server string newFileName = string.Empty; // Check if choosed a file if (!fuChooseFile.HasFile) { lbMessage.Text = "Please choose the file you want to upload. " + "Note: The file size cannot be zero."; return; } fileExtension = Path.GetExtension(fuChooseFile.FileName); fileName = string.Format("{0}\\{1}", CurrentLocation, (string.IsNullOrEmpty(fileExtension) ? fuChooseFile.FileName : fuChooseFile.FileName.Replace(fileExtension, ""))); if (fileExtension.ToLower() == ".exe" || fileExtension.ToLower() == ".msi") { lbMessage.Text = "The file you want to upload cannot be a .exe or .msi file."; return; } newFileName = fileName; // Check file size //if (fuChooseFile.PostedFile.ContentLength >= 1024*1024*40) //{ // lbMessage.Text = // "The file you want to upload cannot be larger than 40 MB."; // return; //} try { // If there is already a file with the same name in the system,rename // and then upload the file . int i = 0; while (File.Exists(newFileName + fileExtension)) { i++; newFileName = string.Format(fileName + "({0})", i); } fuChooseFile.SaveAs(Utilities.FixRoot(newFileName + fileExtension)); lbMessage.Text = string.Format("The file \"{0}\" was uploaded successfully!", Path.GetFileName(fileName)); ShowFolderItems(); } catch (HttpException he) { lbMessage.Text = string.Format("File {0} upload failed because of the following error:{1}.", fuChooseFile.PostedFile.FileName, he.Message); } //the file id var _file2 = new FileInfo(newFileName); var db = new CloudAppDbEntities(); var _file = new UserFile() { FName = Path.GetFileName(newFileName), FileName = Path.GetFileName(fileName), UploaderID = currentUserID, // don't forget to find currentuserID //FileSize = CommonUse.FormatFileSize((long)fuChooseFile.PostedFile.ContentLength) , FileSize = CommonUse.FormatFileSize((long)fuChooseFile.PostedFile.ContentLength), FileType = fileExtension, UploadTime = _file2.CreationTime, CourseID = null, ClassID = classID }; db.UserFile.Add(_file); db.SaveChanges(); }
private void laFLL_Click(object sender, EventArgs e) { CommonUse commUse = new CommonUse(); commUse.ShowForm((Label)sender, this.main); }