コード例 #1
0
        private void saveFileTypeButton_Click(object sender, EventArgs e)
        {
            try
            {
                SettingsDAO settingsDAO = new SettingsDAO(ConfigurationDatabase);
                settingsDAO.Delete(FileTypeID);

                settingsDAO.Insert(new Settings(FileTypeID, useFileNameCheckBox.Checked, useFileExtensionCheckBox.Checked, textToIgnoreFileNameTextBox.Text, dateTimeFormatFileNameTextBox.Text, textToIgnoreFileExtensionTextBox.Text, dateTimeFormatFileExtensionTextBox.Text, linkDateTimeCheckBox.Checked, dateTimeColumnTextBox.Text, dateTimeFormatLinkDateTextBox.Text, truncateTableCheckBox.Checked));

                ColumnDAO columnDAO = new ColumnDAO(ConfigurationDatabase);
                columnDAO.DeleteAll(FileTypeID);

                foreach (DataGridViewRow row in columnDataGridView.Rows)
                {
                    columnDAO.Insert(new Column(FileTypeID, Convert.ToInt32(row.Cells[0].Value), row.Cells[1].Value.ToString(), row.Cells[2].Value.ToString(), Convert.ToBoolean(row.Cells[3].Value), Convert.ToBoolean(row.Cells[4].Value)));
                }

                HeaderDAO headerDAO = new HeaderDAO(ConfigurationDatabase);
                headerDAO.DeleteAll(FileTypeID);

                foreach (DataGridViewRow row in headerDataGridView.Rows)
                {
                    headerDAO.Insert(new Header(FileTypeID, Convert.ToInt32(row.Cells[0].Value), row.Cells[1].Value.ToString()));
                }

                FooterDAO footerDAO = new FooterDAO(ConfigurationDatabase);
                footerDAO.DeleteAll(FileTypeID);

                foreach (DataGridViewRow row in footerDataGridView.Rows)
                {
                    footerDAO.Insert(new Footer(FileTypeID, Convert.ToInt32(row.Cells[0].Value), row.Cells[1].Value.ToString()));
                }

                MessageBox.Show("Successfully saved File Type Configuration!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);

                Close();
            }
            catch (Exception exception)
            {
                MessageBox.Show("Failed to save Column data. " + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #2
0
ファイル: Service1.cs プロジェクト: duynguyenfpt/API-Service
        public async Task FetchAndUpdateDatabase(DateTime time)
        {
            using (DIEMDANHAPIEntities db = new DIEMDANHAPIEntities()) {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        // IDENTIFY THE NEXT TIME POINT IF SUCCESSS
                        int timePoint = handler.getTimeLines(time);
                        // FETCH API
                        Result dataReceived = await handler.fetchData(time);

                        //
                        int headerIDMin = headerDAO.getFirstSuccessfullyFetch(dataReceived.dateFetching, dataReceived.Session);
                        //
                        headerDAO.Insert(dataReceived);
                        //
                        if (dataReceived.success)
                        {
                            int currenHeaderID = headerDAO.getHeader(dataReceived.dateFetching, dataReceived.Session, dataReceived.actualTimeFetching);
                            if (headerIDMin == -1)
                            {
                                headerIDMin = currenHeaderID;
                                headerDetailDAO.Insert(headerIDMin);
                            }
                            //
                            var listHaveNotAdded = attendanceDAO.getUnExistItemList(dataReceived.data, headerIDMin);
                            List <DiemDanh_NangSuatLaoDong> attendanceList = new List <DiemDanh_NangSuatLaoDong>();
                            foreach (var item in listHaveNotAdded)
                            {
                                DiemDanh_NangSuatLaoDong ddEntity = new DiemDanh_NangSuatLaoDong();
                                ddEntity.HeaderID            = headerIDMin;
                                ddEntity.MaNV                = item.MaNhanVien;
                                ddEntity.ActualHeaderFetched = currenHeaderID;
                                ddEntity.DiLam               = true;
                                ddEntity.isFilledFromAPI     = true;
                                ddEntity.isChangedManually   = false;
                                ddEntity.ThoiGianXuongLo     = item.startTime;
                                ddEntity.ThoiGianLenLo       = item.endTime;
                                attendanceList.Add(ddEntity);
                            }
                            attendanceDAO.Insert(attendanceList);
                            DateTime nextTimePoint;
                            if (timePoint == 5)
                            {
                                // next 2 AM morning
                                nextTimePoint = new DateTime(time.Year, time.Month, time.Day + 1, 2, 0, 0);
                            }
                            else
                            {
                                nextTimePoint = new DateTime(time.Year, time.Month, time.Day, handler.timelinesHours[timePoint], handler.timelinesMinutes[timePoint], 0);
                            }

                            timer.Interval = nextTimePoint.Subtract(time).Seconds;
                        }
                        else
                        {
                            // 10 minutes each until successfully fetch
                            timer.Interval = 10 * 1000 * 60;
                        }

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        WriteToFile(ex.Message);
                        transaction.Rollback();
                    }
                }
            }
        }