Пример #1
0
 public void CheckMesInfo(object sender, ElapsedEventArgs e)
 {
     if (AppCurrent.IsRunning && Current.Mes.IsEnabled && !Current.Mes.IsOffline)
     {
         MES.UploadMachineInfo("S");
         MES.Upload();
     }
 }
Пример #2
0
        public static void Upload(int id)
        {
            if (Current.Mes.IsOffline)
            {
                return;
            }

            var datas = new List <InsulationDataLog>();

            if (id > 0)
            {
                datas = Context.InsulationContext.DataLogs.Where(d => d.Id == id)
                        .Include("Battery").ToList();
            }
            else
            {
                datas = Context.InsulationContext.DataLogs.Where(d => d.Resistance > 0 && d.Temperature > 0)
                        .Include("Battery").OrderByDescending(d => d.DateTime)
                        .Where(i => !i.IsUploaded).Take(5).ToList();
            }

            if (datas.Count < 1)
            {
                return;
            }

            datas.ForEach(d =>
            {
                Current.Mes.RealtimeStatus = string.Format("MES检验通过,ID:{0}", d.Id);
                Thread.Sleep(100);
                if (MES.UploadBattery(d.Battery.Code, d.Resistance, d.Voltage, d.Temperature, d.TimeSpan))
                {
                    d.IsUploaded = true;
                    //上传MES
                    AppCurrent.YieldNow.BlankingOK++;
                    Current.Mes.RealtimeStatus = string.Format("上传MES完成,ID:{0}", d.Id);
                }
                else
                {
                    d.IsUploaded = true;
                    Current.Mes.RealtimeStatus = string.Format("上传MES失败,ID:{0}", d.Id);
                }
                Context.InsulationContext.SaveChanges();
                Thread.Sleep(100);
            });

            var t = new Thread(() =>
            {
                Thread.Sleep(1000);
                Current.Mes.RealtimeStatus = "等待上传";
            });

            t.IsBackground = true;
            t.Start();
        }
Пример #3
0
        protected override void Seed(MesContext context)
        {
            var mes = new MES
            {
                Name      = "MES",
                Host      = "192.168.1.1",
                IsEnabled = true
            };

            context.MESs.Add(mes);
        }
Пример #4
0
        public static void Insert()
        {
            if (Battery.Id > 0)
            {
                Context.InsulationContext.DataLogs.Add(new InsulationDataLog()
                {
                    User        = AppCurrent.User,
                    Battery     = Battery,
                    Resistance  = 0,
                    Voltage     = 0,
                    TimeSpan    = 0,
                    Temperature = 0,
                    IsUploaded  = false,
                    DateTime    = DateTime.Now
                });
                Context.InsulationContext.SaveChanges();

                AppCurrent.YieldNow.FeedingOK++;

                Battery = new Battery();
            }

            if (Resistance > -1)
            {
                var data = Context.InsulationContext.DataLogs.Where(d => d.Resistance == 0)
                           .OrderByDescending(d => d.DateTime).Take(3).OrderBy(d => d.DateTime).FirstOrDefault();
                if (data != null)
                {
                    data.Resistance = Resistance;
                    data.Voltage    = Voltage;
                    data.TimeSpan   = TimeSpan;
                    Context.InsulationContext.SaveChanges();
                }
                Resistance = -1;
            }

            if (Temperature > -1)
            {
                var data = Context.InsulationContext.DataLogs.Where(d => d.Temperature == 0)
                           .OrderByDescending(d => d.DateTime).Take(3).OrderBy(d => d.DateTime).FirstOrDefault();
                if (data != null)
                {
                    data.Temperature = Temperature;
                    Context.InsulationContext.SaveChanges();

                    if (data.Id > 0)
                    {
                        MES.Upload(data.Id);
                    }
                }
                Temperature = -1;
            }
        }
Пример #5
0
        public static bool Login(string userNumber, string password, out string msg)
        {
            string userName = string.Empty;

            if (!MES.GetUserName(userNumber, password, out userName, out msg))
            {
                return(false);
            }

            if (TengDa.Wpf.Context.UserContext.Users.Where(u => u.Name == userName).Count() == 0)
            {
                //首次登录需先注册
                if (!User.Register(userName, userNumber, password, true, out msg))
                {
                    return(false);
                }
            }

            return(User.Login(userName, password, out msg));
        }
Пример #6
0
        public LoginWindow()
        {
            InitializeComponent();

            new DbInitializer().Initialize();

            this.DataContext       = Current.App;
            myMediaTimeline.Source = new Uri(AppDomain.CurrentDomain.BaseDirectory + "Videos/LoginHead.mp4");
            if (Current.Option.IsRememberMe)
            {
                var user = TengDa.Wpf.Context.UserContext.Users.SingleOrDefault(u => u.Id == Current.Option.LastLoginUserId);
                if (user != null)
                {
                    this.userNameTextBox.Text = user.Name;
                    this.passwordBox.Password = Base64.DecodeBase64(user.Password);
                    this.ProfileImage.Source  = new BitmapImage(new Uri(user.ProfilePicture, UriKind.Relative));;
                }
            }

            MES.GetInfo();
        }
Пример #7
0
        private void btnLoginOrRegister_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(this.userNameTextBox.Text))
            {
                Tip.Alert("请输入用户名");
                return;
            }

            if (string.IsNullOrEmpty(this.passwordBox.Text))
            {
                Tip.Alert("请输入密码");
                return;
            }

            if (!Current.App.IsLoginWindow && string.IsNullOrEmpty(this.confirmPasswordBox.Text))
            {
                Tip.Alert("请输入确认密码");
                return;
            }

            if (!Current.App.IsLoginWindow && this.confirmPasswordBox.Text != this.passwordBox.Text)
            {
                Tip.Alert("两次输入密码不相同");
                return;
            }

            string msg = string.Empty;

            //登录
            if (Current.App.IsLoginWindow)
            {
                if (Current.Option.IsMesLogin)
                {
                    if (!Current.Mes.IsPingSuccess)
                    {
                        Error.Alert("无法连接至MES服务器,登录失败!");
                        return;
                    }
                    //MES登录
                    if (MES.Login(this.userNameTextBox.Text, this.passwordBox.Password, out msg))
                    {
                        AfterLogin();
                    }
                    else
                    {
                        Tip.Alert(msg);
                    }
                }
                else
                {
                    //普通登录
                    if (User.Login(this.userNameTextBox.Text, this.passwordBox.Password, out msg))
                    {
                        AfterLogin();
                    }
                    else
                    {
                        Tip.Alert(msg);
                    }
                }
            }
            else //注册
            {
                if (User.Register(this.userNameTextBox.Text, this.passwordBox.Password, out msg))
                {
                    AfterRegister();
                }
                else
                {
                    Tip.Alert(msg);
                }
            }
        }