.net 日期总结,用于业务时间查询

     //今天是这周的第几天,是个英文星期,可以转换成intstring a  = DateTime.Now.DayOfWeek.ToString();//今天//MessageBox.Show(Convert.ToInt32(DateTime.Now.DayOfWeek) + "");昨天MessageBox.Show(DateTime.Now.AddDays(-1).ToString());//星期一,相对当前时间MessageBox.Show(DateTime.Now.AddDays(-Convert.ToInt32(DateTime.Now.DayOfWeek) + 1).ToString());//星期日,相对当前时间MessageBox.Show(DateTime.Now.AddDays(-Convert.ToInt32(DateTime.Now.DayOfWeek) + 7).ToString());//今天0点MessageBox.Show("Test" + DateTime.Today);/*个人感觉now , today 作用及相似, 但是now 是现在,today是从今天0点开始,它们用法相似。*///本周星期一0点到星期天0点 MessageBox.Show(-Convert.ToInt32(DateTime.Today.DayOfWeek) + "");  -5 得到上个星期天MessageBox.Show(DateTime.Today.AddDays(-Convert.ToInt32(DateTime.Today.DayOfWeek) + 1).ToString());MessageBox.Show(DateTime.Today.AddDays(-Convert.ToInt32(DateTime.Now.DayOfWeek) + 8).ToString());//本月第一天string fristDayOfMonth = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + 1;//本月最后一天string lastDayOfMonth = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);DateTime dt;bool b = DateTime.TryParse(lastDayOfMonth, out dt);if (b) //true,可以判断这个字符串是不是日期MessageBox.Show("Test");//各种加法系列。点一个一个的... MessageBox.Show("Test" + DateTime.Today.DayOfWeek);// FridayDateTime dt = DateTime.Today;dt.AddDays(1);dt.AddHours(1.2);dt.AddMinutes(2.0);dt.AddSeconds(10);dt.AddYears(1);//MessageBox.Show("Test" + dt);日期部分MessageBox.Show(dt.ToLongDateString());//时间部分MessageBox.Show(dt.ToLongTimeString());//本季度第一个月DateTime firstOfQuater = dt.AddMonths(-(dt.Month - 1) % 3).AddDays(- dt.Day + 1);// 10 月 1 号//本季度最后一月DateTime lastOfQuater = firstOfQuater.AddMonths(3).AddDays(-1);DateTime dt1 = Convert.ToDateTime("2019-11-08 20:20");//现在和dt1两个日期 相减 得到 一个时间间隔TimeSpan span = DateTime.Now - dt1;//现在和 dt1 查了具体的几个小时 , 保留了一位小数MessageBox.Show(span.TotalHours.ToString("f1") + "");//相差了几小时,几分钟MessageBox.Show(span.Hours + "小时" + span.Minutes + "分钟");//基于以上可实用的日期总结,其它的随便玩玩。针对季度的 , 卡 -0 , -1 , -2 月,这样好像便于理解为什么有个减一了。

PS:
快一个月,我没写博客了,多在忙于写项目,一个小小的餐饮管理项目,居然花了我很多时间。。。而且戏剧性的是
到今天项目答辩时,还出了bug。。。关于退菜,居然还可以负数。。。但是项目完成了,我太感觉还好了,没有判断,其数量不可以退到负数,
因为以前退菜是一个一个退的,就不至于,有负数,listview中就不会显示。

这个项目是 多层结构 +.net(ado.net) + sqlserver技术,便可完成。对于界面这个东西,可以千奇百怪,花里胡哨。
.net 的学习,到此可能就这样了。。。

自己写的代码,让自己运行看,永远找不到最精确的效果,要别人帮忙来看的你的项目,来测试。发现bug ,并解决。

Point 1 What I Learn ?
多层结构的 熟悉使用 ,少许的几个控件 , 时间日期的把控 , 还是 基于面向对象的封装。。。
继承多态,并未使用。
字符串操作相当是复习了一部分。。。
动态控件的使用 , 并生成对应的事件 。还有tag 这个重要的东西,可以绑定对应的对象,让你少写一点代码。
内存操作,利用集合判断 某个东西是否合法;点菜,利用一个暂停的集合,点菜,退菜

lambda表达式。在dgv或者listview 得到一个对象。 λ 。

Products t = (dgv.DataSource as List<Products>).find(pt => pt.productid = dgv.SelectedRows[0].Cells[0].Value.ToString());

Point 2
其它控件的 取值,要合法,做判断。这种判断是必须必须的否则程序数据出错。
增删改,匹配数据库。

Point 3
在查一个数据表时,需要统计某个列的数量,但是这会用到分组查询,没有正确的结果,
但是,可以用子查询,把要查的这个数据的 单独查,再把这个sql语句看成是一个表。

select pt.PTName,p.ProductName,back,cd.CDDate from (select distinct cd.prodcutid, count(CDType) as 'back' from ConsumerDetails cd inner join products pon cd.prodcutid = p.productidgroup by cd.prodcutid,cd.CDDate) t inner join Products pon t.ProdcutID = p.ProductID inner join ProductType pton p.PTID = pt.PTID inner join ConsumerDetails cd on cd.ProdcutID = p.ProductID inner join  ConsumerBill cbon cb.CBID = cd.CBIDwhere cd.CDType = 1 and 1=1

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/421182.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

1042. Shuffling Machine (20)

