예제 #1
0
        void saveButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                Station.IsActive = isActiveBox.Checked;

                String code = codeBox.Text.Trim().ToUpper();

                if (code == String.Empty)
                {
                    ErrorMessage = "Code is required";
                    return;
                }

                if (code.Length < 3 || code.Length > 20)
                {
                    ErrorMessage = "Code must be between 3 and 20 characters";
                    return;
                }

                DollarSaverDB.StationDataTable stationCodeLookup = stationAdapter.GetByCode(code);

                if (stationCodeLookup.Count == 1 && stationCodeLookup[0].StationId != Station.StationId)
                {
                    InfoMessage = "Code is already in use";
                    return;
                }

                Station.Code = code;

                String subdomain = subdomainBox.Text.Trim().ToLower();

                if (subdomain != String.Empty)
                {
                    if (!Regex.IsMatch(subdomain, @"\w+([-]\w+)*"))
                    {
                        ErrorMessage = "Subdomain can only contain letters, numbers and dashes";
                        return;
                    }


                    DollarSaverDB.StationDataTable stationLookup = stationAdapter.GetBySubdomain(subdomain);

                    if (stationLookup.Count == 1 && stationLookup[0].StationId != Station.StationId)
                    {
                        InfoMessage = "Subdomain is already in use";
                        return;
                    }

                    Station.Subdomain = subdomain;
                }
                else
                {
                    Station.SetSubdomainNull();
                }

                stationAdapter.Update(Station);
                InfoMessage = "Station Updated";


                RedirectToSuperAdminHome();
            }
        }
        void saveButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                StationTableAdapter stationAdapter = new StationTableAdapter();

                String name          = nameBox.Text.Trim();
                int    siteTypeId    = Int32.Parse(siteTypeList.SelectedValue);
                int    stationTypeId = Int32.Parse(stationTypeList.SelectedValue);
                String phoneNumber   = phoneNumberBox.Text.Trim();
                String address1      = address1Box.Text.Trim();
                String address2      = address2Box.Text.Trim();
                String city          = cityBox.Text.Trim();
                String stateCode     = stateList.SelectedValue;
                String zipCode       = zipCodeBox.Text.Trim();
                int    timeZoneId    = Int32.Parse(timeZoneList.SelectedValue);
                //bool affectedByDST = daylightSavingsBox.Checked;
                String stationUrl = stationUrlBox.Text.Trim();
                String siteName   = siteNameBox.Text.Trim();
                String content1   = content1Box.Text.Trim();
                String content2   = content2Box.Text.Trim();
                //bool isActive = isActiveBox.Checked;

                if (name == String.Empty)
                {
                    ErrorMessage = "Name is required";
                    return;
                }


                if (phoneNumber == String.Empty)
                {
                    ErrorMessage = "Phone Number is required";
                    return;
                }

                if (address1 == String.Empty)
                {
                    ErrorMessage = "Address 1 is required";
                    return;
                }

                if (city == String.Empty)
                {
                    ErrorMessage = "City is required";
                    return;
                }

                if (zipCode == String.Empty)
                {
                    ErrorMessage = "Zip Code is required";
                    return;
                }

                if (stationUrl != String.Empty)
                {
                    stationUrl = stationUrlStart.SelectedValue + stationUrl;

                    // come up with a better validation...
                    if (!Uri.IsWellFormedUriString(stationUrl, UriKind.Absolute))
                    {
                        ErrorMessage = "Please enter a valid Station Website";
                        return;
                    }
                }

                if (stationUrl.Length > 500)
                {
                    stationUrl = stationUrl.Substring(0, 500);
                }

                /*
                 * if (content1 == String.Empty) {
                 *  ErrorMessage = "Content 1 is required";
                 *  return;
                 * }*/

                if (content1.Length > 1000)
                {
                    content1 = content1.Substring(0, 1000);
                }


                /*
                 * if (content2 == String.Empty) {
                 *  ErrorMessage = "Content 2 is required";
                 *  return;
                 * }*/

                if (content2.Length > 1000)
                {
                    content2 = content2.Substring(0, 1000);
                }

                siteName = siteName.Replace("<br />", "");

                if (siteName.Length > 500)
                {
                    siteName = siteName.Substring(0, 500);
                }

                String siteNameCheck = Regex.Replace(siteName, "<[^>]+>", "").Replace("&nbsp;", "").Trim();

                if (siteNameCheck == String.Empty)   // only leftover formatting in site name
                {
                    siteName = String.Empty;
                }

                if (Station != null)
                {
                    Station.Name          = name;
                    Station.SiteTypeId    = Int32.Parse(siteTypeList.SelectedValue);
                    Station.StationTypeId = Int32.Parse(stationTypeList.SelectedValue);
                    Station.PhoneNumber   = phoneNumber;
                    Station.Address1      = address1;
                    Station.Address2      = address2;
                    Station.City          = city;
                    Station.StateCode     = stateList.SelectedValue;
                    Station.ZipCode       = zipCode;
                    Station.TimeZoneId    = Int32.Parse(timeZoneList.SelectedValue);
                    //Station.AffectedByDST = daylightSavingsBox.Checked;
                    if (stationUrl != String.Empty)
                    {
                        Station.StationUrl = stationUrl;
                    }
                    else
                    {
                        Station.SetStationUrlNull();
                    }

                    if (siteName != String.Empty)
                    {
                        Station.SiteName = siteName;
                    }
                    else
                    {
                        Station.SetSiteNameNull();
                    }

                    Station.Content1 = content1;
                    Station.Content2 = content2;
                    //Station.IsActive = isActiveBox.Checked;
                    Station.IsSiteActive = isSiteActiveBox.Checked;

                    stationAdapter.Update(Station);
                    InfoMessage = "Station Updated";
                }
                else
                {
                    if (IsSuperAdmin)
                    {
                        String code = codeBox.Text.Trim().ToUpper();

                        if (code == String.Empty)
                        {
                            ErrorMessage = "Code is required";
                            return;
                        }

                        if (code.Length < 3 || code.Length > 20)
                        {
                            ErrorMessage = "Code must be between 3 and 20 characters";
                            return;
                        }

                        DollarSaverDB.StationDataTable stationCodeLookup = stationAdapter.GetByCode(code);

                        if (stationCodeLookup.Count == 1 && (Station == null || stationCodeLookup[0].StationId != Station.StationId))
                        {
                            InfoMessage = "Code is already in use";
                            return;
                        }

                        int stationId = Convert.ToInt32(stationAdapter.InsertPK(name, code, stationTypeId, siteTypeId, phoneNumber, address1, address2,
                                                                                city, stateCode, zipCode, timeZoneId, false, DateTime.Now, DateTime.Now, true,
                                                                                content1, content2, Globals.ConvertToNull(stationUrl), Globals.ConvertToNull(siteName), isSiteActiveBox.Checked, null));

                        Station = stationAdapter.GetStation(stationId)[0];

                        CategoryTableAdapter categoryAdapter = new CategoryTableAdapter();
                        categoryAdapter.Insert(stationId, null, "Restaurants & Food", 1);
                        categoryAdapter.Insert(stationId, null, "Things To Do", 2);
                        categoryAdapter.Insert(stationId, null, "Home & Garden", 3);
                        categoryAdapter.Insert(stationId, null, "Health & Beauty", 4);
                        categoryAdapter.Insert(stationId, null, "Retail", 5);
                        categoryAdapter.Insert(stationId, null, "Automotive", 6);

                        StationContentTableAdapter stationContentTableAdapter = new StationContentTableAdapter();
                        stationContentTableAdapter.Insert(stationId, null, null, null, null, null, null, null, null, null);

                        DealSettingsTableAdapter dealSettingsAdapter = new DealSettingsTableAdapter();
                        dealSettingsAdapter.Insert(stationId, 1, 8, 4, 10);

                        SpecialSettingsTableAdapter specialSettingAdapter = new SpecialSettingsTableAdapter();
                        specialSettingAdapter.Insert(stationId, true);

                        if (!Directory.Exists(Request.PhysicalApplicationPath + Station.StationDirUrl))
                        {
                            Directory.CreateDirectory(Request.PhysicalApplicationPath + Station.StationDirUrl);
                        }

                        if (!Directory.Exists(Request.PhysicalApplicationPath + Station.ImageDirUrl))
                        {
                            Directory.CreateDirectory(Request.PhysicalApplicationPath + Station.ImageDirUrl);
                        }
                    }
                }

                RedirectToHomePage();
            }
        }