Exemplo n.º 1
0
        /// <summary>对照项目
        ///
        /// </summary>
        /// <param name="Hrow">医院选中行</param>
        /// <param name="Drow">达安选中行</param>
        /// <returns>是否成功</returns>
        private bool Save(DataGridViewRow Hrow, DataGridViewRow Drow)
        {
            bool b = true;

            try
            {
                VDAListests      Hosptest    = Hrow.DataBoundItem as VDAListests;
                DADicttestitem   Daantest    = Drow.DataBoundItem as DADicttestitem;
                List <DATestmap> testmapList = new List <DATestmap>();
                DATestmap        testmap     = new DATestmap();
                //取出列表值,用于保存
                testmap.Customertestcode = Hosptest.Testcode;
                testmap.Customertestname = Hosptest.Testname;
                testmap.Datestcode       = Daantest.Datestcode;
                testmap.Datestname       = Daantest.Datestname;
                testmapList.Add(testmap);
                if (testmapBll.SaveDATestmapList(testmapList))
                {
                    ShowMessageHelper.ShowBoxMsg("保存对照成功!");
                    cacheMapList = new DATestmapBLL().GetDATestmapList(null);
                }
                else
                {
                    ShowMessageHelper.ShowBoxMsg("保存对照失败!");
                    b = false;
                }
            }
            catch (Exception ex)
            {
                ShowMessageHelper.ShowBoxMsg("保存对照出错:" + ex.Message);
                b = false;
            }
            return(b);
        }
