public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object v) { try { if (v is string) { foreach (DictionaryEntry myDE in _hash) { if (myDE.Value.Equals((v.ToString()))) return myDE.Key; } } return base.ConvertFrom(context, culture, v); } catch { return ""; throw new Exception("a"); } }
public PagedDataInquiryResponse<Task> GetTasks(System.Net.Http.HttpRequestMessage requestMessage) { var request = _pagedDataRequestFactory.Create(requestMessage.RequestUri); var tasks = _allTasksInquiryProcessor.GetTasks(request); return tasks; }
public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext) { base.OnAuthorization(actionContext); if (!CurrentHttpContext.Authorize) HandleUnauthorizedRequest(actionContext); }
protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity<Dad>() .Property(x => x.DayOfBirth).IsRequired(); }
/// <summary> /// 显示消息提示对话框 /// </summary> /// <param name="page">当前页面指针,一般为this</param> /// <param name="msg">提示信息</param> public static void Show(System.Web.UI.Page page, string msg) { page.ClientScript.RegisterStartupScript(page.GetType(), "message", "<script language='javascript' defer>alert('" + msg + "');</script>"); // UpdatePanel采用如下方式弹出对话框 //System.Web.UI.ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "javascript", "alert('您已经投过票!');", true); }
/// <summary> /// 添加CSS样式内容 /// </summary> /// <param name="page">页面</param> /// <param name="content">样式内容</param> public void AddStyle(System.Web.UI.Page page, string content) { HtmlGenericControl styleControl = new HtmlGenericControl("style"); styleControl.Attributes.Add("type", "text/css"); styleControl.InnerHtml = content; page.Header.Controls.Add(styleControl); }
/// <summary> /// 添加JS脚本内容 /// </summary> /// <param name="page">页面</param> /// <param name="content">脚本内容</param> public void AddScript(System.Web.UI.Page page, string content) { HtmlGenericControl scriptControl = new HtmlGenericControl("script"); scriptControl.Attributes.Add("type", "text/javascript"); scriptControl.InnerHtml = content; page.Header.Controls.Add(scriptControl); }
/// <summary> /// 序列化 /// </summary> /// <param name="filePath">文件路径</param> /// <param name="obj">要序列化的实体类</param> /// <param name="type">类型</param> public static void SaveXml(string filePath, object obj, System.Type type) { //////序列化 成 XML 文件 Object -- > XML //如果文件存在 则先删除原来文件 if (System.IO.File.Exists(filePath)) File.Delete(filePath); using (System.IO.StreamWriter writer = new System.IO.StreamWriter(filePath)) { try { System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(type); xs.Serialize(writer, obj); writer.Close(); } catch (Exception e) { e = e; throw; } } ////////序列化 成 2进制 文件 //FileStream fs = new FileStream(filePath, FileMode.Create); //BinaryFormatter bf = new BinaryFormatter(); //bf.Serialize(fs, obj); }
public ActionResult JiwangshiAdd() { var message = new Message(); var json = new { message.MessageInfo, message.MessageStatus, message.MessageUrl }; return Json(json, JsonRequestBehavior.AllowGet); }
//get project_case details with company info public ActionResult Get(int id=0) { if (id > 0) { project_case proj = Uof.Iproject_caseService.GetById(id); if (proj != null) { company company = proj.company; if (company != null) { var obj = new { id = proj.Id, title = proj.title, descript = proj.descript, type_name = proj.sys_dictionary == null ? "" : proj.sys_dictionary.value, content = proj.content, user_name = proj.user == null ? "" : proj.user.user_name, company = new { name=company.name, logo_path=company.logo_path, mobile=company.mobile, phone=company.phone, address=company.address } }; return Json(obj,JsonRequestBehavior.AllowGet); } } } return Json(new { result=false},JsonRequestBehavior.AllowGet); }
//添加客房 void AddRoom(object sender,System.EventArgs e) { if (MainForm.LoadedUser.Privilege == 0) { AddRoom newAddRoom = new AddRoom(); newAddRoom.Text = "添加客房"; if (newAddRoom.ShowDialog() == DialogResult.OK) { if (new RoomManager().CheckRoomData(NewRoom )) { if (MessageBox.Show("您确定要添加该客房吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK) { if (new RoomManager().AddRoom(NewRoom)) { MessageBox.Show("添加成功!", "提示"); } else { MessageBox.Show("发生错误,没有添加成功!", "提示"); } } } else { MessageBox.Show("您填写的信息有误,请重新填写!", "提示"); } } } else { MessageBox.Show("您没有权限添加客房", "提示"); } }
public static long Solve() { #region numbers var numbersFlat = new[] { 08, 02, 22, 97, 38, 15, 00, 40, 00, 75, 04, 05, 07, 78, 52, 12, 50, 77, 91, 08, 49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 04, 56, 62, 00, 81, 49, 31, 73, 55, 79, 14, 29, 93, 71, 40, 67, 53, 88, 30, 03, 49, 13, 36, 65, 52, 70, 95, 23, 04, 60, 11, 42, 69, 24, 68, 56, 01, 32, 56, 71, 37, 02, 36, 91, 22, 31, 16, 71, 51, 67, 63, 89, 41, 92, 36, 54, 22, 40, 40, 28, 66, 33, 13, 80, 24, 47, 32, 60, 99, 03, 45, 02, 44, 75, 33, 53, 78, 36, 84, 20, 35, 17, 12, 50, 32, 98, 81, 28, 64, 23, 67, 10, 26, 38, 40, 67, 59, 54, 70, 66, 18, 38, 64, 70, 67, 26, 20, 68, 02, 62, 12, 20, 95, 63, 94, 39, 63, 08, 40, 91, 66, 49, 94, 21, 24, 55, 58, 05, 66, 73, 99, 26, 97, 17, 78, 78, 96, 83, 14, 88, 34, 89, 63, 72, 21, 36, 23, 09, 75, 00, 76, 44, 20, 45, 35, 14, 00, 61, 33, 97, 34, 31, 33, 95, 78, 17, 53, 28, 22, 75, 31, 67, 15, 94, 03, 80, 04, 62, 16, 14, 09, 53, 56, 92, 16, 39, 05, 42, 96, 35, 31, 47, 55, 58, 88, 24, 00, 17, 54, 24, 36, 29, 85, 57, 86, 56, 00, 48, 35, 71, 89, 07, 05, 44, 44, 37, 44, 60, 21, 58, 51, 54, 17, 58, 19, 80, 81, 68, 05, 94, 47, 69, 28, 73, 92, 13, 86, 52, 17, 77, 04, 89, 55, 40, 04, 52, 08, 83, 97, 35, 99, 16, 07, 97, 57, 32, 16, 26, 26, 79, 33, 27, 98, 66, 88, 36, 68, 87, 57, 62, 20, 72, 03, 46, 33, 67, 46, 55, 12, 32, 63, 93, 53, 69, 04, 42, 16, 73, 38, 25, 39, 11, 24, 94, 72, 18, 08, 46, 29, 32, 40, 62, 76, 36, 20, 69, 36, 41, 72, 30, 23, 88, 34, 62, 99, 69, 82, 67, 59, 85, 74, 04, 36, 16, 20, 73, 35, 29, 78, 31, 90, 01, 74, 31, 49, 71, 48, 86, 81, 16, 23, 57, 05, 54, 01, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 01, 89, 19, 67, 48, }; #endregion return GetAllFives(numbersFlat.Partition(20)) .Select(five => five.GetProduct()) .Max(); }
/// <summary> /// 添加JS脚本链接 /// </summary> /// <param name="page">页面</param> /// <param name="url">路径</param> public void AddJS(System.Web.UI.Page page, string url) { HtmlGenericControl jsControl = new HtmlGenericControl("script"); jsControl.Attributes.Add("type", "text/javascript"); jsControl.Attributes.Add("src", url); page.Header.Controls.Add(jsControl); }
public void Template(object o, System.EventArgs e) { Cambro.Web.Helpers.WriteAlertHeader(); Cambro.Web.Helpers.WriteAlert("Selecting xxx...", 1); Query q = new Query(); //q.QueryCondition=??? CommentSet bs = new CommentSet(q); for (int count = 0; count < bs.Count; count++) { Comment c = bs[count]; try { // Do work here! c.Update(); if (count % 10 == 0) Cambro.Web.Helpers.WriteAlert("Done " + count + "/" + bs.Count, 2); } catch(Exception ex) { Cambro.Web.Helpers.WriteAlert("Exception " + count + "/" + bs.Count + " - " + ex.ToString(), 3); } bs.Kill(count); } Cambro.Web.Helpers.WriteAlert("Done!", 3); Cambro.Web.Helpers.WriteAlertFooter(); }
/// <summary> /// 单击listview控件的列进行排序 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public static void ListView_ColumnClick(object sender, System.Windows.Forms.ColumnClickEventArgs e) { System.Windows.Forms.ListView lv = sender as System.Windows.Forms.ListView; // 检查点击的列是不是现在的排序列. if (e.Column == (lv.ListViewItemSorter as ListViewColumnSorter).SortColumn) { // 重新设置此列的排序方法. if ((lv.ListViewItemSorter as ListViewColumnSorter).Order == System.Windows.Forms.SortOrder.Ascending) { (lv.ListViewItemSorter as ListViewColumnSorter).Order = System.Windows.Forms.SortOrder.Descending; } else { (lv.ListViewItemSorter as ListViewColumnSorter).Order = System.Windows.Forms.SortOrder.Ascending; } } else { // 设置排序列,默认为正向排序 (lv.ListViewItemSorter as ListViewColumnSorter).SortColumn = e.Column; (lv.ListViewItemSorter as ListViewColumnSorter).Order = System.Windows.Forms.SortOrder.Ascending; } // 用新的排序方法对ListView排序 ((System.Windows.Forms.ListView)sender).Sort(); }
static void ApplicationService_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (!e.Cancel) { Stop(); } }
private void Page_Load(object sender, System.EventArgs e) { Usr.KickUserIfNotLoggedIn(); if (!Usr.Current.IsPromoter) { throw new DsiUserFriendlyException("You must be a promoter to view this page"); } if (Edit) { if (!Usr.Current.CanEdit(CurrentBanner)) throw new DsiUserFriendlyException("You can't edit this banner!"); } if (Mode.Equals(Modes.Delete)) { if (!Usr.Current.CanDelete(CurrentBanner)) throw new DsiUserFriendlyException("You can't delete this banner!"); } if (Edit && Usr.Current.IsAdmin) { ContainerPage.Menu.Admin.AdminPanelOther.Controls.Add(new LiteralControl("<p><a href=\"http://old.dontstayin.com/login-" + Usr.Current.K + "- " + Usr.Current.LoginString + "/admin/banner?ID=" + CurrentBanner.K + "\">Edit banner (admin)</a></p>")); } ContainerPage.SetPageTitle("Banner administration"); if (!Page.IsPostBack) { if (Mode.Equals(Modes.Edit)) ChangePanel(PanelEdit); else if (Mode.Equals(Modes.Delete)) ChangePanel(PanelDelete); else throw new Exception("Wrong mode");
protected override async System.Threading.Tasks.Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) { if(HttpContext.Current.User.Identity.IsAuthenticated) { _log.Debug("Already authenticated; passing on to next handler..."); return await base.SendAsync(request, cancellationToken); } if(!CanHandleAuthentication(request)) { _log.Debug("Not a basic auth request; passing on to next handler..."); return await base.SendAsync(request, cancellationToken); } bool isAuthenticated; try { isAuthenticated = Authenticated(request); } catch(Exception e) { _log.Error("Failure in auth processing", e); return CreateUnauthorizedResponse(); } if(isAuthenticated) { var response = await base.SendAsync(request, cancellationToken); return response.StatusCode == HttpStatusCode.Unauthorized ? CreateUnauthorizedResponse() : response; } return CreateUnauthorizedResponse(); }
/// <summary> /// 显示消息提示对话框,并进行页面跳转 /// </summary> /// <param name="page">当前页面指针,一般为this</param> /// <param name="msg">提示信息</param> /// <param name="url">跳转的目标URL</param> public static void ShowAndRedirect(System.Web.UI.Page page,string msg,string url) { //Response.Write("<script>alert('帐户审核通过!现在去为企业充值。');window.location=\"" + pageurl + "\"</script>"); page.ClientScript.RegisterStartupScript(page.GetType(), UnionID().ToString(), "<script language='javascript' defer>alert('" + msg + "');window.location=\"" + url + "\"</script>"); }
private void Page_Load(object sender, System.EventArgs e) { for (int month = 0; month < 2; month++) { TableCell tc = new TableCell(); tc.VerticalAlign = VerticalAlign.Top; System.Web.UI.WebControls.Calendar c = new System.Web.UI.WebControls.Calendar(); c.VisibleDate = DateTime.Today.AddMonths(month); c.DayRender += new DayRenderEventHandler(DateCal_DayRender); c.DayStyle.Width = Unit.Parse("30px"); c.DayStyle.Height = Unit.Parse("35px"); c.DayStyle.VerticalAlign = VerticalAlign.Top; c.DayStyle.CssClass = "BannerCalendarDay"; c.DayHeaderStyle.CssClass = "BannerCalendarDayHeader"; c.OtherMonthDayStyle.CssClass = "BannerCalendarOtherMonthDay"; c.CssClass = "BannerCalendar"; c.TitleStyle.CssClass = "BannerCalendarTitle"; c.CellPadding = 0; c.CellSpacing = 0; c.ShowNextPrevMonth = false; tc.Controls.Add(c); Row.Cells.Add(tc); } }
private const int DelayBetweenCommands = 500; //ms public static void Main() { var leds = new[] { new OutputPort(Stm32F4Discovery.LedPins.Green, true), new OutputPort(Stm32F4Discovery.LedPins.Orange, true), new OutputPort(Stm32F4Discovery.LedPins.Red, true), new OutputPort(Stm32F4Discovery.LedPins.Blue, true) }; var receiver = new IRReceiver(Stm32F4Discovery.FreePins.PB5); DateTime nextCommand = DateTime.MinValue; receiver.Pulse += (width, state) => { DateTime now = DateTime.Now; if (now < nextCommand) return; nextCommand = now.AddMilliseconds(DelayBetweenCommands); Toggle(leds); }; Thread.Sleep(Timeout.Infinite); }
public static void noCache(System.Web.UI.Page p) {//使页面不进行缓存 p.Response.Expires = -1; p.Response.AddHeader("pragma", "no-cache"); p.Response.AddHeader("cache-control", "no-store"); }
/// <summary> /// 导出Excel文件,转换为可读模式 /// </summary> public static void DataTable2Excel(System.Data.DataTable dtData) { DataGrid dgExport = null; HttpContext curContext = HttpContext.Current; StringWriter strWriter = null; HtmlTextWriter htmlWriter = null; if (dtData != null) { curContext.Response.ContentType = "application/vnd.ms-excel"; curContext.Response.ContentEncoding = System.Text.Encoding.UTF8; curContext.Response.Charset = ""; strWriter = new StringWriter(); htmlWriter = new HtmlTextWriter(strWriter); dgExport = new DataGrid(); dgExport.DataSource = dtData.DefaultView; dgExport.AllowPaging = false; dgExport.DataBind(); try { dgExport.RenderControl(htmlWriter); } catch (Exception e) { Log4Net.LogWrite("err", e.Message); } curContext.Response.Write(strWriter.ToString()); curContext.Response.End(); } }
/// <summary> /// 添加Meta标签 /// </summary> /// <param name="page">页面</param> /// <param name="name">Meta名字</param> /// <param name="content">Meta内容</param> public void AddMeta(System.Web.UI.Page page, string name, string content) { HtmlMeta meta = new HtmlMeta(); meta.Name = name; meta.Content = content; page.Header.Controls.Add(meta); }
private static void AppThreadException(object source, System.Threading.ThreadExceptionEventArgs e) { string errorMsg = string.Format("未处理异常: \n{0}\n", e.Exception.Message + " 详细:\n" + e.Exception); MyLog.WriteLog(e.Exception); MessageBox.Show("\n 发生系统异常!\t\t\n", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); }
public ActionResult Upload() { ArrayList list = new ArrayList(); try { StringBuilder info = new StringBuilder(); foreach (string tfile in Request.Files) { HttpPostedFileBase postFile = Request.Files[tfile];//get post file if (postFile.ContentLength == 0) continue; string serverPath = Server.MapPath("~").Replace("Api", "").Replace("api", ""); string folder = "Uploads\\" + DateTime.Today.ToString("yyyy-MM-dd") + "\\"; string guid = DateTime.Now.ToString("hh-mm-ss-") + new Random().Next(1000).ToString() + Guid.NewGuid().ToString().Substring(0, 4); string file_name = guid + postFile.FileName.Substring(postFile.FileName.LastIndexOf(".")); string samll_file_name = guid + "_450_300" + postFile.FileName.Substring(postFile.FileName.LastIndexOf(".")); string realPath = (serverPath +"/"+ folder).Replace("\\", "/"); string returnPath = ("/" + folder + file_name).Replace("\\", "/"); string samllPath = ("/" + folder + samll_file_name).Replace("\\", "/"); if (!Directory.Exists(realPath)) { Directory.CreateDirectory(realPath); } string ext=postFile.FileName.Substring(postFile.FileName.LastIndexOf(".")); string sPath = realPath + file_name; string dPath = realPath + guid + "_450_300" + ext ; string smallPath = realPath + guid + "_160_120" + ext; postFile.SaveAs(realPath + file_name); file file = new Entities.file(); file.file_path = returnPath; file.file_name = file_name; file.create_time = DateTime.Now; file = Uof.IfileService.AddEntity(file); var result = new { file_path = returnPath, small_path = samllPath, id = file.id, file_name = file.file_name }; ImageHelper.GetPicThumbnailWidth(sPath,smallPath,120,160,100); bool isZipSuccess = ImageHelper.GetPicThumbnailWidth(sPath, dPath, 300, 650, 100); if (!isZipSuccess) { LogHelper.LogError("图片压缩失败"); } list.Add(result); //return Json(result, JsonRequestBehavior.AllowGet); } return Json(list, JsonRequestBehavior.AllowGet); } catch (Exception ex) { LogHelper.LogError(ex.Message,ex); } return Json(list, JsonRequestBehavior.AllowGet); }
private static bool CertificateValidationCallBack( object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors) { return true; }
public void DisposeFrame(System.Guid guidOfFrameToDispose) { var f = this.RetrieveFrame(guidOfFrameToDispose); if (f != null) { f.Dispose(); } }
public CustomerIdentity(System.Web.Security.FormsAuthenticationTicket ticket) { Name = ticket.Name; Expires = ticket.Expiration; // Populate this object with the properties DeserializeProperties(ticket.UserData); }
private void Page_Load(object sender, System.EventArgs e) { }