コード例 #1
0
        public ActionResult SaveEmployeeRelationships(EmployeeRelationships obj)
        {
            var db = new EmployeeRelationshipsDAL();

            obj.CreatedBy  = Global.CurrentUser.UserID;
            obj.ModifiedBy = Global.CurrentUser.UserID;
            int staffID = 0;

            int.TryParse(Session["StaffID"].ToString(), out staffID);
            var result = db.SaveEmployeeRelationships(Global.CurrentUser.RoleId, 1, obj, staffID);

            if (result.IsSuccess == true && obj.StaffID == 0)
            {
                result.Message = AppRes.MSG_INSERT_SUCCESSFUL;
            }
            else if (result.IsSuccess == true && obj.StaffID != 0)
            {
                result.Message = AppRes.MS_Update_success;
            }
            return(Content(JsonConvert.SerializeObject(new
            {
                result
            })));
        }
コード例 #2
0
        public ActionResult UploadRelationships()
        {
            if (Request != null)
            {
                HttpPostedFileBase file = Request.Files["file-0"];
                if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName))
                {
                    string fileName          = file.FileName;
                    string fileContentType   = file.ContentType;
                    byte[] fileBytes         = new byte[file.ContentLength];
                    var    data              = file.InputStream.Read(fileBytes, 0, Convert.ToInt32(file.ContentLength));
                    var    relationshipsList = new List <EmployeeRelationships>();

                    using (var package = new ExcelPackage(file.InputStream))
                    {
                        var currentSheet = package.Workbook.Worksheets;
                        var workSheet    = currentSheet.First();
                        var noOfCol      = workSheet.Dimension.End.Column;
                        var noOfRow      = workSheet.Dimension.End.Row;

                        for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++)
                        {
                            var relationships = new EmployeeRelationships();
                            relationships.AutoID           = Convert.ToInt32(workSheet.Cells[rowIterator, 1].Value.ToString());
                            relationships.StaffName        = workSheet.Cells[rowIterator, 3].Value == null ? null : workSheet.Cells[rowIterator, 3].Value.ToString();
                            relationships.OrganizationUnit = workSheet.Cells[rowIterator, 2].Value == null ? null : workSheet.Cells[rowIterator, 2].Value.ToString();
                            relationships.Name             = workSheet.Cells[rowIterator, 5].Value == null ? null : workSheet.Cells[rowIterator, 5].Value.ToString();
                            relationships.RelationshipName = workSheet.Cells[rowIterator, 4].Value == null ? null : workSheet.Cells[rowIterator, 4].Value.ToString();
                            relationships.BirthDay         = workSheet.Cells[rowIterator, 6].Value == null?Convert.ToDateTime(null) : Convert.ToDateTime(workSheet.Cells[rowIterator, 6].Value.ToString());

                            relationships.Phone         = workSheet.Cells[rowIterator, 7].Value == null ? null : workSheet.Cells[rowIterator, 7].Value.ToString();
                            relationships.Deduction     = Convert.ToBoolean(workSheet.Cells[rowIterator, 8].Value.ToString());
                            relationships.DeductionCode = workSheet.Cells[rowIterator, 9].Value == null ? null : workSheet.Cells[rowIterator, 9].Value.ToString();
                            relationships.DeductionFrom = workSheet.Cells[rowIterator, 10].Value == null?Convert.ToDateTime(null) : Convert.ToDateTime(workSheet.Cells[rowIterator, 10].Value.ToString());

                            relationships.DeductionTo = workSheet.Cells[rowIterator, 11].Value == null?Convert.ToDateTime(null) : Convert.ToDateTime(workSheet.Cells[rowIterator, 11].Value.ToString());

                            relationships.StatusName = workSheet.Cells[rowIterator, 12].Value == null ? null : workSheet.Cells[rowIterator, 12].Value.ToString();
                            relationships.Note       = workSheet.Cells[rowIterator, 13].Value == null ? null : workSheet.Cells[rowIterator, 13].Value.ToString();
                            if (relationships.BirthDay == Convert.ToDateTime("01/01/0001 12:00:00 AM"))
                            {
                                relationships.BirthDay = null;
                            }
                            if (relationships.DeductionFrom == Convert.ToDateTime("01/01/0001 12:00:00 AM"))
                            {
                                relationships.DeductionFrom = null;
                            }
                            if (relationships.DeductionTo == Convert.ToDateTime("01/01/0001 12:00:00 AM"))
                            {
                                relationships.DeductionTo = null;
                            }
                            relationshipsList.Add(relationships);
                        }
                    }
                    var db     = new EmployeeRelationshipsDAL();
                    var result = db.ImportExcelRelationships(relationshipsList);
                    if (result.IsSuccess == true)
                    {
                        result.Message = AppRes.ImportExcelSuccess;
                    }
                    else
                    {
                        result.Message = AppRes.ImportExcelFailed;
                    }
                    return(Content(JsonConvert.SerializeObject(new
                    {
                        result
                    })));
                }
            }
            return(View("Index"));
        }