1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
| DateTime dt = DateTime.Now.AddMonths(-3); var dayOfWeek = dt.DayOfWeek; int dayOfYear = dt.DayOfYear;
TimeHelper timeHelper = new TimeHelper(); string dtFormat1 = timeHelper.GetFormatDate(dt, '-'); string timeFormat = timeHelper.GetFormatTime(dt, ':');
int second = 1502; int minite = TimeHelper.SecondToMinute(second);
int lastDay = TimeHelper.GetMonthLastDate(2088, 5);
DateTime dt1 = new DateTime(2028, 2, 3); DateTime dt2 = new DateTime(2032, 12, 9); string dateDiff = TimeHelper.DateDiff(dt1, dt2); TimeSpan timeSpan = TimeHelper.DateDiff2(dt1, dt2);
string formatDate = TimeHelper.FormatDate(dt1, "0"); DateTime randomDate = TimeHelper.GetRandomTime(dt1, dt2);
BaseRandom baseRandom = new BaseRandom(); int randomInt1 = baseRandom.GetRandom(); int randomInt2 = baseRandom.GetRandom(50000, 999999); string randomStr = baseRandom.GetRandomString(13);
Random random = new Random(); double randomDouble = random.NextDouble();
ViewBag.randomInt1 = randomInt1; ViewBag.randomInt2 = randomInt2; ViewBag.randomStr = randomStr; ViewBag.randomDouble = randomDouble;
private void FileOperator (){
string existFile1 = Server.MapPath("/dir/test2.txt"); string existFile2 = System.AppDomain.CurrentDomain.BaseDirectory + "/dir/test3.txt";
DirFile.ExistsFile(existFile1); DirFile.ExistsFile(existFile2);
string fileExtension = DirFile.GetExtension(existFile1); string fileExtension2 = DirFile.GetExtension("./dir/text3.txt"); ViewBag.fileExtension = fileExtension; ViewBag.fileExtension2 = fileExtension2;
}
private void GenerateQrcode() { QRcode qrCode = new QRcode(); var userQrCode = qrCode.Create("https://cn.ubuntu.com/", 4, "/Content/Images/QrCode/"); ViewBag.UserQrCode = userQrCode;
var qrCodePath = Request.MapPath(userQrCode); var logoPath = Request.MapPath("~/Content/Images/ubuntu.png"); System.Drawing.Image image = System.Drawing.Image.FromFile(qrCodePath); System.Drawing.Image combinImage = QRcode.CombinImage(image, logoPath);
string filename = "~" + "/Content/Images/QrCode/" + Guid.NewGuid() + ".jpg"; combinImage.Save(Request.MapPath(filename)); var fileCombinUrl = filename.Replace("~", ""); ViewBag.fileCombinUrl = fileCombinUrl; }
public void ExportTemplate() { #region 生成测试DataTable数据 正式环境 从数据库中读取,在转换为DataTable格式导出 DataTable dataTable = new DataTable(); dataTable.Columns.Add("item_no", typeof(string)); dataTable.Columns.Add("barcode", typeof(string)); dataTable.Columns.Add("unit", typeof(string)); dataTable.Columns.Add("ware_house", typeof(string)); dataTable.Columns.Add("quantity", typeof(int)); dataTable.Columns.Add("price", typeof(decimal)); dataTable.Columns.Add("discount_rate", typeof(decimal)); dataTable.Columns.Add("tax_rate", typeof(decimal)); dataTable.Columns.Add("sn", typeof(string)); dataTable.Columns.Add("manufacture_date", typeof(DateTime)); dataTable.Columns.Add("remark", typeof(string));
Random r = new Random(); BaseRandom baseRandom = new BaseRandom(); for (int i = 0; i < 1000; i++) { DataRow row = dataTable.NewRow();
row["item_no"] = baseRandom.GetRandomString(13); row["barcode"] = baseRandom.GetRandom(1000000, 9000000).ToString(); row["unit"] = r.Next(2) % 2 == 0 ? "千克" : "克"; row["ware_house"] = baseRandom.GetRandomString(6); row["quantity"] = r.Next(5000).ToString(); row["discount_rate"] = 0.22.ToString(); row["tax_rate"] = 0.35.ToString(); row["sn"] = baseRandom.GetRandomString(13); row["manufacture_date"] = TimeHelper.GetRandomTime(DateTime.Now.AddYears(-10), DateTime.Now.AddYears(10)).ToString(); row["remark"] = baseRandom.GetRandomString(23);
dataTable.Rows.Add(row); }
Dictionary<string, string> dir = new Dictionary<string, string>(); dir.Add("item_no", "存货编码"); dir.Add("barcode", "条码"); dir.Add("unit", "计量单位"); dir.Add("ware_house", "仓库"); dir.Add("quantity", "数量"); dir.Add("price", "单价"); dir.Add("discount_rate", "折扣率%"); dir.Add("tax_rate", "税率"); dir.Add("sn", "SN码"); dir.Add("manufacture_date", "生产日期"); dir.Add("remark", "备注"); #endregion
string fileName = "导入模板-进货单" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")+".xls"; NPOIHelper.ExportByWeb(dataTable, "进货单", fileName, dir);
}
|