protected void btnAdd_OnClick(object sender, EventArgs e)
        {
            DeviceDa deviceDa = new DeviceDa();
            List<Device> lstDevice = deviceDa.getDevices();

            Device device = new Device();
            lstDevice.Add(device);

            grdDevices.EditIndex = lstDevice.Count-1;

            grdDevices.DataSource = lstDevice;
            grdDevices.DataBind();
        }
Пример #2
0
        //Buttons
        private void btnSaveDevice_Click(object sender, EventArgs e)
        {
            Device device = new Device();
            device.Date = DateTime.Now;
            device.IP = txtDeviceIP.Text;
            device.Cell = txtDeviceCell.Text;
            device.Name = txtDeviceName.Text;
            lstDevices.Add(device);

            xmlConfigFile.saveDevices(lstDevices);

            loadData();
        }
Пример #3
0
        private void saveDevice(XmlTextWriter writer,Device device)
        {
            // add a node
            writer.WriteStartElement("device");

            // add an attribute to "device" node
            writer.WriteAttributeString("date", device.Date.ToString("MM/dd/yyyy HH:mm"));

            writer.WriteElementString("cell", device.Cell);
            writer.WriteElementString("name", device.Name);
            writer.WriteElementString("ip", device.IP);

            //  Close "device" node
            writer.WriteEndElement();
        }
Пример #4
0
        public void doBackUp(Device device, DateTime date)
        {
            string cell = device.Cell.CellNr.ToString();
            string robot = device.Name;

            //Config
            configDate = new XMLConfigFile().readFile();

            //DATA_C950R201/BAK20120917/1400
            configDate.BackUpPath += "DATA_C" + cell + robot + "/BAK" + date.ToString("yyyyMMdd") + "/" + date.ToString("HHmm") + "/";
            System.IO.Directory.CreateDirectory(configDate.BackUpPath);

            Console.Out.WriteLine("Download files from " + device.IP + "/" + device.Cell.CellNr + "/" + device.Name);

            DownloadFiles(device,"");
        }
Пример #5
0
        public void DownloadFiles(Device device,string wildCard)
        {
            try
            {
                //WildCard = "*Parts.csv"
                string[] Files = GetFiles(device, wildCard);
                foreach (string file in Files)
                {
                    if (file.IndexOf(".") > 0)
                    {

                        if (file.LastIndexOf("/") > 0)
                            DownloadFile(device, wildCard + "/" + file.Substring(file.IndexOf("/") + 1));
                        else
                            DownloadFile(device, wildCard + file);
                    }
                    else
                    {
                        string path = "";

                        if (file.LastIndexOf("/") > 0)
                        {
                            path = wildCard + file.Substring(file.LastIndexOf("/"));
                            System.IO.Directory.CreateDirectory(configDate.BackUpPath + wildCard + file.Substring(file.LastIndexOf("/")));
                        }
                        else
                        {
                            System.IO.Directory.CreateDirectory(configDate.BackUpPath + file);
                            path = wildCard + file;
                        }

                        DownloadFiles(device, path);
                    }
                }
            }
            catch (Exception)
            {
                Console.Out.WriteLine("IP connection "+ device.IP +" not established");
            }
        }
        protected void grdDevices_OnRowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            Device device = new Device();
            device.Id = int.Parse(e.Keys[0].ToString());

            GridViewRow row = (GridViewRow)grdDevices.Rows[e.RowIndex];
            DropDownList drpCell = (DropDownList)row.FindControl("drpCell");
            DropDownList drpType = (DropDownList)row.FindControl("drpType");
            DropDownList drpBrand = (DropDownList)row.FindControl("drpBrand");

            device.IP = e.NewValues[0].ToString();
            device.CellId = int.Parse(drpCell.SelectedValue);
            device.Name = e.NewValues[1].ToString();
            device.TypeId = int.Parse(drpType.SelectedValue);
            device.BrandId = int.Parse(drpBrand.SelectedValue);

            //Save Data
            DeviceDa deviceDa = new DeviceDa();
            deviceDa.Save(device);

            grdDevices.EditIndex = -1;
            loadData();
        }
Пример #7
0
        public ConfigData readFile()
        {
            ConfigData configData = new ConfigData();
            List<Device> lstDevices = new List<Device>();

            XmlDocument doc = new XmlDocument();
            doc.Load(configPath);

            XmlNodeList devices = doc.GetElementsByTagName("device");

            foreach (XmlNode nodeDevice in devices)
            {
                Device device = new Device();
                device.Date = DateTime.Parse(nodeDevice.Attributes.GetNamedItem("date").Value);
                device.Cell = nodeDevice["cell"].InnerText;
                device.Name = nodeDevice["name"].InnerText;
                device.IP = nodeDevice["ip"].InnerText;
                lstDevices.Add(device);
            }

            //configData.Devices = lstDevices;

            return configData;
        }
