public ActionResult MachinesInsertOrEdit(int machineID)
        {
            using (DBEPREntities db = new DBEPREntities())
            {
                MachinesViewModel mvm = new MachinesViewModel();
                //for Modals:

                List <MANUFACTURER> manList = db.MANUFACTURERS.Where(s => s.IsDeleted == false).ToList();
                ViewBag.ManufacturerList = new SelectList(manList, "ID", "Name");
                List <MACHINETYPE> tList = db.MACHINETYPES.Where(s => s.IsDeleted == false).ToList();
                ViewBag.typeList = new SelectList(tList, "ID", "Name");
                List <UZAUTOSUPPLIER> uList = db.UZAUTOSUPPLIERS.Where(s => s.IsDeleted == false).ToList();
                ViewBag.UzAutoSupplierList = new SelectList(uList, "ID", "Name");

                if (machineID > 0)
                {
                    MACHINE machine = db.MACHINES.SingleOrDefault(m => m.IsDeleted == false && m.ID == machineID);
                    if (machine != null)
                    {
                        mvm.ID               = machine.ID;
                        mvm.Name             = machine.Name;
                        mvm.Description      = machine.Description;
                        mvm.PartNumber       = machine.PartNumber;
                        mvm.Lifespan         = machine.Lifespan;
                        mvm.InstalledDate    = machine.InstalledDate;
                        mvm.Status           = machine.IsActive;
                        mvm.ManufacturerID   = machine.ManufacturerID;
                        mvm.UzAutoSupplierID = machine.UzAutoSupplierID;
                        mvm.TypeID           = machine.TypeID;
                    }
                }
                return(PartialView("MachinesInsertOrEdit", mvm));
            }
        }
Beispiel #2
0
        public ActionResult Index()
        {
            var model = new MachinesViewModel
            {
                FilterText = ""
            };

            return(View(model));
        }
        public ActionResult MachinesSave(MachinesViewModel model)
        {
            using (DBEPREntities db = new DBEPREntities())
            {
                if (model.ID > 0)
                {
                    MACHINE machine = db.MACHINES.SingleOrDefault(m => m.IsDeleted == false && m.ID == model.ID);
                    if (machine != null)
                    {
                        machine.Name          = model.Name;
                        machine.Description   = model.Description;
                        machine.Lifespan      = model.Lifespan;
                        machine.InstalledDate = model.InstalledDate;
                        machine.PartNumber    = model.PartNumber;
                        if (model.Status)
                        {
                            machine.IsActive = true;
                        }
                        else
                        {
                            machine.IsActive = false;
                        }
                        machine.ManufacturerID   = model.ManufacturerID;
                        machine.UzAutoSupplierID = model.UzAutoSupplierID;
                        machine.TypeID           = model.TypeID;

                        db.SaveChanges();
                    }
                }
                else
                {
                    MACHINE machine = new MACHINE();

                    machine.Name          = model.Name;
                    machine.Description   = model.Description;
                    machine.Lifespan      = model.Lifespan;
                    machine.InstalledDate = model.InstalledDate;
                    machine.PartNumber    = model.PartNumber;
                    if (model.Status)
                    {
                        machine.IsActive = true;
                    }
                    else
                    {
                        machine.IsActive = false;
                    }
                    machine.ManufacturerID   = model.ManufacturerID;
                    machine.UzAutoSupplierID = model.UzAutoSupplierID;
                    machine.TypeID           = model.TypeID;
                    machine.IsDeleted        = false;

                    db.MACHINES.Add(machine);
                    db.SaveChanges();
                }
                return(RedirectToAction("Machines"));
            }
        }
        public ActionResult Machines()
        {
            using (DBEPREntities db = new DBEPREntities())
            {
                MachinesViewModel mvm = new MachinesViewModel();
                mvm.machineList = db.MACHINES.Include("MACHINETYPE").Include("UZAUTOSUPPLIER").Include("MANUFACTURER").Where(m => m.IsDeleted == false).ToList();

                return(View(mvm));
            }
        }