Exemplo n.º 2
0
        //对照:把需要保存的匹配信息加到下面两个列表后,保存到数据库表DATestmap
        private void btnSave_Click(object sender, EventArgs e)
        {
            //验证
            if (gvMapHospital.Rows.Count == 0 || gvMapDaan.Rows.Count == 0)
            {
                ShowMessageHelper.ShowBoxMsg("请选择要保存对照的项目!");
                return;
            }

            //单项只能对照一个单项
            if (gvMapHospital.Rows[0].Cells["gvMapHospitalGroup"].Value.ToString() == "0" && gvMapDaan.Rows.Count != 1)
            {
                ShowMessageHelper.ShowBoxMsg("医院单项只能对应一个达安单项!");
                return;
            }

            try
            {
                List <DATestmap> testmapList = new List <DATestmap>();
                for (int i = 0; i < gvMapDaan.Rows.Count; i++)
                {
                    DATestmap testmap = new DATestmap();
                    //已经存在对应 修改操作
                    //if (gvMapHospital.Rows[0].Cells[0].Value != null)
                    //{
                    //    testmap.Testmapid = Convert.ToDecimal(gvMapHospital.Rows[0].Cells[0].Value.ToString());
                    //}
                    //取出列表值,用于保存
                    testmap.Customertestcode = gvMapHospital.Rows[0].Cells["gvMapHoapitalTestCode"].Value.ToString();
                    testmap.Customertestname = gvMapHospital.Rows[0].Cells["gvMapHoapitalTestName"].Value.ToString();
                    testmap.Datestcode       = gvMapDaan.Rows[i].Cells["gvMapDaanDaTestCode"].Value.ToString();
                    testmap.Datestname       = gvMapDaan.Rows[i].Cells["gvMapDaanDaTestName"].Value.ToString();
                    testmap.Createtime       = DateTime.Now;
                    testmapList.Add(testmap);
                }
                if (testmapBll.SaveDATestmapList(testmapList))
                {
                    ShowMessageHelper.ShowBoxMsg("保存对照成功!");
                    doFilter();
                }
                else
                {
                    ShowMessageHelper.ShowBoxMsg("保存对照失败!");
                }
            }
            catch (Exception ex)
            {
                ShowMessageHelper.ShowBoxMsg("保存对照出错:" + ex.Message);
            }
        }
        //从Excel导入数据
        private void ImportExcel()
        {
            OpenFileDialog openDialog = new OpenFileDialog();

            openDialog.Filter           = "Execl files (*.xls)|*.xls|(*.xlsx)|*.xlsx";
            openDialog.FilterIndex      = 0;
            openDialog.RestoreDirectory = true;
            openDialog.Title            = "打开Excel文件";

            string fileName = string.Empty;//要上传的文件名

            if (openDialog.ShowDialog() == DialogResult.OK)
            {
                WinFileTransporter wFile = new WinFileTransporter();

                fileName = openDialog.FileName;
                string uriFiles   = string.Empty;//保存到服务器路径
                string folderName = Application.StartupPath + "\\importFiles";

                if (!Directory.Exists(folderName))//如果路径不存在则创建
                {
                    Directory.CreateDirectory(folderName);
                }

                try
                {
                    if (wFile.UpLoadFile(fileName, folderName, out uriFiles, true))
                    {
                        DataTable dt       = new DataTable();
                        string    errorStr = string.Empty;
                        AsposeExcelTools.ExcelFileToDataTable(uriFiles, out dt, out errorStr);//读取表格数据,转换为datatable
                        List <DATestmap> errorList   = new List <DATestmap>();
                        List <DATestmap> testmapList = new List <DATestmap>();
                        if (dt != null && dt.Rows.Count > 0)
                        {
                            for (int i = 0; i < dt.Rows.Count; i++)
                            {
                                DATestmap testmap = new DATestmap();
                                testmap.Customertestcode = dt.Rows[i]["医院项目代码(项目导入唯一标识)"].ToString().Trim();
                                testmap.Customertestname = dt.Rows[i]["医院项目名称(作为对应参考,不做导入标识)"].ToString().Trim();
                                testmap.Datestcode       = dt.Rows[i]["达安项目代码(项目导入唯一标识)"].ToString().Trim();
                                testmap.Datestname       = dt.Rows[i]["达安项目名称(作为对应参考,不做导入标识)"].ToString().Trim();
                                if (testmap.Customertestcode == string.Empty)
                                {
                                    errorList.Add(testmap);
                                    errorStr += "导入错误:医院项目代码为空,";
                                    continue;
                                }
                                if (testmap.Datestcode == string.Empty)
                                {
                                    errorList.Add(testmap);
                                    errorStr += "导入错误:达安项目代码为空,";
                                    continue;
                                }
                                if (testmap.Customertestname == string.Empty)
                                {
                                    errorList.Add(testmap);
                                    errorStr += "导入错误:医院项目名称为空,";
                                    continue;
                                }
                                if (testmap.Datestname == string.Empty)
                                {
                                    errorList.Add(testmap);
                                    errorStr += "导入错误:达安项目名称为空,";
                                    continue;
                                }
                                if (!IsExistHosp(testmap.Customertestcode, testmap.Customertestname))
                                {
                                    errorList.Add(testmap);
                                    errorStr += "导入错误:医院项目信息不存在,";
                                    continue;
                                }
                                if (!IsExistDaan(testmap.Datestcode, testmap.Datestname))
                                {
                                    errorList.Add(testmap);
                                    errorStr += "导入错误:达安项目信息不存在,";
                                    continue;
                                }
                                //如果在testmap表已经存在医院项目代码的记录,记录对象及错误信息
                                //if (IsExist(testmap.Customertestcode))
                                //{
                                //    errorList.Add(testmap);
                                //    errorStr += "导入失败:该医院项目已存在对应的匹配信息,";
                                //    continue;
                                //}
                                errorList.Add(testmap);
                                errorStr += "导入成功,";

                                testmapList.Add(testmap);
                            }
                            //if (testmapBll.ImportDaTestmap(testmapList))
                            if (testmapBll.SaveDATestmapList(testmapList))
                            {
                                //弹出错误信息
                                //if (errorList != null)
                                //{
                                FrmItemHoapitalAndDaanImportError errorFrm = new FrmItemHoapitalAndDaanImportError();
                                errorFrm.StrFailed     = errorStr;
                                errorFrm.testmapList   = errorList;
                                errorFrm.StartPosition = FormStartPosition.CenterScreen;
                                errorFrm.ShowDialog();
                                BindData();
                                //}
                                //else
                                //{
                                //    ShowMessageHelper.ShowBoxMsg("导入成功!");
                                //}
                            }
                            else
                            {
                                ShowMessageHelper.ShowBoxMsg("导入失败!");
                            }
                        }
                        else
                        {
                            ShowMessageHelper.ShowBoxMsg("没有数据导入!");
                        }
                    }
                }
                catch (Exception e)
                {
                    ShowMessageHelper.ShowBoxMsg("导入的过程中发生了异常:" + e.Message);
                }

                finally
                {
                    //删除文件
                    if (File.Exists(uriFiles))
                    {
                        File.Delete(uriFiles);
                    }
                }
            }
        }