1042. Shuffling Machine (20) 时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueShuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid &qu…

leetcode 73 矩阵置零 C++ 两种解法

leetcode 73 两种解法~~&#xff0c;没有一个是我想出来的&#xff0c;哈哈~~ one class Solution { public:void setZeroes(vector<vector<int>>& matrix) {int mmatrix.size(),nmatrix[0].size();bool colfalse,rowfalse;for(int i0;i!m;i){if(!matrix[i][0…

JS第一课

<!DOCTYPE html> <html><head><meta charset"utf-8" /><title></title></head><body><script>///*1,它可以做什么。a, 动态改变页面的内容和页面外观b,验证表单数据&#xff0c;各大网站的注册验证功能可以通…

排序二叉树

排序二叉树 二叉树&#xff1a;作为基本数据结构的一种&#xff0c;是红黑树&#xff0c;B树等树形结构的基础。而排序二叉树是按照二叉树的结构来组织的。在本文中采用链表结构来创建二叉树。排序二叉树的    基本原理&#xff1a; 排序二叉树是将归并排序的基本思想构建二…

1020. Tree Traversals (25)

1020. Tree Traversals (25) 时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueSuppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to out…

leetcode 387 C++数组做法

leetcode 387 C数组做法 class Solution { public:int firstUniqChar(string s) {int ns.length();if(n0) return -1;int table[26]{0};for(int i0;i!n;i){table[s[i]-a];}for(int i0;i!n;i){if(table[s[i]-a]1)return i;}return -1;} };END

获取Class对象方式

在java中&#xff0c;每个class都有一个相应的Class对象&#xff0c;当编写好一个类&#xff0c;编译完成后&#xff0c;在生成的.class文件中&#xff0c;就产生一个Class对象&#xff0c;用来表示这个类的类型信息。获得Class实例的三种方式&#xff1a; 1). 利用对象调用get…

前端学习(1002):简洁版滑动下拉菜单问题解决

快速滑动 不停切换 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>Document</title><scrip…

js bom and dom

以下的代码只是一些小的例子。我画了一张图来总结js大的结构 <!DOCTYPE html> <html><head><meta charset"UTF-8"><title></title><script>//Point 1 delayer and timer (BOM browser Object Model)var delayer;var tim…

leetcode 383 赎金信 C++

自己想的&#xff0c;一个思路两个解法&#xff0c;从字符串中的第一个唯一字符的思路搬过来的 one class Solution { public:bool canConstruct(string ransomNote, string magazine) {int table2[26]{0};for(int i0;i!magazine.length();i){table2[magazine[i]-a];}for(int …

Win32下 Qt与Lua交互使用(二):在Lua脚本中使用Qt类

话接上篇。成功配置好QtLuatoLua后&#xff0c;我们可以实现在Lua脚本中使用各个Qt的类。直接看代码吧。 #include "include/lua.hpp" #include <QWidget> #include <QApplication> #include <QFile> #include <QDebug>static int tolua_new…

1099. Build A Binary Search Tree (30)

1099. Build A Binary Search Tree (30) 时间限制100 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueA Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains o…

mysql列属性auto(mysql笔记四)

常见的的是一个字段不为null存在默认值 没值得时候才去找默认值&#xff0c;可以插入一个null到 可以为null的行里 主键&#xff1a;可以唯一标识某条记录的字段或者字段的集合 主键设置 主键不可为null,声明时自动设置为not null 字段上设置 字段名 primary key定义完字段后 …

详解html结构之间的各个关系,层级关系(以列表为例)

<!DOCTYPE html> <html><head><meta charset"UTF-8"><title>层级关系查找元素</title></head><body><div id "div">hello<ul id ""><li>li1</li><li>li2</…

leetcode 242 有效的字母异位词 C++

和赎金信的思路一样 我想我本科时光是找不到女朋友了&#xff0c;哪怕是一个异性的好朋友也不会有了&#xff0c;男女比例4&#xff1a;1&#xff0c;哼 class Solution { public:bool isAnagram(string s, string t) {int table2[26]{0};for(char a:t){table2[a-a];}for(char…

1058. A+B in Hogwarts (20)

1058. AB in Hogwarts (20) 时间限制50 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueIf you are a fan of Harry Potter, you would know the world of magic has its own currency system -- as Hagrid explained it to Harry, "Seventeen silve…

jquery post 同步异步总结

最近在测试,发现有些效果不对,最后发现是post的执行顺序问题,所以研究了下,写了以下总结 1.post被请求多次,解决方法: 连接加入随机数 rand""Math.random() $.post("/Control/webControl.ashx?rand "Math.random(), { Method: "LoginIn", Parem…

js对html节点的操作

<!DOCTYPE html> <html><head><meta charset"UTF-8"><title></title><style></style><script>function copy(){//克隆节点//1&#xff0c;得到要克隆的divvar div document.body.firstElementChild;//2,复制…

leetcode 141 环形链表 C++

两种方法一个空间O(n)&#xff0c;另一个O(1)&#xff0c;时间都是O(n)。 one class Solution { public:bool hasCycle(ListNode *head) {unordered_set<ListNode*>set;while(head){if(set.count(head))return true;set.insert(head);headhead->next;}return false;}…

1056. Mice and Rice (25)

1056. Mice and Rice (25) 时间限制100 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueMice and Rice is the name of a programming contest in which each programmer must write a piece of code to control the movements of a mouse in a given map…