Ejemplo n.º 1
0
        public async Task <JsonResult> UpdatePatient(ImportClass tempData)
        {
            dynamic jsData      = JsonConvert.DeserializeObject(tempData.receive);
            var     fileID      = HttpContext.Session.GetInt32(SessionFile);
            string  DateOfBirth = jsData.DOB;

            Patient patient = new Patient();

            patient.PatientID   = jsData.Patient_ID;
            patient.PatientCode = jsData.Patient_Code;
            patient.PatientName = jsData.Patient_Name;
            patient.Address     = jsData.Address;
            patient.GenderID    = jsData.GenderID;
            //patient.FileID = Convert.ToInt32(fileID);

            if (!string.IsNullOrEmpty(DateOfBirth))
            {
                string[] datePart = DateOfBirth.Split('/');
                patient.DOB = new DateTime(Convert.ToInt32(datePart[2]), Convert.ToInt32(datePart[1]), Convert.ToInt32(datePart[0]));
            }

            int message = new PatientDao().EditPatient(patient);

            return(Json(new
            {
                status = message
            }));
        }
Ejemplo n.º 2
0
        private void importButton_Click(object sender, EventArgs e)
        {
            if (filePath.Equals(""))
            {
                MessageBox.Show("Please browse a file first.", "Import",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            DialogResult result = MessageBox.Show("The process can't be undo after importing...\n" +
                                                  "Do you really want to import?", "Import", MessageBoxButtons.YesNo,
                                                  MessageBoxIcon.Question, MessageBoxDefaultButton.Button1
                                                  );

            if (result == DialogResult.Yes)
            {
                importingPanel.Visible = true;
                string table = "";
                if (memberRadioButton.Checked)
                {
                    table = "Member";
                }
                else if (bookRadioButton.Checked)
                {
                    table = "Book";
                }

                int[] sucessFail = ImportClass.ImportMembers(table, filePath);
                importProgress.IsRunning = false;
                MessageBox.Show("Import Sucess With\n\n" +
                                "Sucess\t: " + sucessFail[0].ToString() + "\n" +
                                "Fail\t: " + sucessFail[1].ToString());
            }
        }
Ejemplo n.º 3
0
        public void When_adding_by_type_then_object_should_automatically_be_instantiated()
        {
            var ctx = new CompositionContext();
            ctx.AddPart<ExportClass, ExportClass>();

            var obj = new ImportClass();
            ctx.SatisfyImports(obj);

            Assert.IsTrue(obj.Object != null);
        }
Ejemplo n.º 4
0
        public void When_adding_by_type_then_object_should_automatically_be_instantiated()
        {
            var ctx = new CompositionContext();

            ctx.AddPart <ExportClass, ExportClass>();

            var obj = new ImportClass();

            ctx.SatisfyImports(obj);

            Assert.IsTrue(obj.Object != null);
        }
Ejemplo n.º 5
0
        public void When_adding_object_then_it_should_be_loadable()
        {
            var ctx  = new CompositionContext();
            var part = new ExportClass();

            ctx.AddPart <ExportClass, ExportClass>(part);

            var obj = new ImportClass();

            ctx.SatisfyImports(obj);

            Assert.AreEqual(part, obj.Object);
        }
Ejemplo n.º 6
0
        public void When_adding_object_then_it_should_be_loadable()
        {
            var ctx = new CompositionContext();
            var part = new ExportClass();
            ctx.AddPart<ExportClass, ExportClass>(part);

            var obj = new ImportClass();
            ctx.SatisfyImports(obj);

            Assert.AreEqual(part, obj.Object);
        }
        /// <summary>
        /// 檢查匯入的 CSV資料.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="importSalesCodes">The import zip codes.</param>
        /// <returns></returns>
        public CheckResult CheckImportData(
            string fileName,
            List<ImportClass> importSalesCodes)
        {
            var result = new CheckResult();

            var targetFile = new FileInfo(fileName);

            if (!targetFile.Exists)
            {
                result.ID = Guid.NewGuid();
                result.Success = false;
                result.ErrorCount = 0;
                result.ErrorMessage = "匯入的資料檔案不存在";
                return result;
            }

            var excelFile = new ExcelQueryFactory(fileName);

            //欄位對映
            excelFile.AddMapping<ImportClass>(x => x.Code, "序號");


            //SheetName
            var excelContent = excelFile.Worksheet<ImportClass>("促銷碼管理");
            int errorCount = 0;
            int rowIndex = 1;
            var importErrorMessages = new List<string>();

            //檢查資料
            foreach (var row in excelContent)
            {

                var errorMessage = new StringBuilder();
                var SalesCode = new ImportClass();

                //CityName
                if (string.IsNullOrWhiteSpace(row.Code))
                {
                    errorMessage.Append("不能為空白 ");
                }
                else
                {
                    bool Check = IsNumOrEn(row.Code);
                    if (row.Code.Length == 14 && Check == true)
                    {
                    }
                    else if (row.Code.Length == 14 && Check == false)
                    {
                        errorMessage.Append("包含特殊字元 ");
                    }
                    else if (row.Code.Length > 14 && Check == true)
                    {
                        errorMessage.Append("大於14位數 ");
                    }
                    else if (row.Code.Length > 14 && Check == false)
                    {
                        errorMessage.Append("大於14位數,且包含特殊字元 ");
                    }
                    else if (row.Code.Length < 14 && Check == true)
                    {
                        errorMessage.Append("小於14位數 ");
                    }
                    else
                    {
                        errorMessage.Append("小於14位數,且包含特殊字元 ");
                    }
                }

                SalesCode.Code = row.Code;
                //=============================================================================
                if (errorMessage.Length > 0)
                {
                    errorCount += 1;
                    importErrorMessages.Add(string.Format(
                        "第 {0} 列資料發現錯誤:{1}{2}",
                        rowIndex,
                        errorMessage,
                        "<br/>"));
                }
                importSalesCodes.Add(SalesCode);
                rowIndex += 1;
            }

            try
            {
                result.ID = Guid.NewGuid();
                result.Success = errorCount.Equals(0);
                result.RowCount = importSalesCodes.Count;
                result.ErrorCount = errorCount;

                string allErrorMessage = string.Empty;

                foreach (var message in importErrorMessages)
                {
                    allErrorMessage += message;
                }

                result.ErrorMessage = allErrorMessage;

                return result;
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            var importClass = new ImportClass();

            importClass.ImportFile(args);
        }
Ejemplo n.º 9
0
        private void OpenExcel(int BoxNum)
        {
            OpenFileDialog open = new OpenFileDialog
            {
                Filter = "Excel (*.XLSX)|*.xlsx|all file|*.*"
            };

            open.ShowDialog();
            try
            {
                XSSFWorkbook xss;
                using (FileStream fs = new FileStream(open.FileName, FileMode.Open, FileAccess.Read))
                {
                    xss = new XSSFWorkbook(fs);
                }

                boxes = new List <MyModel>();

                IndexHeaders  = new List <Excel>();
                IndexContents = new List <Excel>();
                IndexBodies   = new List <Excel>();
                Buttones      = new List <string>();

                AddContents = new List <Excel>();

                ImportBidies = new ImportClass();
                for (int t = 0; t < BoxNum + 4; t++)
                {
                    if (t == 0)
                    {
                        XSSFSheet sheet = (XSSFSheet)xss.GetSheetAt(t);

                        int cot = sheet.LastRowNum;
                        //按钮
                        for (int i = 1; i <= cot; i++)
                        {
                            string btn = sheet.GetRow(i).GetCell(6) == null ? "" : sheet.GetRow(i).GetCell(6).ToString();
                            if (String.IsNullOrEmpty(btn))
                            {
                                break;
                            }
                            Buttones.Add(btn);
                        }

                        //控件、查询字段
                        for (int i = 1; i <= cot; i++)
                        {
                            Excel sFC = new Excel();
                            sFC.CONTROL_CODE = sheet.GetRow(i).GetCell(2) == null ? "" : sheet.GetRow(i).GetCell(2).ToString();
                            sFC.SEARCH_CODE  = sheet.GetRow(i).GetCell(3) == null ? "" : sheet.GetRow(i).GetCell(3).ToString();
                            sFC.SEARCH_NAME  = sheet.GetRow(i).GetCell(4) == null ? "" : sheet.GetRow(i).GetCell(4).ToString();
                            string api = sheet.GetRow(i).GetCell(5) == null ? "" : sheet.GetRow(i).GetCell(5).ToString();
                            sFC.IsApi = api == "YES" ? true : false;
                            if (string.IsNullOrEmpty(sFC.CONTROL_CODE))
                            {
                                break;
                            }
                            IndexContents.Add(sFC);
                        }
                        //表格
                        for (int i = 1; i <= cot; i++)
                        {
                            Excel sFC = new Excel();
                            sFC.GRID_CODE = sheet.GetRow(i).GetCell(0) == null ? "" : sheet.GetRow(i).GetCell(0).ToString();
                            sFC.GRID_NAME = sheet.GetRow(i).GetCell(1) == null ? "" : sheet.GetRow(i).GetCell(1).ToString();
                            if (String.IsNullOrEmpty(sFC.GRID_CODE) || string.IsNullOrEmpty(sFC.GRID_NAME))
                            {
                                break;
                            }
                            IndexBodies.Add(sFC);
                        }
                    }
                    else if (t == 1 && AddChecked)
                    {
                        List <excel> sFCs  = new List <excel>();
                        XSSFSheet    sheet = (XSSFSheet)xss.GetSheetAt(t);

                        int cot = sheet.LastRowNum;
                        //控件、查询字段
                        for (int i = 1; i <= cot; i++)
                        {
                            Excel sFC = new Excel();
                            sFC.CONTROL_CODE = sheet.GetRow(i).GetCell(0) == null ? "" : sheet.GetRow(i).GetCell(0).ToString();
                            sFC.SEARCH_CODE  = sheet.GetRow(i).GetCell(1) == null ? "" : sheet.GetRow(i).GetCell(1).ToString();
                            sFC.SEARCH_NAME  = sheet.GetRow(i).GetCell(2) == null ? "" : sheet.GetRow(i).GetCell(2).ToString();

                            if (string.IsNullOrEmpty(sFC.CONTROL_CODE))
                            {
                                break;
                            }
                            AddContents.Add(sFC);
                        }
                    }
                    else if (t == 3 && ImportChecked)
                    {
                        XSSFSheet sheet = (XSSFSheet)xss.GetSheetAt(t);

                        int cot = sheet.LastRowNum;
                        for (int i = 1; i <= cot; i++)
                        {
                            Im im = new Im();
                            im.GRID_CODE = sheet.GetRow(i).GetCell(0) == null ? "" : sheet.GetRow(i).GetCell(0).ToString();
                            im.GRID_NAME = sheet.GetRow(i).GetCell(1) == null ? "" : sheet.GetRow(i).GetCell(1).ToString();
                            if (string.IsNullOrEmpty(im.GRID_CODE) || string.IsNullOrEmpty(im.GRID_NAME))
                            {
                                break;
                            }
                            ImportBidies.Body.Add(im);
                        }

                        for (int i = 1; i <= cot; i++)
                        {
                            string EMPTY_CODE = sheet.GetRow(i).GetCell(2) == null ? "" : sheet.GetRow(i).GetCell(2).ToString();
                            if (string.IsNullOrEmpty(EMPTY_CODE))
                            {
                                break;
                            }
                            ImportBidies.EMPTY_CODE.Add(EMPTY_CODE);
                        }

                        for (int i = 1; i <= cot; i++)
                        {
                            string REPEAT_CODE = sheet.GetRow(i).GetCell(3) == null ? "" : sheet.GetRow(i).GetCell(3).ToString();
                            if (string.IsNullOrEmpty(REPEAT_CODE))
                            {
                                break;
                            }
                            ImportBidies.REPEAT_CODE.Add(REPEAT_CODE);
                        }
                    }
                    else if (t > 3)
                    {
                        XSSFSheet sheet = (XSSFSheet)xss.GetSheetAt(t);

                        int     cot = sheet.LastRowNum;
                        MyModel my  = new MyModel();
                        my.BOX_NAME    = sheet.GetRow(1).GetCell(0) == null ? "" : sheet.GetRow(1).GetCell(0).ToString();
                        my.BOX_CODE    = sheet.GetRow(1).GetCell(1) == null ? "" : sheet.GetRow(1).GetCell(1).ToString();
                        my.SEARCH_CODE = sheet.GetRow(1).GetCell(4) == null ? "" : sheet.GetRow(1).GetCell(4).ToString();
                        for (int i = 1; i <= cot; i++)
                        {
                            Excel excel = new Excel();
                            excel.GRID_CODE = sheet.GetRow(i).GetCell(2) == null ? "" : sheet.GetRow(i).GetCell(2).ToString();
                            excel.GRID_NAME = sheet.GetRow(i).GetCell(3) == null ? "" : sheet.GetRow(i).GetCell(3).ToString();
                            if (String.IsNullOrEmpty(excel.GRID_CODE) || String.IsNullOrEmpty(excel.GRID_NAME))
                            {
                                break;
                            }
                            my.Body.Add(excel);
                        }
                        boxes.Add(my);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }