protected void btnImport_Click(object sender, EventArgs e) { string connectionString = ConfigurationSettings.AppSettings["ConnectionString"] + "password="******"password"] + ";"; ReadOnlyCollection <TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones(); //int b = 0; ESTimeZone TZ = new ESTimeZone(); ArrayList al; foreach (TimeZoneInfo timeZone in timeZones) { //b++; string name = timeZone.StandardName; //WrittenName string displayName = timeZone.DisplayName; //FLB_Name double totalMinutes = timeZone.BaseUtcOffset.TotalMinutes; int offset = Convert.ToInt32(totalMinutes); //OffsetUTC al = new ArrayList(); al.Add(new SqlParameter("@offset", offset)); al.Add(new SqlParameter("@displayName", displayName)); al.Add(new SqlParameter("@active", 1)); al.Add(new SqlParameter("@name", name)); Console.WriteLine("{0} Start Date: {1:D}", " ", displayName); string sqlUpdate = @"UPDATE tblTimeZone SET OffsetUTC = @offset ,FLB_Name = @displayName ,Active = @active WHERE WrittenName=@name select TimeZoneID from tblTimeZone WHERE WrittenName=@name"; DataSet ds = SqlHelper.ExecuteDataset(connectionString, CommandType.Text, sqlUpdate, (SqlParameter[])al.ToArray(typeof(SqlParameter))); string newID = ""; if (ds.Tables[0].Rows.Count == 0) { string sqlInsert = "INSERT INTO tblTimeZone (OffsetUTC,FLB_Name,Active,WrittenName) " + "VALUES (@offset, @displayName ,@active, @name) SELECT @@IDENTITY"; ds = SqlHelper.ExecuteDataset(connectionString, CommandType.Text, sqlInsert, (SqlParameter[])al.ToArray(typeof(SqlParameter))); } newID = Convert.ToString(ds.Tables[0].Rows[0][0]); //reimport daylightsaving if (timeZone.SupportsDaylightSavingTime) { //delete all of existing string sqlDelete = "delete tblTimeZoneDaylightSavingRules where TimezoneID=@timezoneID"; al = new ArrayList(); al.Add(new SqlParameter("@timezoneID", newID)); SqlHelper.ExecuteDataset(connectionString, CommandType.Text, sqlDelete, (SqlParameter[])al.ToArray(typeof(SqlParameter))); //re add all of them TimeZoneInfo.AdjustmentRule[] adjustRules = timeZone.GetAdjustmentRules(); foreach (TimeZoneInfo.AdjustmentRule rule in adjustRules) { bool error = false; TimeZoneInfo.TransitionTime transTimeStart = rule.DaylightTransitionStart; TimeZoneInfo.TransitionTime transTimeEnd = rule.DaylightTransitionEnd; TZ.AddTimeZoneRule(timeZone.StandardName, rule.DaylightDelta.Hours * 60 + rule.DaylightDelta.Minutes, rule.DateStart.Year, rule.DateEnd.Year, transTimeStart.TimeOfDay.Hour * 60 + transTimeStart.TimeOfDay.Minute, (int)transTimeStart.DayOfWeek + 1, transTimeStart.Week, transTimeStart.Month, transTimeEnd.TimeOfDay.Hour * 60 + transTimeEnd.TimeOfDay.Minute, (int)transTimeEnd.DayOfWeek + 1, transTimeEnd.Week, transTimeEnd.Month, out error); } } //if (b == 5 ) break; } Response.Redirect("TimeZone.aspx"); Console.WriteLine("----"); }
protected void btnOrgEditDaylightSave_Click(object sender, EventArgs e) { this.tzId = (int)ViewState["TimezoneID"]; this.isNew = (bool)ViewState["IsNew"]; this.ruleId = (int)ViewState["RuleID"]; if (this.chkDelete.Checked && (!this.isNew)) { using (StoredProcedure sp = new StoredProcedure("prcDeleteTimezoneDaylightSavingRule", StoredProcedure.CreateInputParam("@TimezoneId", SqlDbType.Int, this.tzId), StoredProcedure.CreateInputParam("@RuleID", SqlDbType.Int, this.ruleId))) { sp.ExecuteNonQuery(); } } bool error = false; if (!this.chkDelete.Checked) { this.tzWrittenName = ViewState["WrittenName"].ToString(); int firstYearStart; Int32.TryParse(this.txtFirstYearStart.Text, out firstYearStart); int lastYearStart; Int32.TryParse(this.txtLastYearStart.Text, out lastYearStart); int offset; string strOffset = this.txtOffset.Text; offset = ConvertStringtoMins(strOffset); int timeStart; string strtimeStart = this.txtTimeStart.Text; timeStart = ConvertStringtoMins(strtimeStart); int weekdayStart; Int32.TryParse(drpWeekdayStart.SelectedValue, out weekdayStart); int weekStart; Int32.TryParse(drpWeekStart.SelectedValue, out weekStart); int monthStart; Int32.TryParse(drpMonthStart.SelectedValue, out monthStart); int timeEnd; string strTimeEnd = this.txtTimeEnd.Text; timeEnd = ConvertStringtoMins(strTimeEnd); int weekdayEnd; Int32.TryParse(drpWeekdayEnd.SelectedValue, out weekdayEnd); int weekEnd; Int32.TryParse(drpWeekEnd.SelectedValue, out weekEnd); int monthEnd; Int32.TryParse(drpMonthEnd.SelectedValue, out monthEnd); if (this.isNew) { ESTimeZone es = new ESTimeZone(); es.AddTimeZoneRule(this.tzWrittenName, offset, firstYearStart, lastYearStart, timeStart, weekdayStart, weekStart, monthStart, timeEnd, weekdayEnd, weekEnd, monthEnd, out error); } else { ESTimeZone es = new ESTimeZone(); es.UpdateTimeZoneRule(this.ruleId, this.tzWrittenName, offset, firstYearStart, lastYearStart, timeStart, weekdayStart, weekStart, monthStart, timeEnd, weekdayEnd, weekEnd, monthEnd, out error); } } if (error) { Response.Write(@"<script language='javascript'>alert('Overlapping rule violated');</script>"); } else { Response.Redirect("TimeZoneEdit.aspx?timeZoneId=" + ViewState["TimezoneID"].ToString()); } }