Esempio n. 1
0
        private void btnOpenFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = @"D:\";
            openFileDialog1.Title            = "Browse Excel Files";

            openFileDialog1.CheckFileExists = true;
            openFileDialog1.CheckPathExists = true;

            openFileDialog1.DefaultExt = "xlsx";
            // openFileDialog1.Filter = "Excel files (*.xlsx)|*.xlsx|All files (*.*)|*.*";
            openFileDialog1.FilterIndex      = 2;
            openFileDialog1.RestoreDirectory = true;

            openFileDialog1.ReadOnlyChecked = true;
            openFileDialog1.ShowReadOnly    = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string file = openFileDialog1.FileName;


                try
                {
                    OpenFile(file);

                    selecta = new Vending();
                    //MessageBox.Show(DeviceList.Count().ToString());
                    lblNumberOfDevices.Text += DeviceList.Count().ToString();
                    string directoryPath = Path.GetDirectoryName(file);


                    string text = File.ReadAllText(file);
                    int    size = text.Length;
                }
                catch (IOException)
                {
                }
            }
        }
Esempio n. 2
0
        private void OpenFile(string path)
        {
            string filepath = Path.GetDirectoryName(path);
            string filename = Path.GetFileName(path);

            // MessageBox.Show(filename);
            sw      = new StreamWriter(filepath + "\\" + filename + ".txt");
            selecta = new Vending();
            Reader r = new Reader(path, 1);

            // MessageBox.Show(r.ReadFirstRow(1,1));
            RowNumber = r.CountRows();
            for (int i = 1; i <= RowNumber; i++)
            {
                selecta.UserName = r.ReadFirstRow(i, 1);
                selecta.PWD      = r.ReadFOurthRow(i, 1);
                selecta.IP       = r.ReadSeventhRow(i, 1);
                DeviceList.Add(selecta);

                // MessageBox.Show(selecta.UserName + " " + selecta.PWD + " " + selecta.IP);

                code = "                       INSERT INTO `radcheck` (`id`, `username`, `attribute`, `op`, `value`) VALUES(NULL, '" + selecta.UserName + @"@selecta.m2m', 'Cleartext-Password', ':=', '" + selecta.PWD + @"');
                        INSERT INTO `radreply` (`id`, `username`, `attribute`, `op`, `value`) VALUES(NULL, '" + selecta.UserName + @"@selecta.m2m', 'Framed-Protocol', ':=', 'PPP');
                        INSERT INTO `radreply` (`id`, `username`, `attribute`, `op`, `value`) VALUES(NULL, '" + selecta.UserName + @"@selecta.m2m', 'Service-Type', ':=', 'Framed-User');
                        INSERT INTO `radreply` (`id`, `username`, `attribute`, `op`, `value`) VALUES(NULL, '" + selecta.UserName + @"@selecta.m2m', 'Framed-IP-Netmask', ':=', '255.255.255.0');
                        INSERT INTO `radreply` (`id`, `username`, `attribute`, `op`, `value`) VALUES(NULL, '" + selecta.UserName + @"@selecta.m2m', 'Framed-IP-Address', ':=', '" + selecta.IP + @"');
                        INSERT INTO `radreply` (`id`, `username`, `attribute`, `op`, `value`) VALUES(NULL, '" + selecta.UserName + @"@selecta.m2m', 'Idle-Timeout', ':=', '900');";
                // MessageBox.Show(code);
                Write(code);
                code = " ";
            }
            lblNumberOfDevices.Visible = true;

            sw.Close();
            r.Close();
        }