//----------------------------------------------- //btnSave_Click //----------------------------------------------- protected void btnSave_Click(object sender, EventArgs e) { if (!Page.IsValid) { return; } SMSNumbersEntity smsUser = new SMSNumbersEntity(); smsUser.Name = txtName.Text; smsUser.Numbers = txtNumber.Text; smsUser.IsActive = cbIsActive.Checked; if (SiteSettings.Sms_HasGroups) { smsUser.GroupID = Convert.ToInt32(ddlSmsGroups.SelectedValue); } smsUser.ModuleTypeID = (int)StandardItemsModuleTypes.SMS; //--------------------------------------------------------------------- //Language //--------------------------------------------------------------------- Languages langID = (Languages)SiteSettings.Languages_DefaultLanguageID; if (SiteSettings.Languages_HasMultiLanguages) { langID = (Languages)Convert.ToInt32(ddlLanguages.SelectedValue); } //-------------------------------------- smsUser.LangID = langID; //--------------------------------------------------------------------- ExecuteCommandStatus status = SMSNumbersFactory.Create(smsUser); if (status == ExecuteCommandStatus.Done) { lblResult.CssClass = "operation_done"; lblResult.Text = Resources.AdminText.SavingDataSuccessfuly; ClearControls(); } else if (status == ExecuteCommandStatus.AllreadyExists) { lblResult.CssClass = "operation_error"; lblResult.Text = Resources.AdminText.DuplicateItem; } else { lblResult.CssClass = "operation_error"; lblResult.Text = Resources.AdminText.SavingDataFaild; } }
//----------------------------------------------- #endregion protected void ibtnSmsSubscripe_Click(object sender, ImageClickEventArgs e) { //------------------------------------- if (!Page.IsValid) { return; } //------------------------------------- if (txtMobileNo.Text.Trim() == "") { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "a", "alert('" + DynamicResource.GetText("SMS", "EnterNo") + "')", true); return; } SMSNumbersEntity newNumber = new SMSNumbersEntity(); newNumber.Numbers = txtMobileNo.Text; //newNumber.IsActive = true; ExecuteCommandStatus status = SMSNumbersFactory.Create(newNumber); if (status == ExecuteCommandStatus.Done) { lblResult.CssClass = "operation_done"; lblResult.Text = DynamicResource.GetText("SMS", "Done"); try { if ((SmsWebService.WebMethods.SendMessage(ConfigurationManager.AppSettings["SMSKey"], DynamicResource.GetText("SMS", "Welcome"), txtMobileNo.Text)) != SmsWebService.SMSSendStatus.Sent) { //resultMsg += DynamicResource.GetText("SMS","Error"); } } catch { } txtMobileNo.Text = ""; } else if (status == ExecuteCommandStatus.AllreadyExists) { lblResult.CssClass = "operation_error"; lblResult.Text = DynamicResource.GetText("SMS", "ExistBefor"); } else { lblResult.CssClass = "operation_error"; lblResult.Text = DynamicResource.GetText("SMS", "ExistBefor"); } }
//----------------------------------------------- //SaveData //----------------------------------------------- protected void btnSave_Click(object sender, EventArgs e) { if (!Page.IsValid) { return; } //-------------------------------------- if (fuFile.HasFile) { if (fuFile.PostedFile.ContentType == "text/plain") { string fileName = DCServer.MapPath(DCSiteUrls.GetPath_Sms_SMSFiles() + fuFile.FileName); fuFile.SaveAs(fileName); //--------------------------------------- string[] mobileNumbersToImport = File.ReadAllLines(fileName); int count = 0; //--------------------------------------- int successfullyNumbersCount = 0; string existsNumbers = ""; int existsNumbersCount = 0; string failedNumbers = ""; int failednumbersCount = 0; string notmobileNumbers = ""; int notNumbersCount = 0; //--------------------------------------------------------------------- //--------------------------------------------------------------------- SMSNumbersEntity smsUser = new SMSNumbersEntity(); //--------------------------------------------------------------------- //props //--------------------------------------------------------------------- Languages langID = (Languages)SiteSettings.Languages_DefaultLanguageID; if (SiteSettings.Languages_HasMultiLanguages) { langID = (Languages)Convert.ToInt32(ddlLanguages.SelectedValue); } //------------------------------------------- smsUser.LangID = langID; //------------------------------------------- smsUser.IsActive = cbIsActive.Checked; //------------------------------------------- if (ddlSmsGroups.SelectedValue != "-1") { smsUser.GroupID = Convert.ToInt32(ddlSmsGroups.SelectedValue); } //--------------------------------------------------------------------- char[] Splitter = { '-' }; string[] record = null; string name = ""; string number = ""; bool isMobile = false; //--------------------------------------------------------------------- ExecuteCommandStatus status; //--------------------------------------------------------------------- foreach (string newRecord in mobileNumbersToImport) { name = ""; number = ""; isMobile = false; try { record = newRecord.Split(Splitter); switch (record.Length) { case 1: number = record[0].Trim(); isMobile = DCValidation.IsMobileNumber(number); break; case 2: number = record[0].Trim(); name = record[1].Trim(); isMobile = DCValidation.IsMobileNumber(number); break; default: break; } if (isMobile) { smsUser.Numbers = number; smsUser.Name = name; status = SMSNumbersFactory.Create(smsUser); switch (status) { case ExecuteCommandStatus.Done: ++successfullyNumbersCount; break; case ExecuteCommandStatus.AllreadyExists: existsNumbers += newRecord + "<br>"; ++existsNumbersCount; break; case ExecuteCommandStatus.UnknownError: failedNumbers += newRecord + "<br>"; ++failednumbersCount; break; default: failedNumbers += newRecord + "<br>"; ++failednumbersCount; break; } } else { notmobileNumbers += newRecord + "<br>"; ++notNumbersCount; } } catch (Exception wx) { notmobileNumbers += newRecord + "<br>"; ++notNumbersCount; } } //--------------------------------------------------------------------------------------------- lblSuccessfulyRecords.Text = string.Format(Resources.SmsAdmin.ImportSuccessfulyCount, successfullyNumbersCount); lblNotMobileNumbers.Text = string.Format(Resources.SmsAdmin.NotImportNotNumbersCount, notNumbersCount) + " <br />" + notmobileNumbers; lblExistsMobileNumbers.Text = string.Format(Resources.SmsAdmin.NotImportAlradyExistCount, existsNumbersCount) + " <br />" + existsNumbers; lblFailedMobileNumbers.Text = string.Format(Resources.SmsAdmin.NotImportFailiarCount, failednumbersCount) + " <br />" + failedNumbers; //--------------------------------------------------------------------------------------------- } else { lblResult.CssClass = "operation_error"; lblResult.Text = Resources.SmsAdmin.FileNotSupportedFile; } } else { lblResult.CssClass = "operation_error"; lblResult.Text = Resources.SmsAdmin.FileNotFound; } //-------------------------------------- }
//----------------------------------------------- //btnSave_Click //----------------------------------------------- protected void btnSave_Click(object sender, EventArgs e) { if (!Page.IsValid) { return; } if (FuFile.HasFile) { try { string FileName = DCServer.MapPath(DCSiteUrls.GetPath_Sms_SMSFiles() + FuFile.FileName); FuFile.SaveAs(FileName); String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + DCServer.MapPath(DCSiteUrls.GetPath_Sms_SMSFiles() + FuFile.FileName) + ";" + "Extended Properties=Excel 8.0;"; // Create connection object by using the preceding connection string. OleDbConnection objConn = new OleDbConnection(sConnectionString); // Open connection with the database. objConn.Open(); // The code to follow uses a SQL SELECT command to display the data from the worksheet. // Create new OleDbCommand to return data from worksheet. OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM [Sheet1$]", objConn); // Create new OleDbDataAdapter that is used to build a DataSet // based on the preceding SQL SELECT statement. OleDbDataAdapter objAdapter1 = new OleDbDataAdapter(); // Pass the Select command to the adapter. objAdapter1.SelectCommand = objCmdSelect; // Create new DataSet to hold information from the worksheet. DataSet objDataset1 = new DataSet(); // Fill the DataSet with the information from the worksheet. objAdapter1.Fill(objDataset1, "XLData"); //--------------------------------------------------------------------- SMSNumbersEntity smsUser = new SMSNumbersEntity(); //--------------------------------------------------------------------- //props //--------------------------------------------------------------------- Languages langID = (Languages)SiteSettings.Languages_DefaultLanguageID; if (SiteSettings.Languages_HasMultiLanguages) { langID = (Languages)Convert.ToInt32(ddlLanguages.SelectedValue); } //----------------------- smsUser.LangID = langID; //----------------------- if (SiteSettings.Sms_HasGroups) { smsUser.GroupID = Convert.ToInt32(ddlSmsGroups.SelectedValue); } //----------------------- smsUser.ModuleTypeID = (int)StandardItemsModuleTypes.SMS; //----------------------- smsUser.IsActive = cbIsActive.Checked; //-------------------------------------- int successfullyNumbersCount = 0; string existsNumbers = ""; int existsNumbersCount = 0; string failedNumbers = ""; int failednumbersCount = 0; string notmobileNumbers = ""; int notNumbersCount = 0; //--------------------------------------------------------------------- string newRecord = ""; string name = ""; string number = ""; bool isMobile = false; //--------------------------------------------------------------------- ExecuteCommandStatus status; //--------------------------------------------------------------------- for (int i = 0; i < objDataset1.Tables[0].Rows.Count; i++) { name = ""; number = ""; newRecord = ""; isMobile = false; try { number = objDataset1.Tables[0].Rows[i].ItemArray[0].ToString(); name = objDataset1.Tables[0].Rows[i].ItemArray[1].ToString(); if (string.IsNullOrEmpty(name)) { newRecord = number; } else { newRecord = number + " - " + name; } isMobile = DCValidation.IsMobileNumber(number); if (isMobile) { smsUser.Numbers = number; smsUser.Name = name; status = SMSNumbersFactory.Create(smsUser); switch (status) { case ExecuteCommandStatus.Done: ++successfullyNumbersCount; break; case ExecuteCommandStatus.AllreadyExists: existsNumbers += newRecord + "<br>"; ++existsNumbersCount; break; case ExecuteCommandStatus.UnknownError: failedNumbers += newRecord + "<br>"; ++failednumbersCount; break; default: failedNumbers += newRecord + "<br>"; ++failednumbersCount; break; } } else { notmobileNumbers += newRecord + "<br>"; ++notNumbersCount; } } catch (Exception ex2) { notmobileNumbers += newRecord + "<br>"; ++notNumbersCount; } } objConn.Close(); //--------------------------------------------------------------------------------------------- lblSuccessfulyRecords.Text = string.Format(Resources.SmsAdmin.ImportSuccessfulyCount, successfullyNumbersCount); lblNotMobileNumbers.Text = string.Format(Resources.SmsAdmin.NotImportNotNumbersCount, notNumbersCount) + " <br />" + notmobileNumbers; lblExistsMobileNumbers.Text = string.Format(Resources.SmsAdmin.NotImportAlradyExistCount, existsNumbersCount) + " <br />" + existsNumbers; lblFailedMobileNumbers.Text = string.Format(Resources.SmsAdmin.NotImportFailiarCount, failednumbersCount) + " <br />" + failedNumbers; //--------------------------------------------------------------------------------------------- } catch (Exception ex) { lblResult.CssClass = "operation_error"; lblResult.Text = Resources.SmsAdmin.FileNotSupportedFile; } } else { lblResult.CssClass = "operation_error"; lblResult.Text = Resources.SmsAdmin.FileNotFound; } }