Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1247
  • Last Modified:

I am trying to create desktop application using C# to Read Call information for Panasonic PBX, are ther any sample code?

I am trying to create desktop application using C# to Read Call information, just i need dat and duration and extintion number for Panasonic PBX, are ther any sample code to learn how to access the port and read this data? also the pin assignment i think it may be like that for searial port:
2------------------------3
3-----------------------2
4-----------------------6
5-----------------------5
6-----------------------4
7-----------------------8
8-----------------------7
0
alaamh77
Asked:
alaamh77
  • 5
  • 4
1 Solution
 
topdog770Commented:
This sample won't compile, but it's a fairly complete example of how I did  a serial port to PBX app a long time ago, so the coding style is a bit rough.  Let me know if you have questions.

    public delegate void AppReceivedSerialDataDelegate( string Data );
    public partial class FormMain : Form
    {
        public static event AppReceivedSerialDataDelegate AppReceivedDataEvent;

        SerialPort serialPort = new SerialPort( "COM1", 300, Parity.Even, 7, StopBits.One );

        private FormSerialData formSerialData = new FormSerialData( );

        RawDataProcessor rawDataProcessor = new RawDataProcessor( );

        bool bInErrorCondition = false;

        public FormMain()
        {
            InitializeComponent( );

            if (this.developmentToolStripMenuItem != null)
            {
                this.developmentToolStripMenuItem.Visible = BWCDbInfo.IsBWCDEV_DatabaseAvailable( );
            }

            serialPort.ErrorReceived += new SerialErrorReceivedEventHandler( serialPort_ErrorReceived );
            serialPort.DataReceived += new SerialDataReceivedEventHandler( serialPort_DataReceived );
            serialPort.PinChanged += new SerialPinChangedEventHandler( serialPort_PinChanged );
        }

        private void ApplyStartupSettings()
        {
            BwcConfig.ReadRegistryStartUpOptions( );

            if (BwcConfig.MainFormStartMaximized == true)
            {

            }
            else
            {
                this.Top = BwcConfig.MainFormTop;
                this.Left = BwcConfig.MainFormLeft;
                this.Width = BwcConfig.MainFormWidth;
                this.Height = BwcConfig.MainFormHeight;
            }

            if (!BWCDbInfo.IsBWCDEV_DatabaseAvailable( )
                && BwcConfig.CurrentDbInfo.ActiveDB == BWCDatabaseLocations.DEVBWC)
            {
                // if the current user no longer has access to the development database and
                // it was the database they last used... load the production db instead
                BwcConfig.CurrentDbInfo.ActiveDB = BWCDatabaseLocations.OFFBWC;
            }
            this.ConfigureCommPort( );
        }

        bool bCloseApplicationPerformed = false;
        private void CloseApplication()
        {
            if (!bCloseApplicationPerformed)
            {
                bCloseApplicationPerformed = true;
                BwcConfig.WriteRegistryStartUpOptions( );

                if (this.serialPort != null && this.serialPort.IsOpen)
                {
                    serialPort.Close( );
                }

                Error.SendEmailMessage( "CallCap Application Was Closed", "The CallCap application was intentionally closed by an user" );
                Application.Exit( );
            }
        }


        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            DataSet ds = new DataSet();
            ds.Tables.Add( DbWriter.ErrorTable.Copy() );
            ds.WriteXml( DbWriter.LogFile );
            this.CloseApplication( );
        }

        public void Init()
        {
            this.Text = BwcConfig.ApplicationName;

            ApplyStartupSettings( );

            formSerialData.TopLevel = false;
            formSerialData.Dock = DockStyle.Fill;

            FormMain.dtAppStartTime = DateTime.Now;
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            try
            {              
                Init();
                formSerialData.Show( );
                Application.DoEvents( );

                Go( );          
            }
            catch (Exception ex)
            {
                Error.SendEmailMessage( "CallCap Error", "Error Starting Application\r\n" + ex.Message + "\r\n" + ex.StackTrace );
            }
            finally
            {
               
            }
        }

        void serialPort_PinChanged(object sender, SerialPinChangedEventArgs e)
        {
            this.bInErrorCondition = true;

            if (serialPort.IsOpen )
            {
                serialPort.Close( );
            }

            Error.SendEmailMessage( "Call Capp Serial Error", "The connection from Call Cap to the PBX was broken" );

            this.Go( );
        }

        void serialPort_ErrorReceived(object sender, SerialErrorReceivedEventArgs e)
        {
            throw new Exception( "The method or operation is not implemented." );
        }

        void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            try
            {
                DoUpdate( sender, e );
            }
            catch (Exception ex)
            {
                bInErrorCondition = true;
                Error.SendEmailMessage( "Call Cap Error", "Communication to PBX was lost while reading from the Serial Port" );
                this.Go( );
            }
        }

        static string sDataFromSerialPort = "";

        private void DoUpdate(object s, EventArgs e)
        {
            if (InvokeRequired)
            {
                this.BeginInvoke( new EventHandler( DoUpdate ) );
            }
            else
            {
                this.DisplayProgramActivity( "Getting Data!" );
                this.statusStrip1.Refresh( );
                sDataFromSerialPort = serialPort.ReadExisting( );

                if (sDataFromSerialPort.Length > 0 && AppReceivedDataEvent != null)
                {
                    AppReceivedDataEvent( sDataFromSerialPort );
                }
            }
        }

        private void cOMMPORT1ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ChangeCommPort( 1 );
        }

        private void cOMMPORT2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ChangeCommPort( 2 );
        }

        private void cOMMPORT3ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ChangeCommPort( 3 );
        }

        private void cOMMPORT4ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ChangeCommPort( 4 );
        }

        private void ChangeCommPort(int iPortNumber)
        {
            if (this.serialPort.IsOpen )
            {
                serialPort.Close( );
            }
            BwcConfig.CommPort = "COM" + iPortNumber.ToString( );
            serialPort.PortName = BwcConfig.CommPort;
            this.Go( );
        }

        private void ConfigureCommPort()
        {
            //serialPort.Handshake = Handshake.RequestToSend;

            serialPort.BaudRate = 300;
            serialPort.DtrEnable = true;      // change to true
            serialPort.RtsEnable = false; // change to true
            serialPort.Encoding = new System.Text.ASCIIEncoding( );

            serialPort.ReadTimeout = 100;
            serialPort.ReceivedBytesThreshold = 1;
            serialPort.Parity = Parity.Even;
            serialPort.DataBits = 7;
            serialPort.StopBits = StopBits.One;
            serialPort.Handshake = Handshake.None;
            serialPort.ReadBufferSize = 1024;
            serialPort.PortName = BwcConfig.CommPort;
        }
       
        static DateTime dtStartOfLastGo;

        private void Go()
        {
            dtStartOfLastGo = DateTime.Now;

            try
            {
                DisplayProgramActivity( "Starting communication process" );

                bool bError = true;

                if (serialPort.IsOpen)
                {
                    bError = false;
                    return;
                }

                DisplayProgramActivity( "Opening Serial Port " + serialPort.PortName );
                serialPort.Open( );

                DisplayProgramActivity( "Serial Port " + serialPort.PortName + " opened" );

                DisplayProgramActivity( "Checking for logged calls" );
                DataSet ds = new DataSet( );
                ds.ReadXml( DbWriter.LogFile );

                DisplayProgramActivity( "Recovered " + ds.Tables.Count.ToString( ) + " logged calls" );
                if (ds.Tables.Count > 0)
                {
                    PhoneData.PHO_PHONE_CALLSDataTable dt = (PhoneData.PHO_PHONE_CALLSDataTable)ds.Tables[ 0 ];
                    foreach (PhoneData.PHO_PHONE_CALLSRow row in dt.Rows)
                    {
                        ((PhoneData.PHO_PHONE_CALLSDataTable)(this.formSerialData.dg.DataSource)).Rows.Add( row );

                    }
                }

                DisplayProgramActivity( "Finished checking for logged calls" );

                DisplayProgramActivity( "Communicating with the PBX" );
                SignalPBX_StartDataFeed( );

                if (bInErrorCondition == true)
                {
                    // this time it succeeded, send out an email notifying users that we are working again!
                    Error.SendEmailMessage( "CallCap Resumed Operation", "Program is now monitoring calls");
                }
                bInErrorCondition = false;
            }
            catch (Exception ex)
            {
                DisplayProgramActivity( ex.Message );

                if (bInErrorCondition == false)
                {
                    bInErrorCondition = true;
                    Error.SendEmailMessage( "CallCap Error", ex.Message + "\r\n" + ex.StackTrace );
                }
            }
        }

        bool SignalPBX_StartDataFeed()
        {
            try
            {
                DisplayProgramActivity( "Signaling PBX to Start" );
                // --------------------------------
                // Display Program Activity

                // Send DS2 (char)18 to signal PBX we
                // are ready to receive data

                char c18 = (char)18;
                char [] ar = { c18, '\0' };
                this.serialPort.Write( ar, 0, ar.Length );
                System.Threading.Thread.Sleep( 500 );
            }
            catch (Exception ex)
            {
                Error.SendEmailMessage( "CallCap Error", "Error Starting Communications With Serial Port\r\n" + ex.Message + "\r\n" + ex.StackTrace );
            }

            return true;
        }

        bool SignalPBX_StopDataFeed()
        {
              DisplayProgramActivity("Signaling PBX to Stop");      
              // --------------------------------
              // Display Program Activity

            // Send DS2 (char)18 to signal PBX we
            // are ready to receive data
            serialPort.WriteLine( BwcConfig.SERIAL_PORT_STOP_CHAR.ToString() );
            System.Threading.Thread.Sleep( 500 );

            return true;
        }
    }