Beispiel #5
0
        public async Task <IActionResult> Create(MachinesViewModel model)
        {
            if (ModelState.IsValid)
            {
                var newmachine = Mapper.Map <Machine>(model);
                _context.Add(newmachine);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Beispiel #6
0
        public async Task <IActionResult> Edit(string id, MachinesViewModel model)
        {
            if (ModelState.IsValid)
            {
                var machine = await _context.Machines.SingleAsync(x => x.Name == id);

                Mapper.Map(model, machine);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Beispiel #7
0
        /// <summary>
        /// Initializes a new instance of the ViewModelLocator class.
        /// </summary>
        public ViewModelLocator()
        {
            ////if (ViewModelBase.IsInDesignModeStatic)
            ////{
            ////    // Create design time services and viewmodels
            ////}
            ////else
            ////{
            ////    // Create run time services and view models
            ////}

            main = new MainViewModel();

            machinesViewModel = new MachinesViewModel();
        }
Beispiel #8
0
 private void CMMachineStart1_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         SelectedMachineName = Common.MachineList[0].MachineName;
         MachinesViewModel FirstMachine = Common.MachineList[0];
         _continueth1 = true;
         Thread readThread = new Thread(ReadFromth1);
         readThread.Start(FirstMachine);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Beispiel #9
0
        /// <summary>
        /// Initializes a new instance of the ViewModelLocator class.
        /// </summary>
        public ViewModelLocator()
        {
            ////if (ViewModelBase.IsInDesignModeStatic)
            ////{
            ////    // Create design time services and viewmodels
            ////}
            ////else
            ////{
            ////    // Create run time services and view models
            ////}

            main = new MainViewModel();

            machinesViewModel = new MachinesViewModel();
        }
Beispiel #10
0
        internal static int SendEmail(MachinesViewModel selectedMachine)
        {
            int result = -1;

            try
            {
                List <EMailViewModel> emailConfigList = Dalc.Dalc.LoadEmailConfiguration();

                if (emailConfigList.Count > 0)
                {
                    using (MailMessage mail = new MailMessage())
                    {
                        mail.From = new MailAddress(emailConfigList[0].EmailFrom);
                        if (selectedMachine.EmailTo != "")
                        {
                            mail.To.Add(selectedMachine.EmailTo);
                        }
                        else
                        {
                            mail.To.Add(emailConfigList[0].EmailTo1);
                        }
                        mail.Subject    = emailConfigList[0].EmailSubject;
                        mail.Body       = emailConfigList[0].EmailBody;
                        mail.IsBodyHtml = true;
                        // Can set to false, if you are sending pure text.
                        //mail.Attachments.Add(new Attachment(@"D:\Projects\WPFProject\IDFI_IVMS\IVMSLatest_1_oct\IVMS\IVMS\Images\information.png"));
                        //mail.Attachments.Add(new Attachment("C:\\SomeZip.zip"));
                        using (SmtpClient smtp = new SmtpClient(emailConfigList[0].SMTPAddress, emailConfigList[0].SMTPPort))
                        {
                            smtp.Credentials = new NetworkCredential(emailConfigList[0].EmailFrom, emailConfigList[0].EmailPassword);
                            smtp.EnableSsl   = emailConfigList[0].EnableSSL;
                            //smtp.Send(mail);
                            result = Dalc.Dalc.AddEmailToDatabase(0, selectedMachine, emailConfigList[0]);
                            if (result != -1)
                            {
                                logger.LogInfo("Email added successfuly in database.");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result = -1;
                logger.LogError("Exception in method SendEmail, for server : " + selectedMachine.MachineName + "  Message : " + ex.Message);
            }
            return(result);
        }
Beispiel #11
0
        /// <summary>
        /// Method is used to add machine
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddMachine_Click(object sender, RoutedEventArgs e)
        {
            MachinesViewModel machine = new MachinesViewModel();

            machine.MachineName     = lblMachineName.Content.ToString();
            machine.MachineLocation = lblMachineLocation.Content.ToString();
            machine.ProductName     = lblProductName.Content.ToString();
            machine.SupervisorName  = lblSupervisorName.Content.ToString();
            machine.ConnectionType  = (Common.ConnectionType)lblMachineConType.Content;
            machine.EmailTo         = lblEmailTo.Content.ToString();
            if (machine.ConnectionType == Common.ConnectionType.Telnet)
            {
                machine.MachineIP       = lblMachineIP.Content.ToString();
                machine.MachinePort     = Convert.ToUInt16(lblMachinePort.Content.ToString());
                machine.COMPortName     = "";
                machine.COMPortBoadRate = "";
                machine.COMPortParity   = "";
            }
            else
            {
                machine.COMPortParity   = "";
                machine.MachineIP       = "";
                machine.MachinePort     = 0;
                machine.COMPortName     = lblMachineIP.Content.ToString();
                machine.COMPortBoadRate = lblMachinePort.Content.ToString();
                machine.COMPortParity   = "";
            }
            imgServerConfiguredDark.Visibility = Visibility.Hidden;
            ErrorMessage errmsg = Common.ManageMachine(0, machine, CommandTypeEnum.Insert);

            if (errmsg.ErrorId == 1)
            {
                MessageBox.Show("Machine : " + machine.MachineName + " Added successfuly");
                imgServerConfiguredOK.Visibility = Visibility.Visible;
                FinalImage.Visibility            = Visibility.Hidden;
                btnAddMachinePre.Visibility      = Visibility.Hidden;
                btnAddMachine.Visibility         = Visibility.Hidden;
                ClearAddMachineControls();
                TabDashboard.IsSelected = true;
            }
            else if (errmsg.ErrorId == 100)
            {
                MessageBox.Show(errmsg.ErrorDescription);
                imgServerConfiguredOK.Visibility = Visibility.Hidden;
            }
        }
Beispiel #12
0
        // GET: Machines/Edit/5
        public async Task <IActionResult> Edit(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(NotFound());
            }

            var machine = await _context.Machines.SingleOrDefaultAsync(m => m.Name == id);

            MachinesViewModel model = Mapper.Map <MachinesViewModel>(machine);

            if (machine == null)
            {
                return(NotFound());
            }

            return(View(model));
        }
Beispiel #13
0
        // GET: Machines
        public async Task <IActionResult> Index(int skip = 0, int take = 10)
        {
            PaginationViewModel <MachinesViewModel> result = new PaginationViewModel <MachinesViewModel>();

            int quantita = await _context.Machines.CountAsync();

            List <Machine> person = await _context.Machines.Skip(skip).Take(take).ToListAsync();

            result.Count = quantita;
            result.Skip  = skip;
            foreach (var p in person)
            {
                MachinesViewModel pv = new MachinesViewModel()
                {
                    IpMachine  = p.IpMachine,
                    Nome       = p.Name,
                    MacAddress = p.MacAddress
                };
                result.Data.Add(pv);
            }

            return(View(result));
        }
Beispiel #14
0
/// <summary>
///
/// </summary>
/// <param name="ServerName"></param>
/// <param name="EmailVM"></param>
        public static int AddEmailToDatabase(int Id, MachinesViewModel SelectedMachine, EMailViewModel EmailVM)
        {
            int result = -1;

            try
            {
                using (MySqlConnection con = new MySqlConnection(connectionString))
                {
                    con.Open();
                    MySqlCommand cmd = new MySqlCommand("spAddEmailLog", con);
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;

                    MySqlParameter pId = new MySqlParameter();
                    pId.ParameterName = "in_Id";
                    pId.Value         = Id;
                    cmd.Parameters.Add(pId);

                    MySqlParameter pEmailFrom = new MySqlParameter();
                    pEmailFrom.ParameterName = "in_EmailFrom";
                    pEmailFrom.Value         = EmailVM.EmailFrom;
                    cmd.Parameters.Add(pEmailFrom);

                    MySqlParameter pServerName = new MySqlParameter();
                    pServerName.ParameterName = "in_ServerName";
                    pServerName.Value         = SelectedMachine.MachineName;
                    cmd.Parameters.Add(pServerName);

                    MySqlParameter pEmailTo = new MySqlParameter();
                    pEmailTo.ParameterName = "in_EmailTo";
                    pEmailTo.Value         = SelectedMachine.EmailTo;
                    cmd.Parameters.Add(pEmailTo);

                    MySqlParameter pEmailTo1 = new MySqlParameter();
                    pEmailTo1.ParameterName = "in_EmailTo1";
                    pEmailTo1.Value         = EmailVM.EmailTo1;
                    cmd.Parameters.Add(pEmailTo1);

                    MySqlParameter pEmailTo2 = new MySqlParameter();
                    pEmailTo2.ParameterName = "in_EmailTo2";
                    pEmailTo2.Value         = EmailVM.EmailTo2;
                    cmd.Parameters.Add(pEmailTo2);

                    MySqlParameter pEmailTo3 = new MySqlParameter();
                    pEmailTo3.ParameterName = "in_EmailTo3";
                    pEmailTo3.Value         = EmailVM.EmailTo3;
                    cmd.Parameters.Add(pEmailTo3);

                    MySqlParameter pEmailTo4 = new MySqlParameter();
                    pEmailTo4.ParameterName = "in_EmailTo4";
                    pEmailTo4.Value         = EmailVM.EmailTo4;
                    cmd.Parameters.Add(pEmailTo4);
                    MySqlParameter pEmailTo5 = new MySqlParameter();
                    pEmailTo5.ParameterName = "in_EmailTo5";
                    pEmailTo5.Value         = EmailVM.EmailTo5;
                    cmd.Parameters.Add(pEmailTo5);

                    MySqlParameter pEmailSubject = new MySqlParameter();
                    pEmailSubject.ParameterName = "in_EmailSubject";
                    pEmailSubject.Value         = EmailVM.EmailSubject;
                    cmd.Parameters.Add(pEmailSubject);

                    MySqlParameter pEmailBody = new MySqlParameter();
                    pEmailBody.ParameterName = "in_EmailBody";
                    pEmailBody.Value         = EmailVM.EmailBody;
                    cmd.Parameters.Add(pEmailBody);

                    MySqlParameter pEntryDate = new MySqlParameter();
                    pEntryDate.ParameterName = "in_EntryDate";
                    pEntryDate.Value         = DateTime.Now;
                    cmd.Parameters.Add(pEntryDate);

                    result = cmd.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                result = -1;
                logger.LogError("Exception in AddEmailToDatabase method,Message : " + ex.Message);
            }
            return(result);
        }
Beispiel #15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="serverVM"></param>
        /// <param name="CommandType"></param>
        /// <returns></returns>
        public static ErrorMessage ManageMachine(int MachineId, MachinesViewModel machineVM, CommandTypeEnum CommandType)
        {
            ErrorMessage errmsg = new ErrorMessage();

            try
            {
                using (MySqlConnection con = new MySqlConnection(connectionString))
                {
                    con.Open();
                    MySqlCommand cmd = new MySqlCommand("spManageMachine", con);
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;

                    MySqlParameter pId = new MySqlParameter();
                    pId.ParameterName = "in_Id";
                    pId.Value         = MachineId;
                    cmd.Parameters.Add(pId);

                    MySqlParameter pMachineName = new MySqlParameter();
                    pMachineName.ParameterName = "in_MachineName";
                    pMachineName.Value         = machineVM.MachineName;
                    cmd.Parameters.Add(pMachineName);

                    MySqlParameter pMachineLocation = new MySqlParameter();
                    pMachineLocation.ParameterName = "in_MachineLocation";
                    pMachineLocation.Value         = machineVM.MachineLocation;
                    cmd.Parameters.Add(pMachineLocation);

                    MySqlParameter pProductName = new MySqlParameter();
                    pProductName.ParameterName = "in_ProductName";
                    pProductName.Value         = machineVM.ProductName;
                    cmd.Parameters.Add(pProductName);

                    MySqlParameter pSupervisorName = new MySqlParameter();
                    pSupervisorName.ParameterName = "in_SupervisorName";
                    pSupervisorName.Value         = machineVM.SupervisorName;
                    cmd.Parameters.Add(pSupervisorName);

                    MySqlParameter pEmailTo = new MySqlParameter();
                    pEmailTo.ParameterName = "in_EmailTo";
                    pEmailTo.Value         = machineVM.EmailTo;
                    cmd.Parameters.Add(pEmailTo);

                    MySqlParameter pConnectionType = new MySqlParameter();
                    pConnectionType.ParameterName = "in_ConnectionType";
                    pConnectionType.Value         = machineVM.ConnectionType;
                    cmd.Parameters.Add(pConnectionType);

                    MySqlParameter pServerIP = new MySqlParameter();
                    pServerIP.ParameterName = "in_MachineIP";
                    pServerIP.Value         = machineVM.MachineIP;
                    cmd.Parameters.Add(pServerIP);

                    MySqlParameter pServerPort = new MySqlParameter();
                    pServerPort.ParameterName = "in_MachinePort";
                    pServerPort.Value         = machineVM.MachinePort;
                    cmd.Parameters.Add(pServerPort);

                    MySqlParameter pComportName = new MySqlParameter();
                    pComportName.ParameterName = "in_ComportName";
                    pComportName.Value         = machineVM.COMPortName;
                    cmd.Parameters.Add(pComportName);

                    MySqlParameter pComportParity = new MySqlParameter();
                    pComportParity.ParameterName = "in_ComportParity";
                    pComportParity.Value         = machineVM.COMPortParity;
                    cmd.Parameters.Add(pComportParity);

                    MySqlParameter pin_ComPortBaudRate = new MySqlParameter();
                    pin_ComPortBaudRate.ParameterName = "in_ComPortBaudRate";
                    pin_ComPortBaudRate.Value         = machineVM.COMPortBoadRate;
                    cmd.Parameters.Add(pin_ComPortBaudRate);

                    MySqlParameter pCommandType = new MySqlParameter();
                    pCommandType.ParameterName = "in_CommandType";
                    pCommandType.Value         = CommandType.ToString();
                    cmd.Parameters.Add(pCommandType);

                    MySqlParameter outPutErrorId = new MySqlParameter();
                    outPutErrorId.ParameterName = "out_ErrorId";
                    outPutErrorId.Direction     = System.Data.ParameterDirection.Output;
                    cmd.Parameters.Add(outPutErrorId);

                    MySqlParameter outPutErrorMessage = new MySqlParameter();
                    outPutErrorMessage.ParameterName = "out_ErrorMessage";
                    outPutErrorMessage.Direction     = System.Data.ParameterDirection.Output;
                    cmd.Parameters.Add(outPutErrorMessage);

                    cmd.ExecuteNonQuery();
                    errmsg.ErrorId          = (int)outPutErrorId.Value;
                    errmsg.ErrorDescription = outPutErrorMessage.Value.ToString();
                }
            }
            catch (Exception ex)
            {
                logger.LogError("Exception in DALC CLASS, Method Name AddMachine, Message : " + ex.Message);
                errmsg.ErrorId          = 0;
                errmsg.ErrorDescription = ex.Message;
            }
            return(errmsg);
        }
Beispiel #16
0
        public void ReadFromth1(object firstmachine)
        {
            MachinesViewModel FirstMachine = (MachinesViewModel)firstmachine;

            while (_continueth1)
            {
                try
                {
                    if (FirstMachine.ConnectionType == Common.ConnectionType.Telnet)
                    {
                        if (!client1Socket.Connected)
                        {
                            client1Socket.Connect(FirstMachine.MachineIP, Convert.ToInt32(FirstMachine.MachinePort));
                        }
                        NetworkStream serverStream = client1Socket.GetStream();
                        byte[]        inStream     = new byte[10025];
                        serverStream.Read(inStream, 0, (int)client1Socket.ReceiveBufferSize);
                        string replacement = Regex.Replace(System.Text.Encoding.ASCII.GetString(inStream), @"\t|\0", "");
                        logger.LogInfo("Received message from server : " + replacement);
                        //if (replacement == "1")
                        // {
                        Common.AddDataInDatabase(SelectedMachineName, replacement);
                        int result = Common.SendEmail(FirstMachine);
                        // }
                    }
                    else
                    {
                        if (_serialPort != null && _serialPort.IsOpen)
                        {
                            _serialPort.Close();
                        }
                        if (_serialPort == null)
                        {
                            _serialPort = new SerialPort(FirstMachine.COMPortName);
                            //_serialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandlerForFirstMachine);
                            _serialPort.DtrEnable = true;
                            _serialPort.Handshake = Handshake.None;
                            _serialPort.BaudRate  = Convert.ToInt32(FirstMachine.COMPortBoadRate);
                            _serialPort.Open();
                            string indata  = _serialPort.ReadLine();
                            string message = Regex.Replace(indata, @"\t|\0", "");
                            Common.AddDataInDatabase(SelectedMachineName, message);
                            //Common.SendEmail(Common.MachineList[0]);
                        }
                        else
                        {
                            if (!_serialPort.IsOpen)
                            {
                                _serialPort.Open();
                            }
                            string indata  = _serialPort.ReadLine();
                            string message = Regex.Replace(indata, @"\t|\0", "");
                            Common.AddDataInDatabase(SelectedMachineName, message);
                            //Common.SendEmail(Common.MachineList[0]);
                        }
                    }
                }
                catch (TimeoutException tex) { }
                catch (Exception ex)
                {
                    logger.LogError("" + ex.Message);
                }
            }
        }
Beispiel #17
0
 /// <summary>
 /// Method is used to add server in database
 /// </summary>
 /// <param name="ServerName">Server Name</param>
 /// <param name="ConnectionType">Telnet or COM Port</param>
 /// <param name="ServerIP">Server IP</param>
 /// <param name="ServerPort">Server Port Number</param>
 /// <param name="COMPortName">COM Port Name</param>
 /// <param name="COMPortParity"></param>
 /// <param name="COMPortBoadRate"></param>
 /// <returns></returns>
 public static ErrorMessage ManageMachine(int MachineId, MachinesViewModel MachineVM, CommandTypeEnum CommandType)
 {
     return(Dalc.Dalc.ManageMachine(MachineId, MachineVM, CommandType));
 }