예제 #1
0
        public IList <PakAnass> SearchCommon(PakAnass o, ViewDataDictionary v, string pageModelViewData, string listViewData)
        {
            Type t = o.GetType();

            int pDot = t.Namespace.LastIndexOf(".");
            int pLen = t.Namespace.Length;

            string dir = (pDot > 1 && (pDot < (pLen - 1))) ? (t.Namespace.Substring(pDot + 1, pLen - pDot - 1) + "/") : "";


            string qCount = dir + t.Name + "_Count";
            string qList  = dir + t.Name + "_List";

            IDBContext db = BaseRepo.Db;

            long count = db.SingleOrDefault <int>(qCount, o);

            BaseModel   m      = o as BaseModel;
            PagingModel pmodel = null;

            if (m.RowsPerPage <= 0)
            {
                pmodel = new PagingModel(count, 1, PagingModel.DEFAULT_RECORD_PER_PAGE);
            }
            else
            {
                pmodel = new PagingModel(count, m.CurrentPage, m.RowsPerPage);
            }

            v[pageModelViewData] = pmodel;

            IList <PakAnass> l = db.Fetch <PakAnass>(qList, o);

            return(l);
        }
예제 #2
0
        public void DownloadFileExcel(PakAnass pakanas, int?PageFlag)
        {
            byte[] result   = null;
            string fileName = null;

            try
            {
                if (PageFlag == 0)
                {
                    pakanas.RowsPerPage = Int32.MaxValue;
                }

                IList <PakAnass> data =
                    pakanasRepo.Search(pakanas, pakanas.CurrentPage,
                                       pakanas.RowsPerPage);


                fileName = string.Format("PakAanas-{0}.xls",
                                         DateTime.Now.ToString("yyyyMMddHHmmss"));
                result = pakanasRepo.GenerateDownloadFile(data);
            }
            catch (Exception e)
            {
                //
            }

            this.SendDataAsAttachment(fileName, result);
        }
예제 #3
0
        public JsonResult GetByKey(long?org_codeId)
        {
            AjaxResult ajaxResult = new AjaxResult();

            PakAnass result = null;

            IDBContext db = databaseManager.GetContext();

            try
            {
                result = pakanasRepo.GetByKey(org_codeId);

                ajaxResult.Result = AjaxResult.VALUE_SUCCESS;
                ajaxResult.Params = new object[] {
                    result
                };
            }
            catch (Exception ex)
            {
                ajaxResult.Result   = AjaxResult.VALUE_ERROR;
                ajaxResult.ErrMesgs = new string[] {
                    string.Format("{0} = {1}", ex.GetType().FullName, ex.Message)
                };
            }
            finally
            {
                db.Close();
            }

            return(Json(ajaxResult));
        }
예제 #4
0
        public long SearchCount(PakAnass pak)
        {
            dynamic args = new
            {
                org_code = pak.org_code,
                org_name = pak.org_name
            };
            long Result = Db.SingleOrDefault <int>("PakAnas/Pakanas_SearchCount", args);

            return(Result);
        }
예제 #5
0
        public PakAnass GetByKey(long?org_code)
        {
            dynamic args = new
            {
                org_Code = org_code
            };

            PakAnass result = Db.SingleOrDefault <PakAnass>("PakAnas/PakAnas_GetByKey", args);

            return(result);
        }
예제 #6
0
        private void DoSearch(PakAnass pakanas, int currentPage, int recordPerPage)
        {
            PagingModel pmodel = new PagingModel(pakanasRepo.SearchCount(pakanas),
                                                 currentPage, recordPerPage);

            ViewData["Paging"] = pmodel;

            IList <PakAnass> listData = pakanasRepo.Search(pakanas, pmodel.Start, pmodel.End);

            ViewData["ListDatapakanas"] = listData;
        }
예제 #7
0
        private void WriteDetailSingleData(HSSFWorkbook wb, ICellStyle cellStyle, PakAnass data,
                                           ISheet sheet1, int rowCount, int rowIndex, ICellStyle cellStyleData)
        {
            IRow row = sheet1.CreateRow(rowIndex);
            int  col = 0;

            NPOIWriter.createCellText(row, cellStyle, col++, data.org_code);
            NPOIWriter.createCellText(row, cellStyle, col++, data.org_name);


            sheet1.AutoSizeColumn(0);
        }
예제 #8
0
        public IList <PakAnass> Search(PakAnass pakanass, long rowStart, long rowEnd)
        {
            dynamic args = new
            {
                org_code      = pakanass.org_code,
                org_name      = pakanass.org_name,
                recordPerPage = rowStart,
                currentpage   = rowEnd
            };
            IList <PakAnass> Result = Db.Fetch <PakAnass>("PakAnas/Pakanas_Search", args);

            return(Result);
        }
예제 #9
0
        public ActionResult Search(PakAnass pakanas, int currentPage, int recordPerPage)
        {
            try
            {
                DoSearch(pakanas, currentPage, recordPerPage);
            }
            catch (Exception ex)
            {
                return(Json("Error : " + ex.Message, JsonRequestBehavior.AllowGet));
            }

            return(PartialView("_GridView"));
        }
예제 #10
0
        protected override void Startup()
        {
            Settings.Title = "Master PakAnas";

            int cureentPage   = 1;
            int recordPerPage = PagingModel.DEFAULT_RECORD_PER_PAGE;

            PakAnass pakanas = new PakAnass();

            getTypeSizeUpload();

            DoSearch(pakanas, cureentPage, recordPerPage);
        }
