예제 #1
0
 private void InfoBind()
 {
     using (IFMPDBContext db = new IFMPDBContext())
     {
         IntelligentDevice IntelligentDevice = db.IntelligentDevice.FirstOrDefault(t => t.ID == DeviceID);
         if (IntelligentDevice != null)
         {
             txt_Name.Text = IntelligentDevice.Name;
             ddl_DeviceType.SelectedValue = ((int)IntelligentDevice.DeviceType).ToString();
         }
     }
 }
 private void InfoBind()
 {
     using (IFMPDBContext db = new IFMPDBContext())
     {
         IntelligentDevice IntelligentDevice = db.IntelligentDevice.FirstOrDefault(t => t.ID == IntelligentDeviceID);
         if (IntelligentDevice != null)
         {
             txt_Name.Text = IntelligentDevice.Name;
             ddl_DeviceType.SelectedValue = ((int)IntelligentDevice.DeviceType).ToString();
             txt_Place.Text         = IntelligentDevice.Place;
             txt_Identity.Text      = IntelligentDevice.Identity;
             txt_BeginDate.Text     = IntelligentDevice.BeginDate == null ? "" : IntelligentDevice.BeginDate.Value.ToString("HH:mm:ss");
             txt_EndDate.Text       = IntelligentDevice.EndDate == null ? "" : IntelligentDevice.EndDate.Value.ToString("HH:mm:ss");
             txt_Master.Text        = IntelligentDevice.UserID.ToString();
             ddl_DeviceType.Enabled = false;
         }
     }
 }
예제 #3
0
        //ph-温度传感器
        private static void PHTEMPDataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
        {
            SerialPort sp     = (SerialPort)sender;
            string     indata = sp.ReadLine();

            if (!string.IsNullOrEmpty(indata.Trim()))
            {
                //ID:01 PH:15.2 TEMP:12.5  ALARM!
                string ID          = indata.Substring(indata.IndexOf("ID:") + 3, indata.IndexOf("PH:") - indata.IndexOf("ID:") - 3).Trim();
                double PH          = Convert.ToDouble(indata.Substring(indata.IndexOf("PH:") + 3, indata.IndexOf("TEMP:") - indata.IndexOf("PH:") - 3).Trim());
                double Temperature = Convert.ToDouble(indata.Substring(indata.IndexOf("TEMP:") + 5).Replace("ALARM!", "").Trim());

                using (IFMPDBContext db = new IFMPDBContext())
                {
                    IntelligentDevice IntelligentDevice = db.IntelligentDevice.FirstOrDefault(t => t.Identity == ID);
                    if (IntelligentDevice != null &&
                        (IntelligentDevice.BeginDate == null || new BaseUtils().GetTodayDate(DateTime.Now, IntelligentDevice.BeginDate.Value) < DateTime.Now) &&
                        (IntelligentDevice.EndDate == null || new BaseUtils().GetTodayDate(DateTime.Now, IntelligentDevice.EndDate.Value) > DateTime.Now))
                    {
                        IntelligentDeviceData IntelligentDeviceData = new IntelligentDeviceData();
                        IntelligentDeviceData.IntelligentDeviceID = IntelligentDevice.ID;
                        IntelligentDeviceData.CreateDate          = DateTime.Now;
                        IntelligentDeviceData.DeviceDataType      = DeviceDataType.PH值;
                        IntelligentDeviceData.Data    = PH.ToString();
                        IntelligentDeviceData.IsAlert = !(PH >= 5 && PH <= 9);
                        db.IntelligentDeviceData.Add(IntelligentDeviceData);

                        IntelligentDeviceData = new IntelligentDeviceData();
                        IntelligentDeviceData.IntelligentDeviceID = IntelligentDevice.ID;
                        IntelligentDeviceData.CreateDate          = DateTime.Now;
                        IntelligentDeviceData.DeviceDataType      = DeviceDataType.温度;
                        IntelligentDeviceData.Data    = Temperature.ToString();
                        IntelligentDeviceData.IsAlert = false;
                        db.IntelligentDeviceData.Add(IntelligentDeviceData);

                        db.SaveChanges();
                    }
                }
            }
        }