0
 
alaamh77Author Commented:
Dear
How i can extract information to save into it database from this line, i need call duration and caller number
this.serialPort.Write(ar, 0, ar.Length);

and what is this:
FormSerialData , RawDataProcessor

i know i am asking you more than one point, sorry.
Thanks
0
 
topdog770Commented:
Ok, it's a bit messy but here's the remaining, primary code, it show how I was pulling out the specific pieces of data from the serial data and writing it into the the database
    public class RawDataProcessor
    {
        private string _sCleanDataString = "";
        public static event AppReceivedSerialDataDelegate ProcessedDataStringEvent;
 
        public RawDataProcessor()
        {
            FormMain.AppReceivedDataEvent += new AppReceivedSerialDataDelegate( FormMain_AppReceivedDataEvent );
        }
 
        void FormMain_AppReceivedDataEvent(string Data)
        {
            foreach (char c in Data.ToCharArray( ))
            {
                if (c > 31 && c < 127)
                {
                    _sCleanDataString += c.ToString( );
                }
 
                if (c == 13) // end of transmit string
                {
                    _sCleanDataString = _sCleanDataString.Trim( );
                    if (ProcessedDataStringEvent != null && _sCleanDataString.Length > 1 && _sCleanDataString != "PRINTER FAIL")
                    {
                        ProcessedDataStringEvent( _sCleanDataString );
                    }
                    _sCleanDataString = "";
                }
            }
        }
    }
 
 
    public partial class FormSerialData : Form
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;
 
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose( );
            }
            base.Dispose( disposing );
        }
 
        #region Windows Form Designer generated code
 
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.dg = new System.Windows.Forms.DataGridView( );
            this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn( );
            this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn( );
            this.Column8 = new System.Windows.Forms.DataGridViewTextBoxColumn( );
            this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn( );
            this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn( );
            this.Column5 = new System.Windows.Forms.DataGridViewTextBoxColumn( );
            this.Column6 = new System.Windows.Forms.DataGridViewTextBoxColumn( );
            this.Column7 = new System.Windows.Forms.DataGridViewTextBoxColumn( );
            ((System.ComponentModel.ISupportInitialize)(this.dg)).BeginInit( );
            this.SuspendLayout( );
            // 
            // dg
            // 
            this.dg.AllowUserToAddRows = false;
            this.dg.AllowUserToDeleteRows = false;
            this.dg.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.dg.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dg.Columns.AddRange( new System.Windows.Forms.DataGridViewColumn[] {
            this.Column1,
            this.Column2,
            this.Column8,
            this.Column3,
            this.Column4,
            this.Column5,
            this.Column6,
            this.Column7} );
            this.dg.Location = new System.Drawing.Point( 23, 22 );
            this.dg.Name = "dg";
            this.dg.RowHeadersVisible = false;
            this.dg.Size = new System.Drawing.Size( 571, 196 );
            this.dg.TabIndex = 0;
            this.dg.RowsAdded += new System.Windows.Forms.DataGridViewRowsAddedEventHandler( this.dg_RowsAdded );
            // 
            // Column1
            // 
            this.Column1.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
            this.Column1.DataPropertyName = "CALL_DATE_TIME";
            this.Column1.FillWeight = 6F;
            this.Column1.HeaderText = "Time";
            this.Column1.Name = "Column1";
            this.Column1.ReadOnly = true;
            this.Column1.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column1.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
            this.Column1.Width = 36;
            // 
            // Column2
            // 
            this.Column2.DataPropertyName = "EXTENSION";
            this.Column2.HeaderText = "Ext";
            this.Column2.Name = "Column2";
            this.Column2.ReadOnly = true;
            this.Column2.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column2.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
            // 
            // Column8
            // 
            this.Column8.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
            this.Column8.DataPropertyName = "DURATION";
            this.Column8.HeaderText = "Call Duration";
            this.Column8.Name = "Column8";
            this.Column8.ReadOnly = true;
            this.Column8.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column8.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
            this.Column8.Width = 73;
            // 
            // Column3
            // 
            this.Column3.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
            this.Column3.DataPropertyName = "TRUNK";
            this.Column3.HeaderText = "Trunk";
            this.Column3.Name = "Column3";
            this.Column3.ReadOnly = true;
            this.Column3.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column3.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
            this.Column3.Width = 41;
            // 
            // Column4
            // 
            this.Column4.DataPropertyName = "PRE_CODE";
            this.Column4.HeaderText = "PreCode";
            this.Column4.Name = "Column4";
            this.Column4.ReadOnly = true;
            this.Column4.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column4.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
            // 
            // Column5
            // 
            this.Column5.DataPropertyName = "AREA_CODE";
            this.Column5.HeaderText = "Area Code";
            this.Column5.Name = "Column5";
            this.Column5.ReadOnly = true;
            this.Column5.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column5.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
            // 
            // Column6
            // 
            this.Column6.DataPropertyName = "PREFIX";
            this.Column6.HeaderText = "Prefix";
            this.Column6.Name = "Column6";
            this.Column6.ReadOnly = true;
            this.Column6.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column6.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
            // 
            // Column7
            // 
            this.Column7.DataPropertyName = "SUFFIX";
            this.Column7.HeaderText = "Suffix";
            this.Column7.Name = "Column7";
            this.Column7.ReadOnly = true;
            this.Column7.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.Column7.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
            // 
            // FormSerialData
            // 
            this.ClientSize = new System.Drawing.Size( 617, 241 );
            this.ControlBox = false;
            this.Controls.Add( this.dg );
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.Name = "FormSerialData";
            this.Load += new System.EventHandler( this.FormSerialData_Load );
            ((System.ComponentModel.ISupportInitialize)(this.dg)).EndInit( );
            this.ResumeLayout( false );
 
        }
 
        #endregion
 
        public System.Windows.Forms.DataGridView dg;
        private System.Windows.Forms.DataGridViewTextBoxColumn Column1;
        private System.Windows.Forms.DataGridViewTextBoxColumn Column2;
        private System.Windows.Forms.DataGridViewTextBoxColumn Column8;
        private System.Windows.Forms.DataGridViewTextBoxColumn Column3;
        private System.Windows.Forms.DataGridViewTextBoxColumn Column4;
        private System.Windows.Forms.DataGridViewTextBoxColumn Column5;
        private System.Windows.Forms.DataGridViewTextBoxColumn Column6;
        private System.Windows.Forms.DataGridViewTextBoxColumn Column7;
 
        PhoneData.PHO_PHONE_CALLSDataTable _dtPhoneCalls = new PhoneData.PHO_PHONE_CALLSDataTable( );
 
 
        public FormSerialData()
        {
            InitializeComponent( );
 
            dg.DataSource = _dtPhoneCalls;
        }
 
        private void FormSerialData_Load(object sender, EventArgs e)
        {
            RawDataProcessor.ProcessedDataStringEvent +=new AppReceivedSerialDataDelegate(RawDataProcessor_ProcessedDataStringEvent);
        }
 
        void RawDataProcessor_ProcessedDataStringEvent(string Data)
        {
            AddToDataGrid( Data );
        }
 
        void AddToDataGrid(string source)
        {
            if (source.Length < 54)
            {
                return;
            }
 
            DateTime dt = DateTime.Now;
 
            int iHours = 0;
            int iMinutes = 0;
 
            string sTime = source.Substring( 0, 5 );
 
            string sHours = source.Substring( 0, 2 );
            string sMinutes = source.Substring( 3, 2 );
            if (sHours.Length > 0)
            {
                try
                {
                    iHours = Convert.ToInt32( sHours );
                }
                catch
                {
                }
            }
 
            if (sMinutes.Length > 0)
            {
                try
                {
                    iMinutes = Convert.ToInt32( sMinutes );
                }
                catch
                {
                }
            }
 
            PhoneData.PHO_PHONE_CALLSRow r = _dtPhoneCalls.NewPHO_PHONE_CALLSRow( );
 
            DateTime logTime = new DateTime( DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day,
                                             iHours, iMinutes, DateTime.Now.Second );
            r.CALL_DATE_TIME = logTime;
            r.EXTENSION = source.Substring( 18, 3 );
 
            decimal duration = 0M;
            string sDuration = "";
            try
            {
                decimal hr = 0;
                decimal min = 0;
                decimal sec = 0;
 
                string sDuration_Hours = source.Substring( 6, 2 );
                string sDuration_Minutes = source.Substring( 9, 2 );
                string sDuration_Seconds = source.Substring( 13, 2 );
 
                if (sDuration_Hours.Length > 0)
                {
                    hr = Convert.ToDecimal( sDuration_Hours );
                    sDuration += String.Format("{0} hour(s), ", hr );
                }
                if (sDuration_Minutes.Length > 0)
                {
                    min = Convert.ToDecimal( sDuration_Minutes );
                    sDuration += String.Format("{0} min(s), ", min );
                }
                if (sDuration_Seconds.Length > 0)
                {
                    sec = Convert.ToDecimal( sDuration_Seconds );
                    if( sec > 0 )
                    {
                        sDuration += String.Format( "{0} seconds, ", sec );
                        sec *= 0.1M;                        
                    }
                }
 
                hr = hr * 60;
                min += hr;
                duration = min + sec;
            }
            catch
            {
            }
 
            r.DURATION = duration;
            r.TRUNK = source.Substring( 23, 5 );
            //string sPreCode = source.Substring( 28, 1 );
 
            r.PRE_CODE = source.Substring( 43, 1 );
            r.AREA_CODE = source.Substring( 44, 3 );
            r.PREFIX = source.Substring( 47, 3 );
            r.SUFFIX = source.Substring( 50, 4 );
 
 
            if (r.AREA_CODE == "900")
            {
                string sMessage = "The call was made at " + r.CALL_DATE_TIME.ToLongTimeString() + " from extension (" + r.EXTENSION + ") on trunk (" + r.TRUNK + ")." + "\r\nThe call duration was " + sDuration;
                sMessage += "\r\nThe number called was (" + r.AREA_CODE + ") " + r.PREFIX + "-" + r.SUFFIX;
                Error.Send900Message( sMessage );
            }
 
            try
            {
                this._dtPhoneCalls.AddPHO_PHONE_CALLSRow( r );
            }
            catch (Exception ex)
            {
                Error.SendEmailMessage( "Non-Critical CallCap Error", "Error Adding Phone Record Row\r\n" + ex.Message + "\r\n" + ex.StackTrace );
            }
        }
 
        private void dg_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
        {
            for (int a = 0; a < e.RowCount; a++)
            {
                PhoneData.PHO_PHONE_CALLSRow r = _dtPhoneCalls.Rows[ e.RowIndex + a ] as PhoneData.PHO_PHONE_CALLSRow;
                if (r != null)
                {
                    DbWriter.Write( r );
                }
            }
 
            if (_dtPhoneCalls.Rows.Count > 25)
            {
                _dtPhoneCalls.Rows.Clear( );
            }
        }
    }
 
 
    class DbWriter
    {
        public static readonly string LogFile = "UnwrittenCalls.xml";
 
        static readonly string sql = @"INSERT INTO pho_phone_calls 
	      (call_date_time, extension, duration, trunk, 
	      pre_code, area_code, prefix, suffix) 
	      VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
 
        public static PhoneData.PHO_PHONE_CALLSDataTable ErrorTable = new PhoneData.PHO_PHONE_CALLSDataTable( );
    
        static OleDbCommand cmd = new OleDbCommand( sql );
        static OleDbConnection conn = new OleDbConnection( );
        
        public static bool Write(PhoneData.PHO_PHONE_CALLSRow row)
        {          
            if (row == null)
            {
                return false;
            }
 
            try
            {
                if (!cmd.Parameters.Contains( "call_date_time" ))
                {
                    cmd.Parameters.Add( new OleDbParameter( "call_date_time", row.CALL_DATE_TIME ) );
                }
                else
                {
                    cmd.Parameters[ "call_date_time" ].Value = row.CALL_DATE_TIME;
                }
 
                if (!cmd.Parameters.Contains( "extension" ))
                {
                    cmd.Parameters.Add( new OleDbParameter( "extension", row.EXTENSION ) );
                }
                else
                {
                    cmd.Parameters[ "extension" ].Value = row.EXTENSION;
                }
 
                if (!cmd.Parameters.Contains( "duration" ))
                {
                    cmd.Parameters.Add( new OleDbParameter( "duration", row.DURATION ) );
                }
                else
                {
                    cmd.Parameters[ "duration" ].Value = row.DURATION;
                }
 
                if (!cmd.Parameters.Contains( "trunk" ))
                {
                    cmd.Parameters.Add( new OleDbParameter( "trunk", row.TRUNK ) );
                }
                else
                {
                    cmd.Parameters[ "trunk" ].Value = row.TRUNK;
                }
 
                if (!cmd.Parameters.Contains( "pre_code" ))
                {
                    cmd.Parameters.Add( new OleDbParameter( "pre_code", row.PRE_CODE ) );
                }
                else
                {
                    cmd.Parameters[ "pre_code" ].Value = row.PRE_CODE;
                }
 
                if (!cmd.Parameters.Contains( "area_code" ))
                {
                    cmd.Parameters.Add( new OleDbParameter( "area_code", row.AREA_CODE ) );
                }
                else
                {
                    cmd.Parameters[ "area_code" ].Value = row.AREA_CODE;
                }
 
                if (!cmd.Parameters.Contains( "prefix" ))
                {
                    cmd.Parameters.Add( new OleDbParameter( "prefix", row.PREFIX ) );
                }
                else
                {
                    cmd.Parameters[ "prefix" ].Value = row.PREFIX;
                }
 
                if (!cmd.Parameters.Contains( "suffix" ))
                {
                    cmd.Parameters.Add( new OleDbParameter( "suffix", row.SUFFIX ) );
                }
                else
                {
                    cmd.Parameters[ "suffix" ].Value = row.SUFFIX;
                }
 
                System.Diagnostics.Debug.Assert( cmd.Parameters.Count == 8, "Incorrect Parameter Count in DbWriter.Write" );
 
                OleDbConnection conn = new OleDbConnection( BwcConfig.CurrentDbInfo.ConnectionString );
                conn.Open( );
                cmd.Connection = conn;
                cmd.ExecuteNonQuery( );
                conn.Close( );
                return true;
            }
            catch (OleDbException dbex)
            {
                int iErrorCode = dbex.ErrorCode;
                Type e = dbex.GetType( );
                DbWriter.ErrorTable.ImportRow( row );
                Error.SendEmailMessage("Writing to Database failed", "The current db is: " + BwcConfig.CurrentDbInfo.ActiveDB.ToString() + ".\r\n" + dbex.Message + "\r\n" + dbex.StackTrace);
            }
            catch (Exception ex)
            {
                Type e = ex.GetType( );
                DbWriter.ErrorTable.ImportRow( row );
                Error.SendEmailMessage("Writing to Database failed", "The current db is: " + BwcConfig.CurrentDbInfo.ActiveDB.ToString() + ".\r\n" + ex.Message + "\r\n" + ex.StackTrace);
            }
            finally
            {
                if( conn != null && conn.State == ConnectionState.Open  )
                {
                    conn.Close( );
                }
            }
            return false;
        }    
    }
 
 
        public partial class PHO_PHONE_CALLSDataTable : System.Data.DataTable, System.Collections.IEnumerable {
            
            private System.Data.DataColumn columnCALL_DATE_TIME;
            
            private System.Data.DataColumn columnEXTENSION;
            
            private System.Data.DataColumn columnDURATION;
            
            private System.Data.DataColumn columnTRUNK;
            
            private System.Data.DataColumn columnPRE_CODE;
            
            private System.Data.DataColumn columnAREA_CODE;
            
            private System.Data.DataColumn columnPREFIX;
            
            private System.Data.DataColumn columnSUFFIX;
            
            [System.Diagnostics.DebuggerNonUserCodeAttribute()]
            public PHO_PHONE_CALLSDataTable() {
                this.TableName = "PHO_PHONE_CALLS";
                this.BeginInit();
                this.InitClass();
                this.EndInit();
            }
 
            private void InitClass() {
                this.columnCALL_DATE_TIME = new System.Data.DataColumn("CALL_DATE_TIME", typeof(System.DateTime), null, System.Data.MappingType.Element);
                base.Columns.Add(this.columnCALL_DATE_TIME);
                this.columnEXTENSION = new System.Data.DataColumn("EXTENSION", typeof(string), null, System.Data.MappingType.Element);
                base.Columns.Add(this.columnEXTENSION);
                this.columnDURATION = new System.Data.DataColumn("DURATION", typeof(decimal), null, System.Data.MappingType.Element);
                base.Columns.Add(this.columnDURATION);
                this.columnTRUNK = new System.Data.DataColumn("TRUNK", typeof(string), null, System.Data.MappingType.Element);
                base.Columns.Add(this.columnTRUNK);
                this.columnPRE_CODE = new System.Data.DataColumn("PRE_CODE", typeof(string), null, System.Data.MappingType.Element);
                base.Columns.Add(this.columnPRE_CODE);
                this.columnAREA_CODE = new System.Data.DataColumn("AREA_CODE", typeof(string), null, System.Data.MappingType.Element);
                base.Columns.Add(this.columnAREA_CODE);
                this.columnPREFIX = new System.Data.DataColumn("PREFIX", typeof(string), null, System.Data.MappingType.Element);
                base.Columns.Add(this.columnPREFIX);
                this.columnSUFFIX = new System.Data.DataColumn("SUFFIX", typeof(string), null, System.Data.MappingType.Element);
                base.Columns.Add(this.columnSUFFIX);
                this.Constraints.Add(new System.Data.UniqueConstraint("Constraint1", new System.Data.DataColumn[] {
                                this.columnCALL_DATE_TIME,
                                this.columnEXTENSION}, true));
                this.columnCALL_DATE_TIME.AllowDBNull = false;
                this.columnEXTENSION.AllowDBNull = false;
                this.columnEXTENSION.MaxLength = 3;
                this.columnTRUNK.MaxLength = 6;
                this.columnPRE_CODE.MaxLength = 6;
                this.columnAREA_CODE.MaxLength = 3;
                this.columnPREFIX.MaxLength = 3;
                this.columnSUFFIX.AllowDBNull = false;
                this.columnSUFFIX.MaxLength = 4;
            }
 
}

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
alaamh77Author Commented:
Dear
Thanks very mush for this solution, i have little qustion, what about the variable "PhoneData"
Thanks
0
 