예제 #11
0
        public ActionResult AddEditSave(string screenMode, PakAnass data)
        {
            AjaxResult ajaxResult = new AjaxResult();
            RepoResult repoResult = null;
            IDBContext db         = databaseManager.GetContext();

            Toyota.Common.Credential.User u = Lookup.Get <Toyota.Common.Credential.User>();
            string userName = u.Username;

            try
            {
                repoResult = pakanasRepo.InsertUpdate(db, userName, data, screenMode);

                CopyPropertiesRepoToAjaxResult(repoResult, ajaxResult);

                if (AjaxResult.VALUE_ERROR.Equals(ajaxResult.Result))
                {
                    db.AbortTransaction();
                }
                else
                {
                    db.CommitTransaction();
                }
            }

            catch (Exception ex)
            {
                db.AbortTransaction();
                ajaxResult.Result   = AjaxResult.VALUE_ERROR;
                ajaxResult.ErrMesgs = new string[] {
                    string.Format("{0} = {1}", ex.GetType().FullName, ex.Message)
                };
            }
            finally
            {
                db.Close();
            }

            return(Json(ajaxResult));
        }
예제 #12
0
        public RepoResult InsertUpdate(IDBContext db, string userId,
                                       PakAnass data, string screenMode)
        {
            SqlParameter outputRetVal  = CreateSqlParameterOutputReturnValue("RetVal");
            SqlParameter outputErrMesg = CreateSqlParameterOutputErrMesg("ErrMesg");

            dynamic args = new
            {
                RetVal     = outputRetVal,
                ErrMesg    = outputErrMesg,
                userId     = userId,
                org_code   = data.org_code,
                org_name   = data.org_name,
                ScreenMode = screenMode
            };

            int result = db.Execute("PakAnas/_InsertUpdate", args);

            RepoResult repoResult = new RepoResult();

            repoResult.Result = RepoResult.VALUE_SUCCESS;

            if ((int)outputRetVal.Value != 0)
            {
                repoResult.Result = RepoResult.VALUE_ERROR;
                string errMesg = string.Empty;
                if (outputErrMesg != null && outputErrMesg.Value != null)

                {
                    errMesg = outputErrMesg.Value.ToString();
                }
                repoResult.ErrMesgs    = new string[1];
                repoResult.ErrMesgs[0] = errMesg;
            }

            return(repoResult);
        }
예제 #13
0
        private IList <PakAnass> GetDataLocalUploadExcel(HttpPostedFileBase file,
                                                         IList <string> errMesgs)
        {
            HSSFWorkbook hssfwb = null;

            using (System.IO.Stream file2 = file.InputStream)
            {
                hssfwb = new HSSFWorkbook(file2);
            }

            if (hssfwb == null)
            {
                throw new ArgumentException("Cannot create Workbook object from excel file" + file.FileName);
            }

            IRow             row         = null;
            ICell            cell        = null;
            IList <PakAnass> listPakanas = new List <PakAnass>();

            int  indexRow       = DATA_ROW_INDEX_START;
            bool isAllCellEmpty = true;
            bool isBreak        = false;

            ISheet sheet = hssfwb.GetSheetAt(0);

            for (indexRow = DATA_ROW_INDEX_START; indexRow <= sheet.LastRowNum; indexRow++)
            {
                isAllCellEmpty = true;
                isBreak        = false;
                row            = sheet.GetRow(indexRow);
                row            = sheet.GetRow(indexRow);
                if (row != null) //null is when the row only contains empty celss
                {
                    PakAnass Pak = new PakAnass();

                    //org_code
                    try
                    {
                        cell = row.GetCell(0);
                        if (cell == null || cell.CellType == CellType.BLANK)
                        {
                            cell = row.GetCell(1);
                            if (indexRow != DATA_ROW_INDEX_START && (cell == null || cell.CellType == CellType.BLANK))
                            {
                                break;
                            }
                            else
                            {
                                errMesgs.Add(string.Format("org_code row {0} is empty", indexRow + 1));
                                isAllCellEmpty = true;
                            }
                        }
                        else
                        {
                            if (cell.CellType == CellType.NUMERIC)
                            {
                                Pak.org_code   = Convert.ToString(cell.NumericCellValue);
                                isAllCellEmpty = false;
                            }
                            else if (cell.CellType == CellType.STRING)
                            {
                                Pak.org_code   = cell.StringCellValue;
                                isAllCellEmpty = false;
                            }
                            else
                            {
                                errMesgs.Add(string.Format("org_code row {0} is incorrect Format", indexRow + 1));
                                isAllCellEmpty = true;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        errMesgs.Add(string.Format("Unable To get value of PakAnas No at row {0}, Error Mesg : {1}",
                                                   indexRow + 1, ex.Message));
                    }

                    //org_name
                    try
                    {
                        cell = row.GetCell(1);
                        if (cell.CellType == CellType.BLANK)
                        {
                            errMesgs.Add(string.Format("org_name row {0} is empty", indexRow + 1));
                            isAllCellEmpty = true;
                        }
                        else
                        {
                            if (cell.CellType == CellType.STRING)
                            {
                                Pak.org_name   = cell.StringCellValue;
                                isAllCellEmpty = false;
                            }
                            else
                            {
                                errMesgs.Add(string.Format("org_name row {0} is Incorrect Format", indexRow + 1));
                                isAllCellEmpty = true;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        errMesgs.Add(string.Format("Unable to get value of org_name at row {0}, Error Mesg : {1}",
                                                   indexRow + 1, ex.Message));
                        isAllCellEmpty = true;
                    }

                    listPakanas.Add(Pak);
                }
            }
            return(listPakanas);
        }