/// <summary> /// The AddConfiguration. /// </summary> /// <param name="configuration">The configuration<see cref="ConfigurationDetails"/>.</param> internal static void AddConfiguration(ConfigurationDetails configuration) { OpenSqlCeConnection(); sqlQuery = "INSERT INTO configuration ([EffectiveDate],[NoOfReceipts],[NoOfMonths])VALUES(@EffectiveDate,@NoOfReceipts, @NoOfMonths)"; SqlCeCommand cm = new SqlCeCommand(sqlQuery, con); cm.Parameters.AddWithValue("@EffectiveDate", configuration.effectiveDate); cm.Parameters.AddWithValue("@NoOfReceipts", configuration.TotalNoOfReceipts); cm.Parameters.AddWithValue("@NoOfMonths", configuration.NoOfMonths); try { int intAffectedRow = cm.ExecuteNonQuery(); con.Close(); if (intAffectedRow > 0) { MessageBox.Show("Configuration were added sucessfully", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Insertion Failed", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// The btnConfigure_Click. /// </summary> /// <param name="sender">The sender<see cref="object"/>.</param> /// <param name="e">The e<see cref="EventArgs"/>.</param> private void btnConfigure_Click(object sender, EventArgs e) { string password = txtPassword.Text; DateTime effectivedate = new DateTime(dtEffectiveDate.Value.Year, dtEffectiveDate.Value.Month, dtEffectiveDate.Value.Day, 0, 0, 0); configurationDetails = new ConfigurationDetails { effectiveDate = effectivedate, TotalNoOfReceipts = Convert.ToInt32(nmcReceipts.Value), NoOfMonths = Convert.ToInt32(nmcMonths.Value) }; if (string.IsNullOrWhiteSpace(password)) { MessageBox.Show("Please enter valid password...", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (!string.IsNullOrWhiteSpace(password) && password != Convert.ToString(ConfigurationManager.AppSettings["Password"])) { MessageBox.Show("Please enter valid password...", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (configurationDetails.TotalNoOfReceipts < 5) { MessageBox.Show("Total No.of Receipts should be greater than 5.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (configurationDetails.NoOfMonths < 3) { MessageBox.Show("Min No.of Months for booking annadhanam should be greater than or equal to 3.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (lstConfiguration.Any(n => n.effectiveDate.Date == dtEffectiveDate.Value.Date)) { MessageBox.Show("Record already exists in out database. Please choose another date !..", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { SqlHelper.AddConfiguration(configurationDetails); dtEffectiveDate.MinDate = DateTime.Now.Date; dtEffectiveDate.MaxDate = DateTime.Now.AddYears(1); dtEffectiveDate.Value = DateTime.Now.Date; nmcReceipts.Value = 5; nmcMonths.Value = 3; LoadConfigurationDetails(); } }
/// <summary> /// Initialises the specified file name. /// </summary> /// <param name="fileName">Name of the file.</param> public void Initialise(string fileName) { this.hierarchy.BeginUpdate(); try { this.hierarchy.Nodes.Clear(); var parent = new ConfigurationDetails(fileName); this.AddNode(this.hierarchy, "Configuration", "configuration", parent); } finally { this.hierarchy.EndUpdate(); } this.queues.Clear(); this.itemDetails.SelectedObject = null; }
/// <summary> /// Gets the configuration from repository. /// </summary> /// <exception cref="ItemNotFoundException">No matching external source was found</exception> protected void GetConfigurationFromRepository() { var externalSource = _repository.GetSingle(x => x.Name == Constants.ExternalSourceName); if (externalSource == null) { throw new ItemNotFoundException(); } _nextRefresh = externalSource.ConfigurationTimestamp.AddMinutes(externalSource.ConfigurationRefreshMinutes); if (externalSource.Configuration == null || DateTime.Now >= _nextRefresh.GetValueOrDefault()) { externalSource.Configuration = GetConfigurationFromApi(externalSource.ApiKey); externalSource.ConfigurationTimestamp = DateTime.Now; _repository.Update(externalSource); } _configurationDetails = JsonConvert.DeserializeObject <ConfigurationDetails>(externalSource.Configuration); _configurationDetails.ApiKey = externalSource.ApiKey; }
/// <summary> /// Initialises a new instance of the <see cref="ImageUrlHelper"/> class. /// </summary> /// <param name="configurationApi">The configuration API handler.</param> public ImageUrlHelper(ConfigurationApi configurationApi) { _configurationApi = configurationApi; _configuration = _configurationApi.GetConfiguration(); }
/// <summary> /// The GetAnnadhanamAvailabilityDate. /// </summary> /// <param name="dtAnnadhanamDate">The dtAnnadhanamDate<see cref="DateTime"/>.</param> /// <returns>The <see cref="List{Availability}"/>.</returns> internal static List <Availability> GetAnnadhanamAvailabilityByWeek(DateTime dtAnnadhanamDate) { lstAvailabilityByWeek = new List <Availability>(); DateTime PeriodFrom = new DateTime(dtAnnadhanamDate.Year, dtAnnadhanamDate.Month, dtAnnadhanamDate.Day, 0, 0, 0); DateTime PeriodTo = new DateTime(dtAnnadhanamDate.Date.AddDays(7).Year, dtAnnadhanamDate.Date.AddDays(7).Month, dtAnnadhanamDate.Date.AddDays(7).Day, 23, 59, 59); for (DateTime dt = PeriodFrom; dt <= PeriodTo; dt = dt.AddDays(1)) { lstAvailabilityByWeek.Add(new Availability { annadhanamDate = dt.Date, bookedReceiptCount = 0 }); } try { OpenSqlCeConnection(); string strSelectQuery = "SELECT AnadhanamDate,COALESCE(COUNT(ReceiptNumber),0) FROM tblAnnadhanamDetails WHERE AnadhanamDate>='" + PeriodFrom.ToString("dd-MMM-yyyy") + "' AND AnadhanamDate <='" + PeriodTo.ToString("dd-MMM-yyyy") + "' GROUP BY AnadhanamDate ORDER BY AnadhanamDate ASC"; SqlCeCommand cm = new SqlCeCommand(strSelectQuery, con) { CommandText = strSelectQuery, CommandType = CommandType.Text, Connection = con }; var dataReader = cm.ExecuteReader(); var dataTable = new DataTable(); dataTable.Load(dataReader); if (dataTable != null && dataTable.Rows.Count > 0) { List <ConfigurationDetails> configurationDetails = new List <ConfigurationDetails>(); configurationDetails = SqlHelper.GetConfigurationDetails(); foreach (DataRow dr in dataTable.Rows) { foreach (Availability avail in lstAvailabilityByWeek.Where(n => n.annadhanamDate.Date == Convert.ToDateTime(dr.ItemArray[0]).Date)) { avail.bookedReceiptCount = Convert.ToInt32(dr.ItemArray[1]); } } foreach (Availability avail in lstAvailabilityByWeek) { ConfigurationDetails config = configurationDetails .OrderByDescending(n => n.effectiveDate) .Where(n => n.effectiveDate.Date <= avail.annadhanamDate.Date) .FirstOrDefault(); avail.totalReceiptCount = config.TotalNoOfReceipts; avail.balanceReceiptCount = (config.TotalNoOfReceipts - avail.bookedReceiptCount); } } con.Close(); } catch (SqlCeException ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); Application.ExitThread(); } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { } return(lstAvailabilityByWeek); }
/// <summary> /// Initializes a new instance of the <see cref="FileController"> class.</see> /// </summary> /// <param name="configDetails">The configuration details.</param> public FileController(ConfigurationDetails configDetails) { this.ConfigurationDetails = configDetails; }