protected void btnImportFile_Click(object sender, EventArgs e)
        {
            try
            {
                string file = hdnFilePath.Value;

                if (!System.IO.File.Exists(Server.MapPath(string.Format("/Uploads/{0}", file))))
                {
                    throw new Exception(Language.GetString("FileDoesNotExist"));
                }

                string    extension = file.Substring(file.LastIndexOf('.')).TrimStart('.');
                bool      firstRowHasColumnNames = chbHeaderRow.Checked;
                DataTable dtb = new DataTable();

                switch (extension.ToLower())
                {
                case "csv":
                    dtb = ImportFile.ImportCSV(Server.MapPath(string.Format("/Uploads/{0}", file)), firstRowHasColumnNames, 5);
                    break;

                case "xls":
                case "xlsx":
                    dtb = ImportFile.ImportExcel(Server.MapPath(string.Format("/Uploads/{0}", file)), firstRowHasColumnNames, 5);
                    break;
                }

                gridFile.DataSource = dtb;
                gridFile.DataBind();
            }
            catch (Exception ex)
            {
                ClientSideScript = "saveResult('Error','" + ex.Message + "');";
            }
        }
示例#2
0
        //#region InsertMethod
        //#endregion

        //#region UpdateMethod
        //#endregion

        //#region SelectMethod
        //public static DataTable GetCountNumberOfOperatorsForSendSmsFormat(Guid smsFormatGuid, string groupsGuid)
        //{
        //	Business.PhoneNumber phoneNumberController = new Business.PhoneNumber();
        //	return phoneNumberController.GetCountNumberOfOperatorsForSendSmsFormat(smsFormatGuid, groupsGuid);
        //}

        public static Dictionary <string, string> GetFileNumberInfo(string path, List <string> lstNumbers)
        {
            int correctNumber   = 0;
            int duplicateNumber = 0;
            Dictionary <string, string> fileInfo = new Dictionary <string, string>();

            try
            {
                if (!string.IsNullOrEmpty(path))
                {
                    DataTable dtb           = new DataTable();
                    string    fileExtention = path.Substring(path.LastIndexOf('.'));

                    switch (fileExtention.Trim('.').ToLower())
                    {
                    case "csv":
                        dtb = ImportFile.ImportCSV(path, false);
                        break;

                    case "xls":
                    case "xlsx":
                        dtb = ImportFile.ImportExcel(path, false);
                        break;
                    }

                    foreach (DataRow row in dtb.Rows)
                    {
                        if (Helper.IsCellPhone(row[0].ToString()) > 0)
                        {
                            correctNumber++;
                            lstNumbers.Add(row[0].ToString());
                        }
                    }

                    duplicateNumber = dtb.Rows.Count - lstNumbers.GroupBy(number => number).Count();

                    fileInfo.Add("TotalNumberCount", dtb.Rows.Count.ToString());
                    fileInfo.Add("CorrectNumberCount", correctNumber.ToString());
                    fileInfo.Add("DuplicateNumberCount", duplicateNumber.ToString());
                }
                return(fileInfo);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Common.PhoneNumber        phoneNumber;
            List <Common.PhoneNumber> lstNumbers = new List <Common.PhoneNumber>();
            string fieldId;
            string saveReport = string.Empty;

            try
            {
                string file = hdnFilePath.Value;

                if (!System.IO.File.Exists(Server.MapPath(string.Format("/Uploads/{0}", file))))
                {
                    throw new Exception(Language.GetString("FileDoesNotExist"));
                }

                string    extension = file.Substring(file.LastIndexOf('.')).TrimStart('.');
                bool      firstRowHasColumnNames = chbHeaderRow.Checked;
                DataTable dtb = new DataTable();

                switch (extension.ToLower())
                {
                case "csv":
                    dtb = ImportFile.ImportCSV(Server.MapPath(string.Format("/Uploads/{0}", file)), firstRowHasColumnNames);
                    break;

                case "xls":
                case "xlsx":
                    dtb = ImportFile.ImportExcel(Server.MapPath(string.Format("/Uploads/{0}", file)), firstRowHasColumnNames);
                    break;
                }

                foreach (DataRow row in dtb.Rows)
                {
                    phoneNumber = new Common.PhoneNumber();
                    phoneNumber.PhoneNumberGuid = Guid.NewGuid();
                    phoneNumber.PhoneBookGuid   = PhoneBookGuid;
                    phoneNumber.CreateDate      = DateTime.Now;
                    phoneNumber.FirstName       = !string.IsNullOrEmpty(txtFirstName.Text) ? row[Helper.GetInt(txtFirstName.Text.Trim()) - 1].ToString() : string.Empty;
                    phoneNumber.LastName        = !string.IsNullOrEmpty(txtLastName.Text) ? row[Helper.GetInt(txtLastName.Text.Trim()) - 1].ToString() : string.Empty;

                    if (!string.IsNullOrEmpty(txtBirthDate.Text))
                    {
                        phoneNumber.BirthDate = DateManager.GetChristianDateForDB(row[Helper.GetInt(txtBirthDate.Text.Trim()) - 1].ToString());
                    }

                    if (!string.IsNullOrEmpty(txtSex.Text))
                    {
                        phoneNumber.Sex = GetSex(row[Helper.GetInt(txtSex.Text.Trim()) - 1].ToString());
                    }

                    string mobile = !string.IsNullOrEmpty(txtCellPhone.Text) ? Helper.GetLocalMobileNumber(row[Helper.GetInt(txtCellPhone.Text.Trim()) - 1].ToString()) : string.Empty;
                    string email  = !string.IsNullOrEmpty(txtEmail.Text) ? row[Helper.GetInt(txtEmail.Text.Trim()) - 1].ToString() : string.Empty;

                    if (!Helper.CheckDataConditions(email).IsEmail)
                    {
                        email = string.Empty;
                    }

                    //if (!Helper.CheckingCellPhone(ref mobile) && !Helper.CheckDataConditions(email).IsEmail)
                    //	continue;

                    phoneNumber.Email     = email;
                    phoneNumber.CellPhone = mobile;
                    phoneNumber.Job       = !string.IsNullOrEmpty(txtJob.Text) ? row[Helper.GetInt(txtJob.Text.Trim()) - 1].ToString() : string.Empty;
                    phoneNumber.Telephone = !string.IsNullOrEmpty(txtTelephone.Text) ? row[Helper.GetInt(txtTelephone.Text.Trim()) - 1].ToString() : string.Empty;
                    phoneNumber.FaxNumber = !string.IsNullOrEmpty(txtFaxNumber.Text) ? row[Helper.GetInt(txtFaxNumber.Text.Trim()) - 1].ToString() : string.Empty;
                    phoneNumber.Address   = !string.IsNullOrEmpty(txtAddress.Text) ? row[Helper.GetInt(txtAddress.Text.Trim()) - 1].ToString() : string.Empty;

                    fieldId = string.Empty;
                    for (int customFieldCounter = 1; customFieldCounter <= 20; customFieldCounter++)
                    {
                        fieldId = "Field" + customFieldCounter.ToString();
                        TextBox customField = pnlUserField.FindControl(fieldId) as TextBox;
                        if (customField != null && !string.IsNullOrEmpty(customField.Text))
                        {
                            SetCustomFieldValue(phoneNumber,
                                                customFieldCounter,
                                                row[Helper.GetInt(customField.Text.Trim()) - 1].ToString(),
                                                (UserFieldTypes)Helper.GetInt(customField.Attributes["FieldType"]));
                        }
                    }

                    lstNumbers.Add(phoneNumber);
                }

                if (!Facade.PhoneNumber.InsertBulkNumbers(lstNumbers, UserGuid))
                {
                    throw new Exception(Language.GetString("ErrorRecord"));
                }

                ClientSideScript = "saveResult('OK','" + Language.GetString("InsertRecord") + "');";

                hdnFilePath.Value = string.Empty;
            }
            catch (Exception ex)
            {
                ClientSideScript = "saveResult('Error','" + ex.Message + "');";
            }
        }
示例#4
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            DataTable dtContents = new DataTable();

            dtContents.Columns.Add("Text", typeof(string));

            try
            {
                string        uploadTarget      = Server.MapPath(string.Format("~/RegularContents/"));
                List <string> lstValidExtention = new List <string>()
                {
                    ".xls", ".xlsx", ".csv"
                };
                if (!Directory.Exists(uploadTarget))
                {
                    Directory.CreateDirectory(uploadTarget);
                }

                if (!fileUpload.HasFile)
                {
                    throw new Exception(Language.GetString("ErrorSelectFile"));
                }

                string fileExtention = Path.GetExtension(fileUpload.PostedFile.FileName).ToLower();
                if (!lstValidExtention.Contains(fileExtention))
                {
                    throw new Exception((Language.GetString("InvalidFileExtension")));
                }

                string fileName = Path.GetFileName(fileUpload.PostedFile.FileName);
                fileUpload.SaveAs(uploadTarget + fileName);

                bool           firstRowHasColumnNames = true;
                List <DataRow> lstContents            = new List <DataRow>();

                switch (fileExtention.TrimStart('.').ToLower())
                {
                case "csv":
                    lstContents = ImportFile.ImportCSV(Server.MapPath(string.Format("/RegularContents/{0}", fileName)), firstRowHasColumnNames).AsEnumerable().ToList();
                    break;

                case "xls":
                case "xlsx":
                    lstContents = ImportFile.ImportExcel(Server.MapPath(string.Format("/RegularContents/{0}", fileName)), firstRowHasColumnNames).AsEnumerable().ToList();
                    break;
                }

                lstContents.RemoveAll(cnt => string.IsNullOrEmpty(cnt[0].ToString()));

                foreach (DataRow row in lstContents)
                {
                    dtContents.Rows.Add(row[0].ToString());
                }

                if (!Facade.Content.InsertContents(RegularContentGuid, dtContents))
                {
                    throw new Exception(Language.GetString("ErrorRecord"));
                }

                Response.Redirect(string.Format("/PageLoader.aspx?c={0}&RegularContentGuid={1}", Helper.Encrypt((int)Arad.SMS.Gateway.Business.UserControls.UI_RegularContents_Content, Session), RegularContentGuid));
            }
            catch (Exception ex)
            {
                ShowMessageBox(ex.Message, string.Empty, "danger");
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                Dictionary <Common.DeliveryStatus, List <string> > messageStatus = new Dictionary <Common.DeliveryStatus, List <string> >();
                List <int> lstValidStatus = new List <int>()
                {
                    1, 2, 4, 10, 14
                };

                string        uploadTarget      = Server.MapPath(string.Format("~/Uploads/{0}/", Helper.GetHostOfDomain(Request.Url.Host)));
                List <string> lstValidExtention = new List <string>();
                lstValidExtention.Add("xlsx");
                lstValidExtention.Add("xls");

                if (!Directory.Exists(uploadTarget))
                {
                    Directory.CreateDirectory(uploadTarget);
                }

                if (!fileUpload.HasFile)
                {
                    throw new Exception((Language.GetString("ErrorSelectFile")));
                }

                string fileExtention = Path.GetExtension(fileUpload.PostedFile.FileName).TrimStart('.');
                if (!lstValidExtention.Contains(fileExtention))
                {
                    throw new Exception((Language.GetString("InvalidFileExtension")));
                }

                string file = Path.GetFileName(fileUpload.PostedFile.FileName);
                fileUpload.SaveAs(uploadTarget + file);

                bool      firstRowHasColumnNames = true;
                DataTable dtb = new DataTable();

                switch (fileExtention.ToLower())
                {
                case "csv":
                    dtb = ImportFile.ImportCSV(Server.MapPath(string.Format("/Uploads/{0}", file)), firstRowHasColumnNames);
                    break;

                case "xls":
                case "xlsx":
                    dtb = ImportFile.ImportExcel(Server.MapPath(string.Format("/Uploads/{0}", file)), firstRowHasColumnNames);
                    break;
                }

                int    status;
                string mobile;

                foreach (DataRow row in dtb.Rows)
                {
                    mobile = Helper.GetLocalMobileNumber(Helper.GetString(row[0]));
                    status = Helper.GetInt(row[1]);

                    if (!lstValidStatus.Contains(status))
                    {
                        continue;
                    }

                    if (!messageStatus.ContainsKey((Common.DeliveryStatus)status))
                    {
                        messageStatus.Add((Common.DeliveryStatus)status, new List <string>());
                    }

                    if (!messageStatus[(Common.DeliveryStatus)status].Contains(mobile))
                    {
                        messageStatus[(Common.DeliveryStatus)status].Add(mobile);
                    }
                }

                if (messageStatus.Count > 0)
                {
                    Facade.OutboxNumber.UpdateDeliveryStatus(OutboxGuid, messageStatus);
                }

                Response.Redirect(string.Format("/PageLoader.aspx?c={0}", Helper.Encrypt((int)Arad.SMS.Gateway.Business.UserControls.UI_SmsReports_UserOutbox, Session)));
            }
            catch (Exception ex)
            {
                ShowMessageBox(ex.Message, string.Empty, "danger");
            }
        }