예제 #4
0
        protected void btn_Delete_Click(object sender, EventArgs e)
        {
            string ids = hf_CheckIDS.Value.ToString();

            try
            {
                ids = ids.TrimEnd(',').TrimStart(',');

                using (IFMPDBContext db = new IFMPDBContext())
                {
                    foreach (string id in ids.Split(','))
                    {
                        int selid = Convert.ToInt32(id);
                        IntelligentDevice IntelligentDevice = db.IntelligentDevice.FirstOrDefault(t => t.ID == selid);
                        //Leave Leave = db.Leave.FirstOrDefault(t => t.ID == selid && t.LeaveState == LeaveState.未审核);

                        if (IntelligentDevice != null)
                        {
                            IntelligentDevice.IsDel = true;
                        }
                        else
                        {
                            ShowMessage("删除智能设备失败");
                            return;
                        }
                    }
                    db.SaveChanges();
                    ShowMessage("删除成功");
                    new SysLogDAO().AddLog(LogType.操作日志_删除, "删除智能设备", UserID);
                }
                DataBindList();
                this.hf_CheckIDS.Value = "";
            }
            catch (Exception ex)
            {
                new SysLogDAO().AddLog(LogType.系统日志, ex.Message, UserID);
                return;
            }
        }
        protected void btn_Submit_Click(object sender, EventArgs e)
        {
            try
            {
                using (IFMPDBContext db = new IFMPDBContext())
                {
                    //这里应该有权限,很重要
                    IntelligentDevice IntelligentDevice = db.IntelligentDevice.FirstOrDefault(t => t.ID == IntelligentDeviceID);

                    if (IntelligentDevice == null)
                    {
                        IntelligentDevice      = new IntelligentDevice();
                        IntelligentDevice.Name = txt_Name.Text.Trim();
                        if (db.IntelligentDevice.FirstOrDefault(t => t.IsDel != true && t.Name == IntelligentDevice.Name) != null)
                        {
                            ShowMessage("设备名称重复!");
                            return;
                        }
                        IntelligentDevice.DeviceType = (DeviceType)Convert.ToInt32(ddl_DeviceType.SelectedValue);
                        IntelligentDevice.Identity   = txt_Identity.Text.Trim();
                        if (db.IntelligentDevice.FirstOrDefault(t => t.IsDel != true &&
                                                                t.DeviceType == IntelligentDevice.DeviceType &&
                                                                t.Identity == IntelligentDevice.Identity
                                                                ) != null)
                        {
                            ShowMessage("设备标识重复!");
                            return;
                        }

                        if (!string.IsNullOrEmpty(txt_BeginDate.Text.Trim()))
                        {
                            IntelligentDevice.BeginDate = Convert.ToDateTime(txt_BeginDate.Text.Trim());
                        }

                        if (!string.IsNullOrEmpty(txt_EndDate.Text.Trim()))
                        {
                            IntelligentDevice.EndDate = Convert.ToDateTime(txt_EndDate.Text.Trim());
                        }

                        IntelligentDevice.CreateDate = DateTime.Now;
                        IntelligentDevice.IsDel      = false;
                        IntelligentDevice.Place      = txt_Place.Text;
                        IntelligentDevice.UserID     = Convert.ToInt32(txt_Master.Text);
                        db.IntelligentDevice.Add(IntelligentDevice);

                        new SysLogDAO().AddLog(LogType.操作日志_添加, "添加智能设备", UserID);
                    }
                    else
                    {
                        IntelligentDevice.Name = txt_Name.Text.Trim();

                        if (db.IntelligentDevice.FirstOrDefault(t => t.IsDel != true &&
                                                                t.Name == IntelligentDevice.Name &&
                                                                t.ID != IntelligentDevice.ID) != null)
                        {
                            ShowMessage("设备名称重复!");
                            return;
                        }

                        IntelligentDevice.Identity = txt_Identity.Text.Trim();

                        if (db.IntelligentDevice.FirstOrDefault(t => t.IsDel != true &&
                                                                t.DeviceType == IntelligentDevice.DeviceType &&
                                                                t.Identity == IntelligentDevice.Identity &&
                                                                t.ID != IntelligentDevice.ID
                                                                ) != null)
                        {
                            ShowMessage("设备标识重复!");
                            return;
                        }

                        if (!string.IsNullOrEmpty(txt_BeginDate.Text.Trim()))
                        {
                            IntelligentDevice.BeginDate = Convert.ToDateTime(txt_BeginDate.Text.Trim());
                        }

                        if (!string.IsNullOrEmpty(txt_EndDate.Text.Trim()))
                        {
                            IntelligentDevice.EndDate = Convert.ToDateTime(txt_EndDate.Text.Trim());
                        }

                        IntelligentDevice.Place = txt_Place.Text;

                        new SysLogDAO().AddLog(LogType.操作日志_修改, "修改智能设备", UserID);
                    }

                    db.SaveChanges();
                    ShowMessage();
                }
            }
            catch (Exception ex)
            {
                ShowMessage(ex.Message);
                new SysLogDAO().AddLog(LogType.系统日志, ex.Message, UserID);
                return;
            }
        }