private void UpdateCollections() { OrginMinerals = new ObservableCollection <IMineral>(); OrginHeteMinerals = new ObservableCollection <IMineral>(); OrginHomoMinerals = new ObservableCollection <IMineral>(); for (int i = 0; i < OrginMineralDs.Tables.Count; i++) { for (int j = 0; j < OrginMineralDs.Tables[i].Rows.Count; j++) { if (OrginMineralDs.Tables[i].TableName.Contains("非均质矿物")) { HeterogeneousMineralInfo hete = (HeterogeneousMineralInfo)FillInfoByDataRow(OrginMineralDs.Tables[i].Rows[j], 2); OrginMinerals.Add(hete); OrginHeteMinerals.Add(hete); } else { HomogeneousMineralInfo h**o = (HomogeneousMineralInfo)FillInfoByDataRow(OrginMineralDs.Tables[i].Rows[j], 1); OrginMinerals.Add(h**o); OrginHomoMinerals.Add(h**o); } } } }
/// <summary> /// 通过文本将实体填充 /// </summary> /// <param name="type"></param> private void FillEntityByTextBox(int type) { if (type == 1) { HomogeneousMineralInfo h**o = curMineral as HomogeneousMineralInfo; h**o.ID = 0; h**o.ChineseName = this.Txt_ChineseName.Text.Trim(); h**o.EnglishName = this.Txt_EnglishName.Text.Trim(); h**o.ChemicalFormula = this.Txt_ChemicalFormula.Text.Trim(); h**o.Syngony = this.Txt_Syngony.Text.Trim(); h**o.NonUniformity = this.Txt_NonUniformity.Text.Trim(); h**o.Reflectivity = this.Txt_Reflectivity.Text.Trim(); h**o.Hardness = this.Txt_Hardness.Text.Trim(); h**o.ReflectionColor = this.Txt_ReflectionColor.Text.Trim(); if (!string.IsNullOrEmpty(this.Txt_Rr.Text.Trim())) { h**o.Rr = this.Txt_Rr.Text.Trim().Replace("°", null); } else { h**o.Rr = this.Txt_Rr.Text.Trim(); } h**o.DRr = this.Txt_DRr.Text.Trim(); h**o.InternalReflection = this.Txt_InternalReflection.Text.Trim(); h**o.Origin = this.Txt_Origin.Text.Trim(); h**o.IMK = this.Txt_IMK.Text.Trim(); curMineral = h**o; } else { HeterogeneousMineralInfo hete = curMineral as HeterogeneousMineralInfo; hete.ID = 0; hete.ChineseName = this.Txt_ChineseName_No.Text.Trim(); hete.EnglishName = this.Txt_EnglishName_No.Text.Trim(); hete.ChemicalFormula = this.Txt_ChemicalFormula_No.Text.Trim(); hete.Syngony = this.Txt_Syngony_No.Text.Trim(); hete.NonUniformity = this.Txt_NonUniformity_No.Text.Trim(); hete.Reflectivity = this.Txt_Reflectivity_No.Text.Trim(); hete.Hardness = this.Txt_Hardness_No.Text.Trim(); hete.ReflectionColor = this.Txt_ReflectionColor_No.Text.Trim(); hete.Bireflection = this.Txt_Bireflection_No.Text.Trim(); if (!string.IsNullOrEmpty(this.Txt_Ar_No.Text.Trim())) { hete.Ar = this.Txt_Ar_No.Text.Trim().Replace("°", null); } else { hete.Ar = this.Txt_Ar_No.Text.Trim(); } hete.DAr = this.Txt_DAr_No.Text.Trim(); hete.Rs = this.Txt_Rs_No.Text.Trim(); hete.Ps = this.Txt_Ps_No.Text.Trim(); hete.DRr = this.Txt_DRr_No.Text.Trim(); hete.ReflectionDAR = this.Txt_ReflectionDAR_No.Text.Trim(); hete.InternalReflection = this.Txt_InternalReflection_No.Text.Trim(); hete.Origin = this.Txt_Origin_No.Text.Trim(); hete.IMK = this.Txt_IMK_No.Text.Trim(); curMineral = hete; } }
/// <summary> /// 通过实体将文本框填充 /// </summary> /// <param name="mineral"></param> private void InitTextByEntity(IMineral mineral) { curMineral = mineral; if (mineral.mineralType == 1) //若是均质矿物 { HomogeneousMineralInfo homogeneousMineral = (HomogeneousMineralInfo)mineral; this.Txt_ChineseName.Text = homogeneousMineral.ChineseName; this.Txt_EnglishName.Text = homogeneousMineral.EnglishName; this.Txt_ChemicalFormula.Text = homogeneousMineral.ChemicalFormula; this.Txt_Syngony.Text = homogeneousMineral.Syngony; this.Txt_NonUniformity.Text = homogeneousMineral.NonUniformity; this.Txt_Reflectivity.Text = homogeneousMineral.Reflectivity; this.Txt_Hardness.Text = homogeneousMineral.Hardness; this.Txt_ReflectionColor.Text = homogeneousMineral.ReflectionColor; this.Txt_Rr.Text = string.IsNullOrEmpty(homogeneousMineral.Rr)?"":homogeneousMineral.Rr + "°"; this.Txt_DRr.Text = homogeneousMineral.DRr; this.Txt_InternalReflection.Text = homogeneousMineral.InternalReflection; this.Txt_Origin.Text = homogeneousMineral.Origin; this.Txt_IMK.Text = homogeneousMineral.IMK; ShowHomoMineralInfoView(); } else if (mineral.mineralType == 2) //若是非均质矿物 { HeterogeneousMineralInfo heterogeneousMineral = (HeterogeneousMineralInfo)mineral; this.Txt_ChineseName_No.Text = heterogeneousMineral.ChineseName; this.Txt_EnglishName_No.Text = heterogeneousMineral.EnglishName; this.Txt_ChemicalFormula_No.Text = heterogeneousMineral.ChemicalFormula; this.Txt_Syngony_No.Text = heterogeneousMineral.Syngony; this.Txt_NonUniformity_No.Text = heterogeneousMineral.NonUniformity; this.Txt_Reflectivity_No.Text = heterogeneousMineral.Reflectivity; this.Txt_Hardness_No.Text = heterogeneousMineral.Hardness; this.Txt_ReflectionColor_No.Text = heterogeneousMineral.ReflectionColor; this.Txt_Bireflection_No.Text = heterogeneousMineral.Bireflection; this.Txt_Ar_No.Text = string.IsNullOrEmpty(heterogeneousMineral.Ar) ? "" : heterogeneousMineral.Ar + "°"; this.Txt_DAr_No.Text = heterogeneousMineral.DAr; this.Txt_Rs_No.Text = heterogeneousMineral.Rs; this.Txt_Ps_No.Text = heterogeneousMineral.Ps; this.Txt_DRr_No.Text = heterogeneousMineral.DRr; this.Txt_ReflectionDAR_No.Text = heterogeneousMineral.ReflectionDAR; this.Txt_InternalReflection_No.Text = heterogeneousMineral.InternalReflection; this.Txt_Origin_No.Text = heterogeneousMineral.Origin; this.Txt_IMK_No.Text = heterogeneousMineral.IMK; ShowHeteMineralInfoView(); } }
/// <summary> /// 将DataTable的数据导入到数据库 /// </summary> /// <param name="filepath"></param> /// <param name="dt"></param> public static string ExportDataToAccess(string filepath, DataSet mineralDataSet) { int successed = 0; int failed = 0; DataTable dt = GetDataByExcel(filepath); if (dt.Rows.Count > 0) { if (CheckIsRepeatInExcel(dt)) { return("Excel中有重复的矿物,请检查后再来"); } if (dt.TableName.Contains("非均质矿物")) { for (int i = 0; i < dt.Rows.Count; i++) { DataRow[] dataRow = mineralDataSet.Tables[dt.TableName].Select("ChineseName='" + dt.Rows[i]["矿物中文名称"].ToString() + "'"); if (dataRow.Length > 0) { failed++; } else { try { HeterogeneousMineralInfo heterogeneousMineral = null; string Ar = dt.Rows[i]["非均质视旋转角Ar"].ToString(); if (!String.IsNullOrEmpty(Ar)) { if (Ar.Contains("=")) { Ar = Ar.Split('=')[1]; } Ar = AngleHelper.ConvertAngleToString(Ar); } heterogeneousMineral = new HeterogeneousMineralInfo(0, dt.Rows[i]["矿物中文名称"].ToString(), dt.Rows[i]["矿物英文名称"].ToString(), dt.Rows[i]["化学式"].ToString(), dt.Rows[i]["矿物的晶系"].ToString(), dt.Rows[i]["均非性"].ToString(), dt.Rows[i]["反射率"].ToString(), dt.Rows[i]["硬度"].ToString(), dt.Rows[i]["反射色"].ToString(), dt.Rows[i]["双反射及反射多色性"].ToString(), Ar, dt.Rows[i]["非均质视旋转色散DAr"].ToString(), dt.Rows[i]["旋向Rs"].ToString(), dt.Rows[i]["相符Ps"].ToString(), dt.Rows[i]["反射视旋转色散DRr"].ToString(), dt.Rows[i]["反射视旋转色散DAR"].ToString(), dt.Rows[i]["内反射"].ToString(), dt.Rows[i]["矿物成因产状形态特征及伴生矿物"].ToString(), dt.Rows[i]["主要鉴定特征"].ToString()); AccessDB.Add(heterogeneousMineral); successed++; } catch (Exception) { return("错误"); } } } } else { for (int i = 0; i < dt.Rows.Count; i++) { DataRow[] dataRow = mineralDataSet.Tables[dt.TableName].Select("ChineseName='" + dt.Rows[i]["矿物中文名称"].ToString() + "'"); if (dataRow.Length > 0) { failed++; } else { try { HomogeneousMineralInfo homogeneousMineral = null; string Rr = dt.Rows[i]["反射视旋转角Rr"].ToString(); if (!String.IsNullOrEmpty(Rr)) { if (Rr.Contains("=")) { Rr = Rr.Split('=')[1]; } Rr = AngleHelper.ConvertAngleToString(Rr); } homogeneousMineral = new HomogeneousMineralInfo(0, dt.Rows[i]["矿物中文名称"].ToString(), dt.Rows[i]["矿物英文名称"].ToString(), dt.Rows[i]["化学式"].ToString(), dt.Rows[i]["矿物的晶系"].ToString(), dt.Rows[i]["均非性"].ToString(), dt.Rows[i]["反射率"].ToString(), dt.Rows[i]["硬度"].ToString(), dt.Rows[i]["反射色"].ToString(), Rr, dt.Rows[i]["反射视旋转色散DRr"].ToString(), dt.Rows[i]["内反射"].ToString(), dt.Rows[i]["矿物成因产状形态特征及伴生矿物"].ToString(), dt.Rows[i]["主要鉴定特征"].ToString()); AccessDB.Add(homogeneousMineral); successed++; } catch (Exception) { return("错误"); } } } } return("数据导入到" + dt.TableName + "表成功!成功导入" + successed + "条,有" + failed + "条在数据库中已存在"); } else { return("请检查你的Excel中是否存在数据"); } }