C# 杂活

1 下拉框

List<Model.Sys.AccountModel> AcModel = BLL.Sys.AccountBLL.Instance.GetModelList("RoleID=3"); 
//实例化
// SelectList ServiceName = new SelectList(new List<Model.Sys.AccountModel>(), "ID", "RealName");

 //下拉框
SelectList ServiceName = new SelectList(AcModel, "ID", "RealName",RealName);
ViewData["ServiceName"] = ServiceName;

//页面显示
@Html.DropDownList("ServiceUserID", (SelectList)ViewData["ServiceName"], "全部")
<label>模糊筛选:</label>
        <input data-upload="ServiceName" name="ServiceName" value="@ViewBag.bt" list="listdw2" style="width: 300px" type="text" />
            <datalist id="listdw2">
                @foreach (var dd in (SelectList)ViewData["ServiceName"])
                {
                    <option value="@dd.Text" selected="@dd.Selected"></option>
                }
            </datalist>

List<SelectListItem> lists = new List<SelectListItem>();
lists.Add(new SelectListItem { Text = "未到期", Value ="0" });
lists.Add(new SelectListItem { Text = "到期已还", Value = "1" });
lists.Add(new SelectListItem { Text = "延期已还", Value = "2" });
lists.Add(new SelectListItem { Text = "未到期", Value = "3" });

 //for (int i = 1; i <= 12; i++)
 //{
 //    lists.Add(new SelectListItem { Text = i + "月", Value = i.ToString() });
 //}
 ViewBag.lists = lists;

//页面显示            
@Html.DropDownList("ServiceUserID", (List<SelectListItem>)ViewBag.lists)

MVC 下拉框

 2 时间格式

DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss:ffff dddd"); // => 2016/05/09 13:09:55:2350 星期一

DateTime  CurTime = DateTime.Now;
          CurTime.ToString("f");  //2017年12月5日 9:30
          CurTime.ToString("y");  //2017年12月
          CurTime.ToString("m");  //12月5日
          CurTime.ToString("d");  //2017/12/5
          CurTime.ToString("t");  //9:30
          CurTime.ToShortDateString();//2017/12/5
          CurTime.ToShortTimeString();//9:43
系统时间表达
DateTime CurTime = new DateTime();
            Console.WriteLine(CurTime.ToString()); // 0001/1/1 0:00:00
            Console.WriteLine(DateTime.Now.ToString()); //2017/12/5 9:39:29
            Console.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss:ffff dddd")); //2017/12/05 09:41:08:4617 星期二

            DateTime.Now.Date.ToShortDateString();  //今天   //2017/12/5
            DateTime.Now.AddDays(1).ToShortDateString();//明天 的   //2017/12/6

            //一周
            DateTime.Now.AddDays(Convert.ToDouble((0 - Convert.ToInt16(DateTime.Now.DayOfWeek)))).ToShortDateString();  //2017/12/3
            DateTime.Now.AddDays(Convert.ToDouble((6 - Convert.ToInt16(DateTime.Now.DayOfWeek)))).ToShortDateString();  //2017/12/9

            //
          Convert.ToDateTime(DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + "1" + " " + "00:00:00");//2017/12/1 0:00:00
          DateTime times = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); //2017/12/1 0:00:00
          Convert.ToDateTime(DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + "1" + " " + "00:00:00").AddMonths(1).AddDays(-1).ToString() ; //最后一天 2017/12/31 0:00:00
常用时间转换
//一天的时间段
            DateTime dtTarget = DateTime.Now;
            DateTime FirstSecond = dtTarget.Date;
            DateTime LastSecond = dtTarget.Date.AddDays(+0.99);


            DateTime FirstDay = dtTarget.AddDays(-dtTarget.Day + 1); //每个月第一天
            DateTime LastDay = dtTarget.AddMonths(1).AddDays(-dtTarget.AddMonths(1).Day).Date.AddDays(+0.99);//每个月最后一天
另一种时间变换

 

DateTime NowTime = DateTime.Now;
            Console.WriteLine(NowTime.ToShortDateString());

            //本月第一天和最后一天
            DateTime M1 = new DateTime(NowTime.Year,NowTime.Month,1);
            DateTime M2 = M1.AddMonths(1);

            //本季度第一天和最后一天
            DateTime J1 = M1.AddMonths(0 - (DateTime.Now.Month - 1) % 3);
            DateTime J2 = M1.AddMonths(3 - (DateTime.Now.Month - 1) % 3);

            //本年度第一天和最后一天
            DateTime Y1 = M2.AddMonths(-M1.Month);
            DateTime Y2 = M2.AddMonths(-M1.Month).AddYears(1);

 

 

 

 

3.包含

//判断text 里面是否包含jpg
public static string PicsString = "jpg,png,igf,bmp,tiff";

        public static bool CheckPics(string text)
        {
            string[] strList = PicsString.Split(',');
            foreach (var item in strList)
            {
                if (text.Contains(item))
                {
                    return false;
                }
            }
            return true;
        }

判断text 里面是否包含jpg

 

posted @ 2017-11-22 22:21  革凡  阅读(191)  评论(0编辑  收藏  举报