Click here to Skip to main content
15,867,453 members
Home / Discussions / C#
   

C#

 
AnswerRe: best way to license .net application Pin
thatraja12-Dec-13 6:26
professionalthatraja12-Dec-13 6:26 
GeneralRe: best way to license .net application Pin
PIEBALDconsult12-Dec-13 17:36
mvePIEBALDconsult12-Dec-13 17:36 
AnswerRe: best way to license .net application Pin
jschell13-Dec-13 9:55
jschell13-Dec-13 9:55 
SuggestionHow to set transparent on listbox Pin
Member 1026763012-Dec-13 0:52
Member 1026763012-Dec-13 0:52 
GeneralRe: How to set transparent on listbox Pin
Simon_Whale12-Dec-13 1:03
Simon_Whale12-Dec-13 1:03 
GeneralRe: How to set transparent on listbox Pin
Marco Bertschi12-Dec-13 1:20
protectorMarco Bertschi12-Dec-13 1:20 
GeneralRe: How to set transparent on listbox Pin
Member 1026763012-Dec-13 1:44
Member 1026763012-Dec-13 1:44 
Questionserial port data read Pin
Member 1026351912-Dec-13 0:15
Member 1026351912-Dec-13 0:15 
hi'
am developing project on hand held system,my view is : select the file(excel)by clicking browse. then click on upload.
here it's going to that device but after receiving data that device needs to send "$OK#" back to my program how can i receive that . plz help how to do tha
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Excel=Microsoft.Office.Interop.Excel;
using System.IO;
using System.Threading;
using System.IO.Ports;



namespace Hand_Held_Data_Transporter
{
    public partial class Form1 : Form
    {
        int[] stream_buffer;
      
        
        

        /*private static Microsoft.Office.Interop.Excel.Workbook mWorkBook;
        private static Microsoft.Office.Interop.Excel.Sheets mWorkSheets;
        private static Microsoft.Office.Interop.Excel.Worksheet mWSheet1;
        private static Microsoft.Office.Interop.Excel.Application oXL;*/

        public Form1()
        {
            InitializeComponent();
            progressBar1.Enabled = false;
            progressBar2.Enabled = false;

            serialPort1.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(serialPort1_DataReceived);
           
        }



        private void Browse_Click(object sender, EventArgs e)
        {

            OpenFileDialog fdlg = new OpenFileDialog();
            fdlg.Filter = "All Files(*.*)|*.*";
            if (fdlg.ShowDialog() == DialogResult.OK)
            {


                textBox1.Text = fdlg.FileName;
                File.ReadAllText(textBox1.Text);

            }
        }

       



        private void Upload_Click(object sender, EventArgs e)
        {

           // StringBuilder sb = new StringBuilder();
  

            Excel.Application xlApp = new Excel.Application();
            Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(textBox1.Text, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
            Excel._Worksheet xlWorksheet = (Excel._Worksheet)xlWorkbook.Sheets[1];
            Excel.Range xlRange = xlWorksheet.UsedRange;

            int rowCount = xlRange.Rows.Count;
            int colCount = xlRange.Columns.Count;
            progressBar1.Visible = true;
            

            int k = 100 / rowCount;

            for (int i = 1; i <= rowCount; i++)
            {

                String final = null;
                String upload1 = null, upload2 = null, upload3 = null, upload4 = null, upload5 = null,upload6=null,upload7=null;
                for (int j = 1; j <= colCount; j++)
                {

                    if (j == 1)
                      upload1 = xlRange.Cells[i, j].Value.ToString();
                 

                        //upload1 = xlRange.Cells[i, j].Value.ToString();
                    if (j == 2)
                        upload2 = xlRange.Cells[i, j].Value.ToString();
                   
                  
                    if (j == 3)
                        upload3 = xlRange.Cells[i, j].Value.ToString();
                
                    if (j == 4)
                        upload4= xlRange.Cells[i, j].Value.ToString();
                    
                     if (j == 5)
                         upload5 = xlRange.Cells[i, j].Value.ToString();
                     
                    if (j == 6)
                        upload6= xlRange.Cells[i, j].Value.ToString();
                    
                    if (j == 7)
                        upload7 = xlRange.Cells[i, j].Value.ToString();
                    

                    final = "$ POST," + upload1 + "," + upload2 + "," + upload3 + "," + upload4 + "," + upload5 + "," + upload6 + "," + upload7 + " # ";


                }

                if (serialPort1.IsOpen)

                   serialPort1.Write(final);
                serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);

                MessageBox.Show(final);
                if (progressBar1.Value < 100)
                {
                    Thread.Sleep(1000);
                    progressBar1.Value += k;
                }


            }
            progressBar1.Value = 100;

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            progressBar1.Visible = false;
            progressBar2.Visible = false;
           serialPort1.Open();
            
        }

