private void timer4_Tick(object sender, EventArgs e) { try { string nowTime = DateTime.Now.ToString(); decimal volumeInterval = 0; //体积差值 decimal nowVolume = Convert.ToDecimal(this.labelvolumetext.Text); //现在的体积 volumeInterval = nowVolume - lastVolume; //体积差计算 lastVolume = nowVolume; if (volumeInterval != 0) { using (EVCSEntities1 vodb = new EVCSEntities1()) { VolumeDetail volumeDetail = new VolumeDetail(); volumeDetail.date = Convert.ToDateTime(nowTime); volumeDetail.volume = volumeInterval; vodb.VolumeDetail.Add(volumeDetail); vodb.SaveChanges(); } } } catch (Exception) { } }
private void Calc_Load(object sender, EventArgs e) { NewMain.Nform.logClass = new LogClass(); // TODO: 这行代码将数据加载到表“eVCSDataSet.SerialNumberRecords”中。您可以根据需要移动或删除它。 this.serialNumberRecordsTableAdapter.Fill(this.eVCSDataSet.SerialNumberRecords); // TODO: 这行代码将数据加载到表“eVCSDataSet.SerialNumberRecords”中。您可以根据需要移动或删除它。 //this.serialNumberRecordsTableAdapter.Fill(this.eVCSDataSet.SerialNumberRecords); // TODO: 这行代码将数据加载到表“eVCSDataSet.CarInfos”中。您可以根据需要移动或删除它。 this.carInfosTableAdapter.Fill(this.eVCSDataSet.CarInfos); SNID = Convert.ToInt32(comboBoxCarInfoLists.SelectedValue); // 货运单号 主键 using (EVCSEntities1 db = new EVCSEntities1()) { var carinfo = db.CarInfos.Where(f => f.ID == SNID).First(); var info = db.SerialNumberRecords.Where(f => f.CarNO == carinfo.ID).First(); NewMain.Nform.cloud.volumeCalc.carSN = info.SN; NewMain.Nform.cloud.volumeCalc.carName = carinfo.CarNO; NewMain.Nform.cloud.volumeCalc.carNo = carinfo.ID; NewMain.Nform.cloud.volumeCalc.carVolume = carinfo.Volume; labelVolume.Text = NewMain.Nform.cloud.volumeCalc.carVolume.ToString(); labelCarNumber.Text = NewMain.Nform.cloud.volumeCalc.carSN; } if (NewMain.Nform.time) { buttonOperate_Click(form1, e); } NewMain.Nform.logClass.write("自动计算事件触发"); }
private void button1_Click(object sender, EventArgs e) { int CarNO = Convert.ToInt32(comboBoxCarNO.SelectedValue); string sn = labelSN.Text; string createUser = textBoxCreateUser.Text; using (EVCSEntities1 db = new EVCSEntities1()) { db.SerialNumberRecords.Add(new SerialNumberRecords() { CarNO = CarNO, SN = sn, CreateUser = createUser, Datetime = DateTime.Now }); db.SaveChanges(); } MessageBox.Show("添加单号成功!"); this.Close(); }
private void buttonEnter_Click(object sender, EventArgs e) { string carno = textBoxCarNO.Text; string contract = textBoxContract.Text; string tel = textBoxTel.Text; string volume = textBoxVolume.Text; string remark = textBoxRemark.Text; if (String.IsNullOrEmpty(carno)) { MessageBox.Show("车牌号不能为空!"); return; } if (String.IsNullOrEmpty(contract)) { MessageBox.Show("请填写联系人!"); return; } if (String.IsNullOrEmpty(tel)) { MessageBox.Show("请填写联系方式!"); return; } if (String.IsNullOrEmpty(volume)) { MessageBox.Show("请填写车辆体积!"); return; } using (EVCSEntities1 db = new EVCSEntities1()) { CarInfos info = new CarInfos(); info.CarNO = carno; info.Contact = contract; info.Tel = tel; info.Volume = Convert.ToDecimal(volume); info.Remark = remark; db.CarInfos.Add(info); db.SaveChanges(); MessageBox.Show("录入成功!"); this.Close(); } }
/// <summary> /// 生成流水号 /// </summary> /// <param name="Prefix">前缀</param> /// <param name="DateFormat">时间格式</param> /// <param name="Init">初始值</param> /// <param name="Increment">自增量</param> /// <param name="length">流水号长度</param> /// <returns></returns> public string Generate(string Prefix, string DateFormat, int Init, int Increment, int Length) { string date = DateTime.Now.ToString(DateFormat); using (EVCSEntities1 db = new EVCSEntities1()) { var SerialNumber = db.SerialNumber.Where(f => f.Prefix == Prefix).Where(f => f.DateFormat == DateFormat).Where(f => f.Init == Init).Where(f => f.Increment == Increment).Where(f => f.Length == Length); if (SerialNumber.Count() == 0) { db.SerialNumber.Add(new SerialNumber() { Prefix = Prefix, DateFormat = DateFormat, Init = Init, Increment = Increment, Length = Length, CurrentValue = Init }); db.SaveChanges(); } else { SerialNumber.First().CurrentValue += Increment; db.SaveChanges(); } var CurrentValue = db.SerialNumber.Where(f => f.Prefix == Prefix).Where(f => f.DateFormat == DateFormat).Where(f => f.Init == Init).Where(f => f.Increment == Increment).Where(f => f.Length == Length).FirstOrDefault().CurrentValue; return(Prefix + date + CurrentValue.ToString().PadLeft(Length, '0')); } }
List <HadGenerateDate> HadDatas = new List <HadGenerateDate>(); //已经生成过的数据 不在重新生成 而是从这个列表中读取 //private void dateTimePicker1_ValueChanged(object sender, EventArgs e) //{ // List<int> x = new List<int>() { }; //月数 // List<decimal?> y = new List<decimal?>() { }; //每月体积 // try // { // //DateTime selected = DateTime.Now; // DateTime selected = dateTimePickerAnalysisDayly.Value; // int year = selected.Year; // int month = selected.Month; // if (GYear == year && GMonth == month) // { // return; // } // var hadDatas = HadDatas.Where(f => f.year == year).Where(f => f.month == month); // int hadDatasCount = hadDatas.Count(); // if (hadDatasCount>0) //已经有了数据 // { // x = hadDatas.First().x; // y = hadDatas.First().y; // } // else //没有生成过数据 重新生成 // { // GYear = year; //更新全局变量 // GMonth = month; //更新全局变量 // //int month1; // //if (month == 12) // //{ // // year++; // // month1 = 0; // //} // //else // //{ // // month1 = month; // //} // using (EVCSEntities1 db = new EVCSEntities1()) // { // //循环计算每一天的体体积数 // for (int i = 1; i <= Month_Days[month - 1]; i++) // { // x.Add(i); // string dayStart = year + "-" + month + "-" + i; // string dayEnd = ""; // //最后一天需要特殊处理 // if (i == Month_Days[month - 1]) // { // month++; // dayEnd = year + "-" + month + "-01"; // } // else // { // dayEnd = year + "-" + month + "-" + (i + 1); // } // DateTime DdayStart = Convert.ToDateTime(dayStart); // DateTime DadyEnd = Convert.ToDateTime(dayEnd); // decimal? totalVolume = db.Records.Where(f => f.CreateDate >= DdayStart).Where(f => f.CreateDate < DadyEnd).Sum(f => f.Volume); // y.Add(totalVolume == null ? 0 : totalVolume); // } // } // //存入到已有的列表中 // HadDatas.Add(new HadGenerateDate() {year=GYear,month=GMonth,x=x,y=y }); // } // chartDays.Series[0].Points.DataBindXY(x, y); // } // catch (Exception) // { // } //} private void dateTimePicker1_ValueChanged(object sender, EventArgs e) { List <int> x = new List <int>() { }; //月数 List <decimal?> y = new List <decimal?>() { }; //每月体积 try { //DateTime selected = DateTime.Now; DateTime selected = dateTimePickerAnalysisDayly.Value; int year = selected.Year; int month = selected.Month; if (GYear == year && GMonth == month) { return; } var hadDatas = HadDatas.Where(f => f.year == year).Where(f => f.month == month); int hadDatasCount = hadDatas.Count(); if (hadDatasCount > 0) //已经有了数据 { x = hadDatas.First().x; y = hadDatas.First().y; } else //没有生成过数据 重新生成 { GYear = year; //更新全局变量 GMonth = month; //更新全局变量 //int month1; //if (month == 12) //{ // year++; // month1 = 0; //} //else //{ // month1 = month; //} using (EVCSEntities1 db = new EVCSEntities1()) { //循环计算每一天的体体积数 //for (int i = 1; i <= Month_Days[month - 1]; i++) //{ // x.Add(i); // string dayStart = year + "-" + month + "-" + i; // string dayEnd = ""; // //最后一天需要特殊处理 // if (i == Month_Days[month - 1]) // { // month++; // dayEnd = year + "-" + month + "-01"; // } // else // { // dayEnd = year + "-" + month + "-" + (i + 1); // } // DateTime DdayStart = Convert.ToDateTime(dayStart); // DateTime DadyEnd = Convert.ToDateTime(dayEnd); // decimal? totalVolume = db.Records.Where(f => f.CreateDate >= DdayStart).Where(f => f.CreateDate < DadyEnd).Sum(f => f.Volume); // y.Add(totalVolume == null ? 0 : totalVolume); //} var datas = db.V_Records_Dayly_Volume.Where(f => f.CreateYear == year && f.CreateMonth == month); foreach (var item in datas) { x.Add((int)item.CreateDay); y.Add(item.totalVolume); } for (int i = 1; i <= Month_Days[month - 1]; i++) { if (!x.Contains(i)) { x.Add(i); y.Add(0); } } } //存入到已有的列表中 HadDatas.Add(new HadGenerateDate() { year = GYear, month = GMonth, x = x, y = y }); } chartDays.Series[0].Points.DataBindXY(x, y); } catch (Exception) { } }
/// <summary> /// 定时像体积计算程序获得体积以及个数等信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void timer1_Tick_1(object sender, EventArgs e) { try { //TODO GET Current Volumn //体积数据获取 File.Delete(Filename2);//体积标志flag更新 if (!File.Exists(Filename2)) { Ff2++; // Create a file to write to. File.WriteAllText(Filename2, "" + Ff2); } if (File.Exists(Filename3))//体积数据获取 { // Create a file to write to. NewMain.Nform.cloud.receivevolume(Filename3); } //计数信号传输 if (File.Exists(CountFilename))//计数数据获取 { // Create a file to write to. NewMain.Nform.cloud.volumeCalc.count = File.ReadAllText(CountFilename); } if (File.Exists(Fgood) && File.Exists(Fgood2) && File.Exists(Fgood3))//计数数据获取 { // Create a file to write to. PL = Convert.ToDecimal(File.ReadAllText(Fgood)); PH = Convert.ToDecimal(File.ReadAllText(Fgood2)); PW = Convert.ToDecimal(File.ReadAllText(Fgood3)); PV = PL * PH * PW; } if (PP != PW) { using (EVCSEntities1 db = new EVCSEntities1()) { string time = DateTime.Now.ToString(); Count info = new Count(); info.length = PL; info.wide = PW; info.hight = PH; info.volume = PV; info.time = Convert.ToDateTime(time); db.Count.Add(info); db.SaveChanges(); PP = PW; } } NewMain.Nform.cloud.volumeCalc.Loadingrate = (int)(NewMain.Nform.cloud.Volume * 100 / NewMain.Nform.cloud.volumeCalc.carVolume); progressBarPercent.Value = NewMain.Nform.cloud.volumeCalc.Loadingrate; progressBarvalue = progressBarPercent.Value; labelCurrentPercent.Text = progressBarPercent.Value.ToString(); labelcount.Text = NewMain.Nform.cloud.volumeCalc.count; labelvolumetext.Text = Convert.ToString(NewMain.Nform.cloud.Volume); if (NewMain.Nform.cloud.cloudnet.checksermessflag() == 2) { NewMain.Nform.cloud.cloudnet.sendpackage(NewMain.Nform.cloud.cloudnet.checksermessflag(), NewMain.Nform.cloud.volumeCalc); } } catch (Exception) { //if(progressBarPercent.Value >= 100) //{ // datasave(); // NewMain.Nform.test.volumeCalc.Begintime = DateTime.Now.ToString(); // Process pr = new Process();//声明一个进程类对象 // pr.StartInfo.FileName = "体积计算 v0.07.exe"; // pr.Start(); //} } }
/// <summary> /// 数据保存 /// 先将程序关闭文件删除后将数据上传至数据库中 /// </summary> /// <returns></returns> bool datasave() { Process[] pProcess; pProcess = Process.GetProcesses(); for (int i = 1; i <= pProcess.Length - 1; i++) { if (pProcess[i].ProcessName == "体积计算 " + NewMain.Nform.cloud.Volumev) //任务管理器应用程序的名 { pProcess[i].Kill(); NewMain.Nform.logClass.write("杀死体积计算 " + NewMain.Nform.cloud.Volumev + "程序"); Ff2 = 0; File.WriteAllText(Filename2, "" + Ff2); File.Delete(Filename3); File.Delete(CountFilename); File.Delete(Fgood); File.Delete(Fgood2); File.Delete(Fgood3); } } using (EVCSEntities1 db = new EVCSEntities1()) { Records info = new Records(); info.SN = NewMain.Nform.cloud.volumeCalc.carSN; info.CarNO = NewMain.Nform.cloud.volumeCalc.carNo; info.CreateDate = DateTime.Now; info.StartDate = Convert.ToDateTime(NewMain.Nform.cloud.volumeCalc.Begintime); info.EndDate = Convert.ToDateTime(NewMain.Nform.cloud.volumeCalc.EndTime); info.Volume = Convert.ToDecimal(NewMain.Nform.cloud.Volume); info.Loading_rate = progressBarPercent.Value; info.Count = Convert.ToInt32(NewMain.Nform.cloud.volumeCalc.count); if (NewMain.Nform.timeptr != 0) { switch (NewMain.Nform.timeptr) { case 1: info.Remark = "一频(昨日" + NewMain.Nform.cloud.gethour(0, true, true) + ":" + NewMain.Nform.cloud.getminute(0, true, true) + "-" + NewMain.Nform.cloud.gethour(0, false, true) + ":" + NewMain.Nform.cloud.getminute(0, false, true) + ")"; break; case 2: info.Remark = "二频(" + NewMain.Nform.cloud.gethour(1, true, true) + ":" + NewMain.Nform.cloud.getminute(1, true, true) + " - " + NewMain.Nform.cloud.gethour(1, false, true) + ":" + NewMain.Nform.cloud.getminute(1, false, true) + ")"; break; case 3: info.Remark = "三频(" + NewMain.Nform.cloud.gethour(2, true, true) + ":" + NewMain.Nform.cloud.getminute(2, true, true) + "-" + NewMain.Nform.cloud.gethour(2, false, true) + ":" + NewMain.Nform.cloud.getminute(2, false, true) + ")"; break; } } db.Records.Add(info); db.SaveChanges(); } //string number; //string own; //using (EVCSEntities1 db = new EVCSEntities1()) //{ // var carman = db.CarInfos.Where(f => f.ID == carid).First(); // number = carman.Tel; // own = carman.Contact; //} // File.WriteAllText("test.txt", "time:" + NewMain.Nform.test.volumeCalc.Endtime + " Volume: " + Addvolume + " Count :" + AddCount + " Contact:"+own+" Tel:"+ number); //Process pr = new Process();//声明一个进程类对象 //pr.StartInfo.FileName = "chat.exe"; //pr.Start(); //this.Close(); NewMain.Nform.cloud.receivevolume(); NewMain.Nform.cloud.volumeCalc.count = "0"; return(true); }