private ushort[] m_usRange; //for newer version void Application_Start(object sender, EventArgs e) { // Code that runs on application startup RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); Database.SetInitializer(new CpDashboardDatabaseInitializer()); RouteTable.Routes.MapHttpRoute( name: "Alert", routeTemplate: "api/{controller}/{id}", defaults: new { id = System.Web.Http.RouteParameter.Optional } ); CpDashboardContext cont = new CpDashboardContext(); cont.Database.Initialize(true); cont.Database.CreateIfNotExists(); //set a timer //adam initializer m_bStart = false; // the action stops at the beginning m_szIP = "192.168.10.10"; // modbus slave IP address m_iPort = 502; // modbus TCP port is 502 adamModbus = new AdamSocket(); adamModbus.SetTimeout(1000, 1000, 1000); // set timeout for TCP adamUDP = new AdamSocket(); adamUDP.SetTimeout(1000, 1000, 1000); // set timeout for UDP m_Adam6000Type = Adam6000Type.Adam6015; // the sample is for ADAM-6015 adamUDP.Connect(AdamType.Adam6000, m_szIP, ProtocolType.Udp); if (adamUDP.Configuration().GetFirmwareVer(out m_szFwVersion)) { m_DeviceFwVer = int.Parse(m_szFwVersion.Trim().Substring(0, 1)); } adamUDP.Disconnect(); m_iAiTotal = AnalogInput.GetChannelTotal(m_Adam6000Type); m_iDoTotal = DigitalOutput.GetChannelTotal(m_Adam6000Type); //txtModule.Text = m_Adam6000Type.ToString(); m_bChEnabled = new bool[m_iAiTotal]; //firmware version //fwversion.Text = m_DeviceFwVer.ToString(); if (m_DeviceFwVer > m_Adam6000NewerFwVer) { m_usRange = new ushort[m_iAiTotal]; } if (cont.Database.Exists()) { // start the retrieving datas and save to db; startSending(); } }
protected void Register_Click(object sender, EventArgs e) { CpDashboardContext context = new CpDashboardContext(); string reg_pass = new Encryptions().EncryptPassword(RegisterPass.Text); string reg_repass = new Encryptions().EncryptPassword(RegisterRepass.Text); if (reg_pass == reg_repass) { //singleordefault can only return to var var query = context.Users.SingleOrDefault(q => q.UserName == RegisterEm.Text); if (query == null) { context.Users.Add(InsertUser(RegisterFn.Text, RegisterLn.Text, RegisterEm.Text, reg_repass)); context.SaveChanges(); query = context.Users.SingleOrDefault(u => u.UserName == RegisterEm.Text); Session["Id"] = query.UserId; Session["Username"] = query.UserName; Session["Password"] = query.Password; Session["Name"] = query.Name; Session["Lastname"] = query.LastName; Session["Position"] = context.Positions.SingleOrDefault(p => p.PositionID == query.PositionID).PositionName; Session["Login"] = "******"; Response.Redirect("~/Default.aspx"); } else { LabelEm.Text = "Email already Exist!!"; } } else { LabelPass.Text = "Your password is not match!!"; } }