/// <summary> /// 插入数据 /// </summary> public bool Insert(ArtistMappingSeries mapping) { StringBuilder cmd1 = new StringBuilder(); StringBuilder cmd2 = new StringBuilder(); StringBuilder sqlcmd = new StringBuilder(); Collection<DbParameter> paras = new Collection<DbParameter>(); if (mapping.ChildArtistID > 0) { cmd1.Append(",CHILD_ARTIST_ID"); cmd2.Append(",@ChildArtistID"); paras.Add(new SqlParameter("@ChildArtistID", mapping.ChildArtistID)); } if ( mapping.ChildCVID > 0) { cmd1.Append(",CHILD_CV_ID"); cmd2.Append(",@ChildCVID"); paras.Add(new SqlParameter("@ChildCVID", mapping.ChildCVID)); } if (mapping.ChildCharacterNo != null && !mapping.ChildCharacterNo.Equals(string.Empty)) { cmd1.Append(",CHILD_CHARACTER_NO"); cmd2.Append(",@ChildCharacterNo"); paras.Add(new SqlParameter("@ChildCharacterNo", mapping.ChildCharacterNo)); } sqlcmd.Append(@"INSERT INTO {0} ( ARTIST_ID ,MAPPING_TYPE ,ENABLE_FLG ,LAST_UPDATE_DATETIME "); sqlcmd.Append(cmd1); sqlcmd.Append(@") VALUES ( @id ,@mappingType ,1 ,GETDATE() "); sqlcmd.Append(cmd2); sqlcmd.Append(@")"); paras.Add(new SqlParameter("@id", mapping.ArtistId)); paras.Add(new SqlParameter("@mappingType", mapping.MappingTypeID)); DbCmd.DoCommand(string.Format(sqlcmd.ToString(), CommonConst.TableName.T_ARTIST_MAPPING_TBL), paras); return true; }
/// <summary> /// 作成匹配 /// </summary> /// <returns></returns> private ArtistMappingSeries SetMapping() { //新作成的匹配记录 ArtistMappingSeries map = new ArtistMappingSeries(targetArtist.Id); MusicDataSet.ResultMappingRow resultMapRow = ResultMap.NewResultMappingRow(); switch (mType) { case MappingType.CVMapping: map.MappingTypeID = (int)MappingType.CVMapping; map.ChildCVID = Convert.ToInt32(nameListBox.SelectedValue); resultMapRow.ChildKey = map.MappingTypeID.ToString() + "#" + map.ChildCVID.ToString(); resultMapRow.ChildName = nameListBox.Text.ToString(); DataRow cvDr = CVMap.Rows.Find(map.ChildCVID); CVMap.Rows.Remove(cvDr); CVMap.AcceptChanges(); DataRow cvSDr = CVSearchMap.Rows.Find(map.ChildCVID); if (cvSDr != null) { CVSearchMap.Rows.Remove(cvSDr); CVSearchMap.AcceptChanges(); } break; case MappingType.CharacterMapping: map.MappingTypeID = (int)MappingType.CharacterMapping; map.ChildCharacterNo = nameListBox.SelectedValue.ToString(); resultMapRow.ChildKey = map.MappingTypeID.ToString() + "#" + map.ChildCharacterNo; resultMapRow.ChildName = nameListBox.Text.ToString(); DataRow charaDr = CharacterMap.Rows.Find(map.ChildCharacterNo); CharacterMap.Rows.Remove(charaDr); CharacterMap.AcceptChanges(); DataRow charaSDr = CharacterSearchMap.Rows.Find(map.ChildCharacterNo); if (charaSDr != null) { CharacterSearchMap.Rows.Remove(charaSDr); CharacterSearchMap.AcceptChanges(); } break; case MappingType.Singer: map.MappingTypeID = (int)MappingType.Singer; map.ChildArtistID = Convert.ToInt32(nameListBox.SelectedValue); resultMapRow.ChildKey = map.MappingTypeID.ToString() + "#" + map.ChildArtistID.ToString(); resultMapRow.ChildName = nameListBox.Text.ToString(); DataRow singerDr = SingerMap.Rows.Find(map.ChildArtistID); SingerMap.Rows.Remove(singerDr); SingerMap.AcceptChanges(); DataRow singerSDr = SingerSearchMap.Rows.Find(map.ChildArtistID); if (singerSDr != null) { SingerSearchMap.Rows.Remove(singerSDr); SingerSearchMap.AcceptChanges(); } break; } var repeattarget = from repeat in this.ResultMap where repeat.ChildKey.Equals(resultMapRow.ChildKey) select repeat.ChildKey; foreach (string i in repeattarget) { goto Repeat; } ResultMap.Rows.Add(resultMapRow); ResultMap.AcceptChanges(); Repeat: resultListBox.DataSource = ResultMap; resultListBox.ValueMember = "ChildKey"; resultListBox.DisplayMember = "ChildName"; return map; }
/// <summary> /// 作成匹配(移除用) /// </summary> /// <returns></returns> private ArtistMappingSeries SetRemoveMapping() { ArtistMappingSeries map = new ArtistMappingSeries(targetArtist.Id); //格式:匹配类型#主键 string[] MapID = resultListBox.SelectedValue.ToString().Split(new char[] { '#' }); int mapType = Convert.ToInt32(MapID[0]); switch(mapType) { case (int)MappingType.CVMapping: map.MappingTypeID = (int)MappingType.CVMapping; map.ChildCVID = Convert.ToInt32(MapID[1]); break; case (int)MappingType.CharacterMapping: map.MappingTypeID = (int)MappingType.CharacterMapping; map.ChildCharacterNo = MapID[1]; break; case (int)MappingType.Singer: map.MappingTypeID = (int)MappingType.Singer; map.ChildArtistID = Convert.ToInt32(MapID[1]); break; } return map; }
/// <summary> /// 从目标列表中移除匹配 /// </summary> private void OnRemoveChooseMapping() { if (mType == MappingType.Original || resultListBox.Enabled == false || resultListBox.Items.Count == 0 || resultListBox.SelectedValue.ToString().Trim() == string.Empty) { return; } //格式:匹配类型#主键 string ChildKey = resultListBox.SelectedValue.ToString(); string[] MapID = ChildKey.Split(new char[] { '#' }); int mapType = Convert.ToInt32(MapID[0]); //ResultList绑定的ResultMap中的对应行 DataRow resultDr = ResultMap.Rows.Find(ChildKey); //待删除的匹配记录 ArtistMappingSeries toRemoveAms = new ArtistMappingSeries(); foreach (ArtistMappingSeries ams in targetArtist.Mapping) { switch (mapType) { case (int)MappingType.CVMapping: if (ams.ChildCVID == Convert.ToInt32(MapID[1])) { //从ArtistMappingSeries中移除 toRemoveAms = ams; //作成新Row加回nameList中 MusicDataSet.ArtistCVMappingRow cvRow = CVMap.NewArtistCVMappingRow(); cvRow.CVID = ams.ChildCVID; cvRow.CVName = resultDr["ChildName"].ToString(); CVMap.Rows.InsertAt(cvRow, 0); CVMap.AcceptChanges(); //作成新Row加回SearchList中 MusicDataSet.ArtistCVMappingForSearchRow cvSRow = CVSearchMap.NewArtistCVMappingForSearchRow(); cvSRow.CVID = ams.ChildCVID; cvSRow.CVName = resultDr["ChildName"].ToString(); CVSearchMap.Rows.InsertAt(cvSRow, 0); CVSearchMap.AcceptChanges(); break; } continue; case (int)MappingType.CharacterMapping: if (ams.ChildCharacterNo == MapID[1]) { //从ArtistMappingSeries中移除 toRemoveAms = ams; //作成新Row加回nameList中 MusicDataSet.ArtistCharacterMappingRow charaRow = CharacterMap.NewArtistCharacterMappingRow(); charaRow.CharacterNo = ams.ChildCharacterNo; charaRow.CharacterName = resultDr["ChildName"].ToString(); CharacterMap.Rows.InsertAt(charaRow, 0); CharacterMap.AcceptChanges(); //作成新Row加回SearchList中 MusicDataSet.ArtistCharacterMappingForSearchRow charaSRow = CharacterSearchMap.NewArtistCharacterMappingForSearchRow(); charaSRow.CharacterNo = ams.ChildCharacterNo; charaSRow.CharacterName = resultDr["ChildName"].ToString(); CharacterSearchMap.Rows.InsertAt(charaSRow, 0); CharacterSearchMap.AcceptChanges(); break; } continue; case (int)MappingType.Singer: if (ams.ChildArtistID == Convert.ToInt32(MapID[1])) { //从ArtistMappingSeries中移除 toRemoveAms = ams; //作成新Row加回nameList中 MusicDataSet.ArtistSingerMappingRow singerRow = SingerMap.NewArtistSingerMappingRow(); singerRow.ChildArtistID = ams.ChildArtistID; singerRow.ChildArtistName = resultDr["ChildName"].ToString(); SingerMap.Rows.InsertAt(singerRow, 0); SingerMap.AcceptChanges(); //作成新Row加回SearchList中 MusicDataSet.ArtistSingerMappingForSearchRow singerSRow = SingerSearchMap.NewArtistSingerMappingForSearchRow(); singerSRow.ChildArtistID = ams.ChildArtistID; singerSRow.ChildArtistName = resultDr["ChildName"].ToString(); SingerSearchMap.Rows.InsertAt(singerSRow, 0); SingerSearchMap.AcceptChanges(); break; } continue; } break; } //从artist中移除mapping targetArtist.Mapping.Remove(toRemoveAms); //总resultlist中移除mapping ResultMap.Rows.Remove(resultDr); }
/// <summary> /// 插入数据 /// </summary> public bool Insert(ArtistMappingSeries mapping) { return dao.Insert(mapping); }