Ejemplo n.º 1
0
        public FindPhoneForImportDataSet FindPhoneForImport(int intExtension)
        {
            try
            {
                aFindPhoneForImportDataSet      = new FindPhoneForImportDataSet();
                aFindPhoneForImportTableAdapter = new FindPhoneForImportDataSetTableAdapters.FindPhoneForImportTableAdapter();
                aFindPhoneForImportTableAdapter.Fill(aFindPhoneForImportDataSet.FindPhoneForImport, intExtension);
            }
            catch (Exception Ex)
            {
                TheEventLogClass.InsertEventLogEntry(DateTime.Now, "Phone Class // Find Phone For Import " + Ex.Message);
            }

            return(aFindPhoneForImportDataSet);
        }
        private void expImportCalls_Expanded(object sender, RoutedEventArgs e)
        {
            Excel.Application xlDropOrder;
            Excel.Workbook    xlDropBook;
            Excel.Worksheet   xlDropSheet;
            Excel.Range       range;

            int      intColumnRange = 0;
            int      intCounter;
            int      intNumberOfRecords;
            string   strCallType;
            string   strExtension;
            int      intExtension;
            string   strDialedDigits;
            string   strStartTime;
            DateTime datStartTime;
            string   strCallDuration;
            int      intPhoneID;
            int      intEmployeeID;
            string   strFirstName;
            string   strLastName;
            int      intRecordsReturned;
            double   douDate;
            bool     blnIsNotNumeric;
            double   douTime;

            try
            {
                expImportCalls.IsExpanded = false;
                TheImportedPhoneCallsDataSet.importedphonecalls.Rows.Clear();

                Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                dlg.FileName   = "Document";             // Default file name
                dlg.DefaultExt = ".xlsx";                // Default file extension
                dlg.Filter     = "Excel (.xlsx)|*.xlsx"; // Filter files by extension

                // Show open file dialog box
                Nullable <bool> result = dlg.ShowDialog();

                // Process open file dialog box results
                if (result == true)
                {
                    // Open document
                    string filename = dlg.FileName;
                }

                PleaseWait PleaseWait = new PleaseWait();
                PleaseWait.Show();

                xlDropOrder = new Excel.Application();
                xlDropBook  = xlDropOrder.Workbooks.Open(dlg.FileName, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
                xlDropSheet = (Excel.Worksheet)xlDropOrder.Worksheets.get_Item(1);

                range = xlDropSheet.UsedRange;
                intNumberOfRecords = range.Rows.Count;
                intColumnRange     = range.Columns.Count;

                for (intCounter = 1; intCounter <= intNumberOfRecords; intCounter++)
                {
                    strCallType     = Convert.ToString((range.Cells[intCounter, 1] as Excel.Range).Value2).ToUpper();
                    strExtension    = Convert.ToString((range.Cells[intCounter, 2] as Excel.Range).Value2).ToUpper();
                    strDialedDigits = Convert.ToString((range.Cells[intCounter, 4] as Excel.Range).Value2).ToUpper();
                    strStartTime    = Convert.ToString((range.Cells[intCounter, 5] as Excel.Range).Value2).ToUpper();
                    strCallDuration = Convert.ToString((range.Cells[intCounter, 6] as Excel.Range).Value2).ToUpper();

                    blnIsNotNumeric = TheDataValidationClass.VerifyIntegerData(strExtension);

                    if (blnIsNotNumeric == false)
                    {
                        intExtension = Convert.ToInt32(strExtension);

                        TheFindPhoneForImportDataSet = ThePhonesClass.FindPhoneForImport(intExtension);

                        intRecordsReturned = TheFindPhoneForImportDataSet.FindPhoneForImport.Rows.Count;

                        if (intRecordsReturned > 0)
                        {
                            intPhoneID    = TheFindPhoneForImportDataSet.FindPhoneForImport[0].TransactionID;
                            intEmployeeID = TheFindPhoneForImportDataSet.FindPhoneForImport[0].EmployeeID;

                            TheFindEmployeeByEmployeeIDDataSet = TheEmployeeClass.FindEmployeeByEmployeeID(intEmployeeID);

                            strFirstName = TheFindEmployeeByEmployeeIDDataSet.FindEmployeeByEmployeeID[0].FirstName;
                            strLastName  = TheFindEmployeeByEmployeeIDDataSet.FindEmployeeByEmployeeID[0].LastName;

                            douDate = Convert.ToDouble(strStartTime);

                            datStartTime = DateTime.FromOADate(douDate);

                            douTime = Convert.ToDouble(strCallDuration);

                            TimeSpan tspInterval = TimeSpan.FromDays(douTime);

                            strCallDuration = tspInterval.ToString();

                            ImportedPhoneCallsDataSet.importedphonecallsRow NewCallRow = TheImportedPhoneCallsDataSet.importedphonecalls.NewimportedphonecallsRow();

                            NewCallRow.CallDuration   = strCallDuration;
                            NewCallRow.CallType       = strCallType;
                            NewCallRow.DialedDigits   = strDialedDigits;
                            NewCallRow.PhoneExtension = intExtension;
                            NewCallRow.EmployeeID     = intEmployeeID;
                            NewCallRow.FirstName      = strFirstName;
                            NewCallRow.LastName       = strLastName;
                            NewCallRow.PhoneID        = intPhoneID;
                            NewCallRow.StartTime      = datStartTime;

                            TheImportedPhoneCallsDataSet.importedphonecalls.Rows.Add(NewCallRow);
                        }
                    }
                }

                dgrPhoneCalls.ItemsSource = TheImportedPhoneCallsDataSet.importedphonecalls;
                PleaseWait.Close();
            }
            catch (Exception Ex)
            {
                TheEventLogClass.InsertEventLogEntry(DateTime.Now, "New Blue Jay ERP // Import Phone Calls // Import Excel  " + Ex.Message);

                TheMessagesClass.ErrorMessage(Ex.ToString());
            }
        }