Пример #8
0
        private string[] GetFiles(Device device,string WildCard)
        {
            string ReturnStr = "";

             //Connect to the FTP
             FtpWebRequest request = WebRequest.Create("ftp://"+ device.IP +"/"+ WildCard) as FtpWebRequest;

             //Listing a directory
             request.Method = WebRequestMethods.Ftp.ListDirectory;
             request.Credentials = new NetworkCredential(configDate.UserNameFTP, configDate.PasswordFTP);

             StringWriter sw = new StringWriter();

             //Get a reponse
             WebResponse response = request.GetResponse();
             Stream responseStream = response.GetResponseStream();

             //Convert the response to a string
             int ch;
             while ((ch = responseStream.ReadByte()) != -1)
              ReturnStr = ReturnStr + Convert.ToChar(ch);

             //clean up
             responseStream.Close();
             response.Close();

             //split the string by new line
             string[] sep = {"\r\n"};
             string[] Files = ReturnStr.Split(sep, StringSplitOptions.RemoveEmptyEntries);
             return Files;
        }
Пример #9
0
        private void DownloadFile(Device device,string FileName)
        {
            try
            {
                //Connect to the FTP
                FtpWebRequest request = WebRequest.Create("ftp://" + device.IP + "/" + FileName) as FtpWebRequest;

                //Downloading a file
                request.Method = WebRequestMethods.Ftp.DownloadFile;
                request.Credentials = new NetworkCredential(configDate.UserNameFTP, configDate.PasswordFTP);

                //initialize the Filestream we're using to create the downloaded file locally
                FileStream localfileStream = new FileStream(configDate.BackUpPath + FileName, FileMode.Create, FileAccess.Write);

                //Get a reponse
                WebResponse response = request.GetResponse();
                Stream responseStream = response.GetResponseStream();

                //create the file
                byte[] buffer = new byte[1024];
                int bytesRead = responseStream.Read(buffer, 0, 1024);
                while (bytesRead != 0)
                {
                    localfileStream.Write(buffer, 0, bytesRead);
                    bytesRead = responseStream.Read(buffer, 0, 1024);
                }

                //clean up
                localfileStream.Close();
                response.Close();
                responseStream.Close();
            }
            catch (WebException wEx)
            {
                //Download Error
            }
            catch (Exception ex)
            {
                //Download Error
            }
        }
Пример #10
0
        public List<Device> getDevicesByTime(DateTime date)
        {
            string sql = "select * from bu_task inner join bu_task_device on bu_task.id = bu_task_device.bu_task_id where timefield ='" + date.ToString("HH:mm") + "' and datefield='" + date.ToString("yyyMMdd") + "'";
            DataSet ds = new MySqlDa().fillDataSet(sql);

            List<Device> lstDevice = new List<Device>();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                Device device = new Device();
                device.Id = (int)ds.Tables[0].Rows[i]["id"];
                device.IP = ds.Tables[0].Rows[i]["ip"].ToString();
                device.Name = ds.Tables[0].Rows[i]["name"].ToString();
                device.TypeId = (int)ds.Tables[0].Rows[i]["typeId"];
                device.BrandId = (int)ds.Tables[0].Rows[i]["brandId"];
                device.CellId = (int) ds.Tables[0].Rows[i]["cellId"];

                Cell cell = new Cell();
                cell.Id = (int)ds.Tables[0].Rows[i]["cellId"];
                cell.Name = ds.Tables[0].Rows[i][16].ToString();
                cell.CellNr = (int)ds.Tables[0].Rows[i]["CellNr"];
                device.Cell = cell;

                lstDevice.Add(device);
            }

            return lstDevice;
        }
Пример #11
0
        private Device fillDevice(DataSet ds,int iRow)
        {
            Device device = new Device();
            device.Id = (int)ds.Tables[0].Rows[iRow]["id"];
            device.IP = ds.Tables[0].Rows[iRow]["ip"].ToString();
            device.Name = ds.Tables[0].Rows[iRow]["name"].ToString();
            device.TypeId = (int)ds.Tables[0].Rows[iRow]["typeId"];
            device.BrandId = (int)ds.Tables[0].Rows[iRow]["brandId"];
            device.CellId = (int) ds.Tables[0].Rows[iRow]["cellId"];

            return device;
        }
Пример #12
0
        public void Save(Device device)
        {
            StringBuilder sql = new StringBuilder();
            if (device.Id > -1)
            {
                sql.Append("UPDATE bu_device SET ip='");
                sql.Append(device.IP);
                sql.Append("',name='"); sql.Append(device.Name);
                sql.Append("',cellId='"); sql.Append(device.CellId);
                sql.Append("',typeId='"); sql.Append(device.TypeId);
                sql.Append("',brandId='"); sql.Append(device.BrandId);
                sql.Append("' WHERE id="); sql.Append(device.Id);
            }
            else
            {
                sql.Append("INSERT INTO bu_device (ip, cellId, name,typeId,brandId) VALUES ('");
                sql.Append(device.IP);sql.Append("','");
                sql.Append(device.CellId);sql.Append("','");
                sql.Append(device.Name);sql.Append("','");
                sql.Append(device.TypeId);sql.Append("','");
                sql.Append(device.BrandId);sql.Append("'");
                sql.Append(");");
            }

            new MySqlDa().ExecuteNonQuery(sql.ToString());
        }