        private void Download_Click(object sender, EventArgs e)
        {
            Excel.Application xlApp = default(Excel.Application);
            Excel.Workbook xlWorkBook = default(Excel.Workbook);
            Excel.Worksheet xlWorkSheet = default(Excel.Worksheet);
            serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
            string fName = @"C:\STL\Download\Download_" + DateTime.Now.ToString("dd MMM YY HH mm").Trim() + ".xls ";
            try
            {
           
                object misValue = System.Reflection.Missing.Value;
                xlApp = new Excel.Application();
                xlWorkBook = xlApp.Workbooks.Add(misValue);
                xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
                xlWorkSheet.Cells[1, 1] = "Name";
                xlWorkSheet.Cells[1, 2] = "ID Number";
                xlWorkSheet.Cells[1, 3] = "Installment";
                xlWorkSheet.Cells[1, 4] = "Paid Amount";
                xlWorkSheet.Cells[1, 5] = "Due Amount";

                xlWorkSheet.Cells[1, 1].Interior.ColorIndex = 39;
                xlWorkSheet.Cells[1, 2].Interior.ColorIndex = 39;
                xlWorkSheet.Cells[1, 3].Interior.ColorIndex = 39;
                xlWorkSheet.Cells[1, 4].Interior.ColorIndex = 39;
                xlWorkSheet.Cells[1, 5].Interior.ColorIndex = 39;

               // serialPort1.Open();
               // String s = "$GET,Chsum#";
               // if (serialPort1.IsOpen)
              //  {
                  //  serialPort1.WriteLine(s);
                    
                  // String s1= serialPort1.ReadLine();
                  // MessageBox.Show(s1);
               // }


                xlWorkBook.SaveAs(fName, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
                xlWorkBook.Close(true, misValue, misValue);
                xlApp.Quit();
                releaseObject(xlWorkSheet);
                releaseObject(xlWorkBook);
                releaseObject(xlApp);
            }
            finally
            {
                if (xlApp != null)
                    releaseObject(xlApp);
                if (xlWorkBook != null)
                    releaseObject(xlWorkBook);
                if (xlWorkSheet != null)
                    releaseObject(xlWorkSheet);
            }
            if (System.IO.File.Exists(fName))
            {
                if (MessageBox.Show("Would you like to open the excel file?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    try
                    {
                        System.Diagnostics.Process.Start(fName);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error opening the excel file." + Environment.NewLine +
                          ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            

            }
        private void releaseObject(object obj)
        {
            try
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
                obj = null;
            }
            catch (Exception ex)
            {
                obj = null;
                MessageBox.Show("Unable to release the Object " + ex.ToString());
            }
            finally
            {
                GC.Collect();
            }
        }

        private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            try
            {
                String inputdata = serialPort1.ReadExisting();
                MessageBox.Show(inputdata);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


            //this method will execute when buffer is full
          /*  stream_buffer[0] = serialPort1.ReadByte();   //read 1st byte
            stream_buffer[1] = serialPort1.ReadByte();   //read another byte and so on
            stream_buffer[2] = serialPort1.ReadByte();
            stream_buffer[3] = serialPort1.ReadByte();
            stream_buffer[4] = serialPort1.ReadByte();
            stream_buffer[5] = serialPort1.ReadByte();
            stream_buffer[6] = serialPort1.ReadByte();

             StreamWriter MyStreamWriter = new StreamWriter(@"c:\Testing.txt, true");
             for (int i = 0; i < 7;i++ )
                 MyStreamWriter.Write(stream_buffer[i]);

            MyStreamWriter.Flush();

            MyStreamWriter.Close();


            for (int j = 0; j < 7; j++)
                textBox1.Text = Convert.ToString(stream_buffer[j]);*/



        }

       

       
        }
    }
t.
AnswerRe: serial port data read Pin
Marco Bertschi12-Dec-13 1:22
protectorMarco Bertschi12-Dec-13 1:22 
QuestionHow to create an organizational chart in ASP with C# without api and HTML5 Pin
Member 1039478611-Dec-13 8:11
Member 1039478611-Dec-13 8:11 
AnswerRe: How to create an organizational chart in ASP with C# without api and HTML5 Pin
Dave Kreskowiak11-Dec-13 11:30
mveDave Kreskowiak11-Dec-13 11:30 
AnswerRe: How to create an organizational chart in ASP with C# without api and HTML5 Pin
Richard MacCutchan11-Dec-13 21:18
mveRichard MacCutchan11-Dec-13 21:18 
QuestionHow I can find selected control on any window from mouse click c# Pin
delphix510-Dec-13 4:57
delphix510-Dec-13 4:57 
AnswerRe: How I can find selected control on any window from mouse click c# Pin
Abhinav S10-Dec-13 5:09
Abhinav S10-Dec-13 5:09 
GeneralRe: How I can find selected control on any window from mouse click c# Pin
delphix510-Dec-13 5:16
delphix510-Dec-13 5:16 
GeneralRe: How I can find selected control on any window from mouse click c# Pin
Dave Kreskowiak10-Dec-13 5:43
mveDave Kreskowiak10-Dec-13 5:43 
GeneralRe: How I can find selected control on any window from mouse click c# Pin
delphix510-Dec-13 6:55
delphix510-Dec-13 6:55 
AnswerRe: How I can find selected control on any window from mouse click c# Pin
Eddy Vluggen10-Dec-13 8:06
professionalEddy Vluggen10-Dec-13 8:06 
AnswerRe: How I can find selected control on any window from mouse click c# Pin
BillWoodruff10-Dec-13 5:52
professionalBillWoodruff10-Dec-13 5:52 
GeneralRe: How I can find selected control on any window from mouse click c# Pin
delphix510-Dec-13 7:03
delphix510-Dec-13 7:03 
GeneralRe: How I can find selected control on any window from mouse click c# Pin
GuyThiebaut10-Dec-13 22:35
professionalGuyThiebaut10-Dec-13 22:35 
QuestionList<> VS Dictionary<,> Pin
HobbyProggy9-Dec-13 22:14
professionalHobbyProggy9-Dec-13 22:14 
AnswerRe: List<> VS Dictionary<,> Pin
Marco Bertschi9-Dec-13 22:24
protectorMarco Bertschi9-Dec-13 22:24 
AnswerRe: List<> VS Dictionary<,> Pin
Pete O'Hanlon9-Dec-13 22:59
subeditorPete O'Hanlon9-Dec-13 22:59 
GeneralRe: List<> VS Dictionary<,> Pin
HobbyProggy9-Dec-13 23:10
professionalHobbyProggy9-Dec-13 23:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.