alaamh77Author Commented:
Dear
also i see BwcConfig but i need to know more about it
Thanks
0
 
topdog770Commented:
The PhoneData object is my typed dataset.  I included part of the code at the bottom so  you could see the columns that made up the PHO_PHONE_CALLSDataTable.

The BwcConfig is my object that stores configuration and application settings information.
0
 
alaamh77Author Commented:
Dear
i search the code again but i didn't see the part that decleare dataset PHO_PHONE_CALLSDataTable,
also if you can let me know the structure of BwcConfig because you do new idea to me.

thanks
0
 
topdog770Commented:
Yeah, i just added the  public partial class PHO_PHONE_CALLSDataTable which shows what columns and the column types;

I'm including the BwcConfig class it's a very simple wrapper to store configuration stuff.
    public static class BwcConfig
    {
        public static readonly string ApplicationName = "MillOrder";
 
        public static bool MainFormStartMaximized = true;
        public static int MainFormLeft = 0;
        public static int MainFormTop = 0;
        public static int MainFormWidth = 0;
        public static int MainFormHeight = 0;
 
        public static bool MainFormLeftPanelShowExpanded = true;
        public static int MainFormLeftPanelWidth = 120;
 
        public static readonly string RegistryKey = @"Software\BRIGHT WOOD\" + ApplicationName.ToUpper( );
        public static BWCDbInfo CurrentDbInfo = new BWCDbInfo( BWCDatabaseLocations.OFFBWC ); 
 
 
        public static void ReadRegistryStartUpOptions()
        {
            RegistryKey regKey = Registry.CurrentUser.CreateSubKey( BwcConfig.RegistryKey );
 
            try
            {
                string sTempActiveDB = regKey.GetValue( "Current_Database", CurrentDbInfo.ActiveDB ).ToString( );
                CurrentDbInfo.ActiveDB = CurrentDbInfo.StringToLocationEnum( sTempActiveDB );
 
                MainFormStartMaximized = ((int)regKey.GetValue( "Startup_ShowMaximized", 1 ) != 0 ? true : false);
 
                // store main form size & position values
                MainFormLeft = Convert.ToInt32( regKey.GetValue( "MainForm_WindowPos_Left", MainFormLeft ) );
                MainFormTop = Convert.ToInt32( regKey.GetValue( "MainForm_WindowPos_Top", MainFormTop ) );
                MainFormWidth = Convert.ToInt32( regKey.GetValue( "MainForm_WindowPos_Width", MainFormWidth ) );
                MainFormHeight = Convert.ToInt32( regKey.GetValue( "MainForm_WindowPos_Height", MainFormHeight ) );
 
                MainFormLeftPanelShowExpanded = ((int)regKey.GetValue( "MainForm_Panel1_ShowExpanded", MainFormLeftPanelShowExpanded ) != 0 ? true : false);
                MainFormLeftPanelWidth = Convert.ToInt32( regKey.GetValue( "MainForm_Panel1_Width", MainFormLeftPanelWidth ) );
            }
            catch (Exception e)
            {
                string s = e.Message;
            }
            regKey.Close( );
        }
 
        public static void WriteRegistryStartUpOptions()
        {
            RegistryKey regKey = Registry.CurrentUser.CreateSubKey( BwcConfig.RegistryKey );
 
            try
            {
                regKey.SetValue( "Current_Database", CurrentDbInfo.ActiveDB.ToString( ) );
 
                regKey.SetValue( "Startup_ShowMaximized", MainFormStartMaximized == true ? 1 : 0 );
 
                // store main form size & position values
                regKey.SetValue( "MainForm_WindowPos_Left", MainFormLeft );
                regKey.SetValue( "MainForm_WindowPos_Top", MainFormTop );
                regKey.SetValue( "MainForm_WindowPos_Width", MainFormWidth );
                regKey.SetValue( "MainForm_WindowPos_Height", MainFormHeight );
 
                regKey.SetValue( "MainForm_Panel1_ShowExpanded", MainFormLeftPanelShowExpanded == true ? 1 : 0 );
                regKey.SetValue( "MainForm_Panel1_Width", MainFormLeftPanelWidth );
 
                regKey.Close( );
            }
            catch
            {
 
            }
        }
 
        public static string MoConnectionString
        {
            get
            {
                return CurrentDbInfo.MoConnectionString;
            }
        }
 
        public static string AckConnectionString
        {
            get
            {
                return CurrentDbInfo.AckConnectionString;
            }
        }
    }

Open in new window

0
 
alaamh77Author Commented:
Thanks Mr. topdog770
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now