Exemplo n.º 1
0
        protected void Page_Init(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["alert"] == "notpass")
                {
                    Response.Write("<script>alert('لم يتم الحفظ');</script>");
                }
                Session["Table"] = null;
                if (Convert.ToInt32(Request.QueryString["id"].ToString()) > 0)
                {
                    ExcelSheets excelSheets = new ExcelSheets();
                    DataTable   dt          = excelSheets.getSheetItemsByID(Convert.ToInt32(Request.QueryString["id"].ToString()));

                    grid.DataSource   = dt;
                    grid.KeyFieldName = "ID";
                    grid.DataBind();
                    btnEdit.Visible = true;
                    btnSave.Visible = false;
                    DataColumn colid = dt.Columns["ID"];
                    dt.PrimaryKey  = new DataColumn[] { colid };
                    colid.ReadOnly = true;


                    Session["Table"] = dt;
                }
                else
                {
                    grid.DataSource   = GetTable();
                    grid.KeyFieldName = "ID";
                    grid.DataBind();
                }
            }
        }
Exemplo n.º 2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Request.Cookies["user"] == null)
     {
         Response.Redirect("~/Default.aspx");
     }
     else
     {
         if (!new UserSecurity().CheckFormPermission((int)Global.formSecurity.ViewsheetStyle, Request.Cookies["user"]["Permission"].ToString()))
         {
             Response.Redirect("~/HR/UnAuthorized.aspx");
         }
     }
     if (!IsPostBack)
     {
         if (Convert.ToInt32(Request.QueryString["id"].ToString()) > 0)
         {
             ExcelSheets excelSheets = new ExcelSheets();
             excelSheets.get(Convert.ToInt32(Request.QueryString["id"].ToString()));
             txtName.Text = excelSheets.SheetStyleName;
             DataTable dt = excelSheets.SheetItems;
             grid.DataSource = dt;
             grid.DataBind();
         }
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Froms the excel.
        /// </summary>
        /// <typeparam name="TEntity">The type of the entity.</typeparam>
        /// <typeparam name="TEntityDetail">The type of the entity detail.</typeparam>
        /// <param name="excelfile">The excelfile.</param>
        /// <param name="sheetNames">The sheet names.</param>
        /// <param name="cellExistin">The cell existin.</param>
        /// <param name="startRows">The start rows.</param>
        /// <returns>FromExcel</returns>
        public dynamic FromExcel <TEntity, TEntityDetail>(System.IO.FileInfo excelfile, string[] sheetNames, Dictionary <string, IEnumerable <string> > cellExistin = null, int[] startRows = null)
            where TEntity : class
            where TEntityDetail : class
        {
            if (startRows == null)
            {
                startRows = new int[] { 3, 3 };
            }

            if (cellExistin == null)
            {
                cellExistin = new Dictionary <string, IEnumerable <string> >();
            }

            var excelSheets = new ExcelSheets <TEntity, TEntityDetail>();

            using (ExcelPackage package = new ExcelPackage(excelfile))
            {
                var excelSheet = new ExcelSheet <TEntity>();
                excelSheet.Name = sheetNames[0];

                if (package.Workbook.Worksheets.Count == 0)
                {
                    excelSheet.Status  = false;
                    excelSheet.Message = $"{sheetNames[0]} not Found in Excel File.";
                    return(excelSheets);
                }

                ExcelWorksheet workSheet1 = package.Workbook.Worksheets.FirstOrDefault(x => x.Name.ToLower().Trim() == sheetNames[0].ToLower().Trim());
                ExcelWorksheet workSheet2;
                if (package.Workbook.Worksheets.Where(x => x.Name.ToLower().Trim() == sheetNames[1].ToLower().Trim()).Count() > 0)
                {
                    excelSheets.IsSingleSheet = false;
                    workSheet2 = package.Workbook.Worksheets.FirstOrDefault(x => x.Name.ToLower().Trim() == sheetNames[1].ToLower().Trim());
                }
                else
                {
                    startRows[1] = startRows[0];
                    excelSheets.IsSingleSheet = true;
                    workSheet2 = workSheet1;
                }

                excelSheets.WorkSheet1 = this.FromExcelSheet <TEntity>(workSheet1, sheetNames[0], cellExistin, startRows[0]);
                excelSheets.WorkSheet2 = this.FromExcelSheet <TEntityDetail>(workSheet2, sheetNames[1], cellExistin, startRows[1]);
                return(excelSheets);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Load Excel WorkSheets
        /// </summary>
        private void LoadExcelWorkSheets()
        {
            // Clear the Excel Sheets
            App.CallMethodInUISynchronizationContext(ClearExcelSheets, null);

            // Clear Selected Sheet to empty
            SelectedExcelSheet = string.Empty;

            string filePath = ExcelFilePath;

            // Get the List of Name of Worksheets
            List <string> worksheets = ExcelParser.GetWorksheetNames(filePath);

            //If List of worksheet names is not working then add them to ExcelWorksheets
            if (worksheets.Count > 0)
            {
                foreach (string worksheet in worksheets)
                {
                    ExcelSheets.Add(worksheet);
                }
            }
        }
Exemplo n.º 5
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            ExcelSheets excelSheets = new ExcelSheets();

            excelSheets.SheetStyleName = txtName.Text;

            excelSheets.OperatorID = 1;
            excelSheets.SheetItems = Session["Table"] as DataTable;
            HttpCookie myCookie = Request.Cookies["user"];

            excelSheets.OperatorID = Convert.ToInt32(myCookie.Values["userid"].ToString());
            int id = excelSheets.save();

            Session["Table"] = null;
            if (id > 0)
            {
                Response.Redirect("~/HR/ExcelSheetStyle.aspx?alert=success");
            }
            else
            {
                Response.Redirect("~/HR/CreatesheetStyle.aspx?id=0&&alret=notpass");
            }
        }
Exemplo n.º 6
0
 private void ClearExcelSheets(object obj)
 {
     ExcelSheets.Clear();
 }