/// <summary> /// Convert the spreadsheet to a dataset /// </summary> /// <param name="withEventThrowing"></param> /// <returns></returns> private DataSet _ConvertSpreadsheetToDataset(bool withEventThrowing) { int count = 0; DataSet data = new DataSet(); try { if(this._doc.TableCount > 0) { int percentMax = 50; double addValue = 0; double throwValue = 0; if(withEventThrowing) { addValue = Convert.ToDouble( Convert.ToDouble(percentMax) / Convert.ToDouble(this._allObjectsInFile) ); } // only for my videos !!!!!!!!!!!!!!!!!!!!!!! bool isMy = false; FileInfo fi = new FileInfo(this._filename); if(fi.Name == "Videos.ods") { isMy = true; } TableCollection col = this._doc.TableCollection; foreach(Table tbl in col) { // add a table to the dataset for each // table in the document table collection data.Tables.Add(new DataTable()); /* * load column info * */ List<ImportTableColumnSettings> list = new List<ImportTableColumnSettings>(); RowCollection rc = tbl.RowCollection; foreach(Row r in rc) { if(count < 2) { CellCollection typecc = r.CellCollection; foreach(Cell c in typecc) { if(count == 0) { list.Add(new ImportTableColumnSettings()); list[r.GetCellIndex(c)].Index = r.GetCellIndex(c); list[r.GetCellIndex(c)].Name = c.Node.InnerText; if(withEventThrowing) { throwValue += addValue; if(throwValue <= percentMax) { this.PercentState(this, new ImportStateEventArgs(throwValue)); } } else { this._allObjectsInFile++; } } else if(count == 1) { //try { // if(c.OfficeValueType != null) { // switch(c.OfficeValueType.Trim()) { // case "string": // list[r.GetCellIndex(c)].CellDataType = Type.GetType("System.String"); // break; // case "float": // list[r.GetCellIndex(c)].CellDataType = Type.GetType("System.Single"); // break; // case "bool": // list[r.GetCellIndex(c)].CellDataType = Type.GetType("System.Boolean"); // break; // default: // list[r.GetCellIndex(c)].CellDataType = Type.GetType("System.String"); // break; // } // } // else { // list[r.GetCellIndex(c)].CellDataType = Type.GetType("System.String"); // } //} //catch(Exception) { // list[r.GetCellIndex(c)].CellDataType = Type.GetType("System.String"); //} if(isMy && ( r.GetCellIndex(c) == 3 || r.GetCellIndex(c) == 5 )) { list[r.GetCellIndex(c)].CellDataType = Type.GetType("System.Boolean"); } else { try { if(c.OfficeValueType != null) { switch(c.OfficeValueType.Trim()) { case "string": list[r.GetCellIndex(c)].CellDataType = Type.GetType("System.String"); break; case "float": list[r.GetCellIndex(c)].CellDataType = Type.GetType("System.Single"); break; default: list[r.GetCellIndex(c)].CellDataType = Type.GetType("System.String"); break; } } else { list[r.GetCellIndex(c)].CellDataType = Type.GetType("System.String"); } } catch(Exception) { list[r.GetCellIndex(c)].CellDataType = Type.GetType("System.String"); } } } else { break; } } } else { break; } count++; } //// genre //ImportTableColumnSettings genre = new ImportTableColumnSettings(); //genre.CellDataType = Type.GetType("System.String"); //genre.Name = "__GENRE"; //list.Add(genre); //// actor //ImportTableColumnSettings actor = new ImportTableColumnSettings(); //actor.CellDataType = Type.GetType("System.String"); //actor.Name = "__ACTOR"; //list.Add(actor); //// director //ImportTableColumnSettings director = new ImportTableColumnSettings(); //director.CellDataType = Type.GetType("System.String"); //director.Name = "__DIRECTOR"; //list.Add(director); //// producer //ImportTableColumnSettings producer = new ImportTableColumnSettings(); //producer.CellDataType = Type.GetType("System.String"); //producer.Name = "__PRODUCER"; //list.Add(producer); //if(withEventThrowing) { // throwValue += addValue; // if(throwValue <= percentMax) { // this.PercentState(this, new ImportStateEventArgs(throwValue); // } //} //else { // this._allObjectsInFile++; //} count = 0; int amountOfRealColumns = 0; /* * create dataset columns * */ foreach(ImportTableColumnSettings itcs in list) { if(itcs.IsRealObject) { data.Tables[0].Columns.Add( new DataColumn( itcs.Name, (itcs.CellDataType == null ? Type.GetType("System.String") : itcs.CellDataType) ) ); if(withEventThrowing) { throwValue += addValue; if(throwValue <= percentMax) { this.PercentState(this, new ImportStateEventArgs(throwValue)); } } else { this._allObjectsInFile++; } amountOfRealColumns++; } } /* * load data from rows * */ foreach(Row r in rc) { if(count > 0) { // cells CellCollection cc = r.CellCollection; try { // add rows to dataset DataRow row = data.Tables[0].NewRow(); foreach(Cell c in cc) { if(r.GetCellIndex(c) < amountOfRealColumns) { // temp variables float tmp_float = 0; // save data if(isMy && (r.GetCellIndex(c) == 3 || r.GetCellIndex(c) == 5)) { if(c.Node.InnerText != null && c.Node.InnerText.Trim() != "" && (c.Node.InnerText.Trim().ToLower() == "x" || c.Node.InnerText.Trim().IsExpressionTrue() )) { row[r.GetCellIndex(c)] = true; } else { row[r.GetCellIndex(c)] = false; } } else { try { if(c.OfficeValueType != null) { switch(c.OfficeValueType) { case "string": //row[r.GetCellIndex(c)] = c.Node.InnerText; foreach(Paragraph p in c.Content) { foreach(SimpleText text in p.TextContent) { row[r.GetCellIndex(c)] = text.Text; } } break; case "float": foreach(Paragraph p in c.Content) { foreach(SimpleText text in p.TextContent) { //row[r.GetCellIndex(c)] = text.Text; float.TryParse(text.Text, out tmp_float); } } row[r.GetCellIndex(c)] = tmp_float; break; default: //row[r.GetCellIndex(c)] = c.Node.InnerText; foreach(Paragraph p in c.Content) { foreach(SimpleText text in p.TextContent) { row[r.GetCellIndex(c)] = text.Text; } } break; } } else { //row[r.GetCellIndex(c)] = c.Node.InnerText; foreach(Paragraph p in c.Content) { foreach(SimpleText text in p.TextContent) { row[r.GetCellIndex(c)] = text.Text; } } } } catch(Exception) { try { //row[r.GetCellIndex(c)] = (c.Node.InnerText != null ? c.Node.InnerText : ""); } catch(Exception) { row[r.GetCellIndex(c)] = DBNull.Value; } } } if(withEventThrowing) { throwValue += addValue; if(throwValue <= percentMax) { this.PercentState(this, new ImportStateEventArgs(throwValue)); } } else { this._allObjectsInFile++; } } } if(row[0] != DBNull.Value) { data.Tables[0].Rows.Add(row); } if(withEventThrowing) { throwValue += addValue; if(throwValue <= percentMax) { this.PercentState(this, new ImportStateEventArgs(throwValue)); } } else { this._allObjectsInFile++; } } catch(Exception) { } } count++; } if(withEventThrowing) { // send a last event with a value of 100 percent this.PercentState(this, new ImportStateEventArgs(percentMax)); } // break after the first table (for this time) break; } } } catch(Exception ex) { throw new Exception( "Error on loading data from OpenDocument spreadsheet!", ex ); } return data; }
/// <summary> /// Start the import /// </summary> /// <param name="allocation">The column allocation.</param> /// <returns>Returns true if the import was successfull.</returns> public bool Import(List<ColumnAllocation> allocation) { if(!this._doc.IsLoadedFile) { return false; } else { if(this._doc.TableCount > 0) { int percentMax = 50; double addValue = addValue = Convert.ToDouble( Convert.ToDouble(percentMax) / Convert.ToDouble(this._allObjectsInFile) ); double throwValue = percentMax; int nextMovieNumber = this._dh.GetNextMovieNumber(); DataSet data = this._ConvertSpreadsheetToDataset(true); DataSet content = this._db.ExecuteQuery("SELECT * FROM tbl_movies"); ImportHelper ih = new ImportHelper(); if(data.Tables[0].Rows.Count > 0) { DataTableReader reader = data.CreateDataReader(); DataRow row; string tmp_str = ""; bool tmp_bool = false; int tmp_int = 0; string newPkid = ""; StringBuilder str = new StringBuilder(); DataSet eData; try { while(reader.Read()) { row = content.Tables[0].NewRow(); // data newPkid = Helper.NewGuid; row["pkid"] = newPkid; // number if(ih.CheckForAllocatedColumn(allocation, "number")) { if(!int.TryParse(reader.GetValue( reader.GetOrdinal( ih.GetAllocatedColumnName(allocation, "number") ) ).ToString(), out tmp_int)) { tmp_int = 0; } row["number"] = tmp_int; } else { row["number"] = nextMovieNumber; } // name if(ih.CheckForAllocatedColumn(allocation, "name")) { tmp_str = reader.GetValue( reader.GetOrdinal( ih.GetAllocatedColumnName(allocation, "name") ) ).ToString(); row["name"] = tmp_str + ""; } else { row["name"] = ""; } // note if(ih.CheckForAllocatedColumn(allocation, "note")) { tmp_str = reader.GetValue( reader.GetOrdinal( ih.GetAllocatedColumnName(allocation, "note") ) ).ToString(); row["note"] = tmp_str + ""; } else { row["note"] = ""; } // has_cover if(ih.CheckForAllocatedColumn(allocation, "has_cover")) { //if(!bool.TryParse(reader.GetValue( // reader.GetOrdinal( // ih.GetAllocatedColumnName(allocation, "has_cover") // ) //).ToString(), out tmp_bool)) { // tmp_bool = false; //} //row["has_cover"] = tmp_bool; tmp_str = reader.GetValue( reader.GetOrdinal( ih.GetAllocatedColumnName(allocation, "has_cover") ) ).ToString(); if(tmp_str.ToLower().Contains("x") || tmp_str.ToLower().IsExpressionTrue()) { row["has_cover"] = true; } else { row["has_cover"] = false; } } else { row["has_cover"] = false; } // is_original if(ih.CheckForAllocatedColumn(allocation, "is_original")) { //if(!bool.TryParse(reader.GetValue( // reader.GetOrdinal( // ih.GetAllocatedColumnName(allocation, "is_original") // ) //).ToString(), out tmp_bool)) { // tmp_bool = false; //} //row["is_original"] = tmp_bool; tmp_str = reader.GetValue( reader.GetOrdinal( ih.GetAllocatedColumnName(allocation, "is_original") ) ).ToString(); if(tmp_str.ToLower().Contains("x") || tmp_str.ToLower().IsExpressionTrue()) { row["is_original"] = true; } else { row["is_original"] = false; } } else { row["is_original"] = false; } // is_conferred if(ih.CheckForAllocatedColumn(allocation, "is_conferred")) { //if(!bool.TryParse(reader.GetValue( // reader.GetOrdinal( // ih.GetAllocatedColumnName(allocation, "is_conferred") // ) //).ToString(), out tmp_bool)) { // tmp_bool = false; //} //row["is_conferred"] = tmp_bool; tmp_str = reader.GetValue( reader.GetOrdinal( ih.GetAllocatedColumnName(allocation, "is_conferred") ) ).ToString(); if(tmp_str.ToLower().Contains("x") || tmp_str.ToLower().IsExpressionTrue()) { row["is_conferred"] = true; } else { row["is_conferred"] = false; } } else { row["is_conferred"] = false; } // codec Codec tmpCodec = Codec.Unknown; if(ih.CheckForAllocatedColumn(allocation, "codec")) { tmp_str = reader.GetValue( reader.GetOrdinal( ih.GetAllocatedColumnName(allocation, "codec") ) ).ToString(); if(tmp_str.ToLower().Contains("divx")) { tmpCodec = Codec.Divx; row["codec"] = (int)Codec.Divx; } else if(tmp_str.ToLower().Contains("dvd")) { tmpCodec = Codec.DVD; row["codec"] = (int)Codec.DVD; } else if(tmp_str.ToLower().Contains("mpeg")) { tmpCodec = Codec.MPEG; row["codec"] = (int)Codec.MPEG; } else if(tmp_str.ToLower().Contains("mvcd")) { tmpCodec = Codec.MVCD; row["codec"] = (int)Codec.MVCD; } else if(tmp_str.ToLower().Contains("svcd")) { tmpCodec = Codec.SVCD; row["codec"] = (int)Codec.SVCD; } else if(tmp_str.ToLower().Contains("vcd")) { tmpCodec = Codec.VCD; row["codec"] = (int)Codec.VCD; } else if(tmp_str.ToLower().Contains("wmv")) { tmpCodec = Codec.WMV; row["codec"] = (int)Codec.WMV; } else if(tmp_str.ToLower().Contains("xvid")) { tmpCodec = Codec.Xvid; row["codec"] = (int)Codec.Xvid; } else if(tmp_str.ToLower().Contains("vhs")) { tmpCodec = Codec.VHS; row["codec"] = (int)Codec.VHS; } } else { row["codec"] = 6; } // conferred_to if(ih.CheckForAllocatedColumn(allocation, "conferred_to")) { tmp_str = reader.GetValue( reader.GetOrdinal( ih.GetAllocatedColumnName(allocation, "conferred_to") ) ).ToString(); row["conferred_to"] = tmp_str + ""; } else { row["conferred_to"] = ""; } // disc_amount if(ih.CheckForAllocatedColumn(allocation, "disc_amount")) { if(!int.TryParse(reader.GetValue( reader.GetOrdinal( ih.GetAllocatedColumnName(allocation, "disc_amount") ) ).ToString(), out tmp_int)) { tmp_int = 0; } row["disc_amount"] = tmp_int; } else { row["disc_amount"] = 0; } // year if(ih.CheckForAllocatedColumn(allocation, "year")) { if(!int.TryParse(reader.GetValue( reader.GetOrdinal( ih.GetAllocatedColumnName(allocation, "year") ) ).ToString(), out tmp_int)) { tmp_int = 0; } row["year"] = tmp_int; } else { row["year"] = -1; } // country //????????? (string, but only the country-code) row["country"] = ""; // quality //????????? (int) switch(tmpCodec) { case Codec.DVD: row["quality"] = 8; break; case Codec.VHS: row["quality"] = 3; break; default: row["quality"] = 5; break; } // GENRE if(ih.CheckForAllocatedColumn(allocation, "__GENRE")) { tmp_str = reader.GetValue( reader.GetOrdinal( ih.GetAllocatedColumnName(allocation, "__GENRE") ) ).ToString(); if(tmp_str.Length > 0) { string[] genres = tmp_str.Split(new char[] { ',' }); List<Genre> lGenre = new List<Genre>(); List<Genre> lNewGenre = new List<Genre>(); foreach(string genre in genres) { Genre tmp = this._dh.GetGenreByName(genre); if(tmp != null) { lGenre.Add(tmp); } else { Genre g = new Genre(); g.ID = Helper.NewGuid; g.Name = genre; lGenre.Add(g); lNewGenre.Add(g); } } // save genres this._dh.SaveNewGenreList(lNewGenre); // save genre link str.Remove(0, str.Length); str.Append("DELETE "); str.Append(" FROM tbl_movies_to_genres"); str.Append(" WHERE movie_pkid = '" + newPkid + "'"); this._db.ExecuteNonQuery(str.ToString()); str.Remove(0, str.Length); str.Append("SELECT * "); str.Append(" FROM tbl_movies_to_genres"); try { eData = null; eData = this._db.ExecuteQuery(str.ToString()); } catch(Exception ex) { throw new Exception("Error on loading genres from table!", ex); } foreach(Genre g in lGenre) { DataRow hrow = eData.Tables[0].NewRow(); hrow["pkid"] = Helper.NewGuid; hrow["genre_pkid"] = g.ID; hrow["movie_pkid"] = newPkid; eData.Tables[0].Rows.Add(hrow); } try { this._db.ExecuteUpdate(eData, "tbl_movies_to_genres"); } catch(Exception ex) { throw new Exception("Error on updating genres to table!", ex); } } } // ACTOR if(ih.CheckForAllocatedColumn(allocation, "__ACTOR")) { tmp_str = reader.GetValue( reader.GetOrdinal( ih.GetAllocatedColumnName(allocation, "__ACTOR") ) ).ToString(); if(tmp_str.Length > 0) { string[] actors = tmp_str.Split(new char[] { ',' }); List<Person> lActors = new List<Person>(); List<Person> lNewActors = new List<Person>(); foreach(string actor in actors) { PersonName name = Tools.SplitNameByLastSpace(actor); if(name != null) { Person person = this._dh.GetPersonByName( name.Firstname, name.Lastname, MovieObjectType.All ); if(person != null) { person.IsActor = true; this._dh.SavePerson( person, SaveMethod.SaveChanges ); lActors.Add(person); } else { Person p = new Person(); p.ID = Helper.NewGuid; p.Firstname = name.Firstname; p.Lastname = name.Lastname; p.IsActor = true; this._dh.SavePerson( p, SaveMethod.CreateNewWithoutID ); lActors.Add(p); lNewActors.Add(p); } } } // save new persons //this._dh.SaveNewPersonList(lNewActors); // save person link //str.Remove(0, str.Length); //str.Append("DELETE "); //str.Append(" FROM tbl_movies_to_persons"); //str.Append(" WHERE movie_pkid = '" + newPkid + "'"); //this._db.ExecuteNonQuery(str.ToString()); str.Remove(0, str.Length); str.Append("SELECT * "); str.Append(" FROM tbl_movies_to_persons"); try { eData = null; eData = this._db.ExecuteQuery(str.ToString()); } catch(Exception ex) { throw new Exception("Error on loading persons from table!", ex); } foreach(Person p in lActors) { DataRow hrow = eData.Tables[0].NewRow(); hrow["pkid"] = Helper.NewGuid; hrow["person_pkid"] = p.ID; hrow["movie_pkid"] = newPkid; hrow["as_actor"] = true; eData.Tables[0].Rows.Add(hrow); } try { this._db.ExecuteUpdate(eData, "tbl_movies_to_persons"); } catch(Exception ex) { throw new Exception("Error on updating persons to table!", ex); } } } // DIRECTOR if(ih.CheckForAllocatedColumn(allocation, "__DIRECTOR")) { tmp_str = reader.GetValue( reader.GetOrdinal( ih.GetAllocatedColumnName(allocation, "__DIRECTOR") ) ).ToString(); if(tmp_str.Length > 0) { string[] directors = tmp_str.Split(new char[] { ',' }); List<Person> lDirectors = new List<Person>(); List<Person> lNewDirectors = new List<Person>(); foreach(string director in directors) { PersonName name = Tools.SplitNameByLastSpace(director); if(name != null) { Person person = this._dh.GetPersonByName( name.Firstname, name.Lastname, MovieObjectType.All ); if(person != null) { person.IsDirector = true; this._dh.SavePerson( person, SaveMethod.SaveChanges ); lDirectors.Add(person); } else { Person p = new Person(); p.ID = Helper.NewGuid; p.Firstname = name.Firstname; p.Lastname = name.Lastname; p.IsDirector = true; this._dh.SavePerson( p, SaveMethod.CreateNewWithoutID ); lDirectors.Add(p); lNewDirectors.Add(p); } } } // save new persons //this._dh.SaveNewPersonList(lNewDirectors); // save person link //str.Remove(0, str.Length); //str.Append("DELETE "); //str.Append(" FROM tbl_movies_to_persons"); //str.Append(" WHERE movie_pkid = '" + newPkid + "'"); //this._db.ExecuteNonQuery(str.ToString()); str.Remove(0, str.Length); str.Append("SELECT * "); str.Append(" FROM tbl_movies_to_persons"); try { eData = null; eData = this._db.ExecuteQuery(str.ToString()); } catch(Exception ex) { throw new Exception("Error on loading persons from table!", ex); } foreach(Person p in lDirectors) { DataRow hrow = eData.Tables[0].NewRow(); hrow["pkid"] = Helper.NewGuid; hrow["person_pkid"] = p.ID; hrow["movie_pkid"] = newPkid; hrow["as_director"] = true; eData.Tables[0].Rows.Add(hrow); } try { this._db.ExecuteUpdate(eData, "tbl_movies_to_persons"); } catch(Exception ex) { throw new Exception("Error on updating persons to table!", ex); } } } // PRODUCER if(ih.CheckForAllocatedColumn(allocation, "__PRODUCER")) { tmp_str = reader.GetValue( reader.GetOrdinal( ih.GetAllocatedColumnName(allocation, "__PRODUCER") ) ).ToString(); if(tmp_str.Length > 0) { string[] producers = tmp_str.Split(new char[] { ',' }); List<Person> lProducers = new List<Person>(); List<Person> lNewProducers = new List<Person>(); foreach(string producer in producers) { PersonName name = Tools.SplitNameByLastSpace(producer); if(name != null) { Person person = this._dh.GetPersonByName( name.Firstname, name.Lastname, MovieObjectType.All ); if(person != null) { person.IsProducer = true; this._dh.SavePerson( person, SaveMethod.SaveChanges ); lProducers.Add(person); } else { Person p = new Person(); p.ID = Helper.NewGuid; p.Firstname = name.Firstname; p.Lastname = name.Lastname; p.IsProducer = true; this._dh.SavePerson( p, SaveMethod.CreateNewWithoutID ); lProducers.Add(p); lNewProducers.Add(p); } } } // save new persons //this._dh.SaveNewPersonList(lNewProducers); // save person link //str.Remove(0, str.Length); //str.Append("DELETE "); //str.Append(" FROM tbl_movies_to_persons"); //str.Append(" WHERE movie_pkid = '" + newPkid + "'"); //this._db.ExecuteNonQuery(str.ToString()); str.Remove(0, str.Length); str.Append("SELECT * "); str.Append(" FROM tbl_movies_to_persons"); try { eData = null; eData = this._db.ExecuteQuery(str.ToString()); } catch(Exception ex) { throw new Exception("Error on loading persons from table!", ex); } foreach(Person p in lProducers) { DataRow hrow = eData.Tables[0].NewRow(); hrow["pkid"] = Helper.NewGuid; hrow["person_pkid"] = p.ID; hrow["movie_pkid"] = newPkid; hrow["as_producer"] = true; eData.Tables[0].Rows.Add(hrow); } try { this._db.ExecuteUpdate(eData, "tbl_movies_to_persons"); } catch(Exception ex) { throw new Exception("Error on updating persons to table!", ex); } } } throwValue += addValue; if(throwValue <= (percentMax * 2)) { this.PercentState(this, new ImportStateEventArgs(throwValue)); } content.Tables[0].Rows.Add(row); nextMovieNumber++; } // save try { this._db.ExecuteUpdate(content, "tbl_movies"); } catch(Exception ex) { throw new Exception("Error on updating movie to table (during import)!", ex); } } catch(Exception ex) { throw new Exception("Error on adding rows to the movies table (during import)!", ex); } } // send a last event with a value of 100 percent this.PercentState(this, new ImportStateEventArgs(percentMax + percentMax)); } } return true; }
/* * Метод перелистывания страниц в гриде */ protected void Store1_RefreshData(object sender, Ext.Net.StoreRefreshDataEventArgs e) { DataSet data = null; List<GridColumn> columns = new List<GridColumn>(); using (ContentDomain provider = Common.GetContentDomain(ClassifiacationTypeView)) { Domain.OrderExpression OrderExpression = new OrderExpression(); if (e.Sort.Length > 0) { string expr = e.Sort.Split('|')[0]; string tp = e.Sort.Split('|')[1]; OrderExpression.Expression = expr; OrderExpression.ColumnType = (TypeEnum)Enum.Parse(typeof(TypeEnum), tp); } if (e.Dir == Ext.Net.SortDirection.DESC) OrderExpression.SortDirection = Aspect.Domain.SortDirection.desc; List<SearchExpression> listSearch = this.SearchConditions.ToList(); // показывать только выбранные if (this.ShowSelected && !String.IsNullOrEmpty(hiddenSelectedProducts.Value.ToString())) { SearchExpression selected = new SearchExpression(); selected.FieldCond = Condition.Inset; selected.FieldValue = hiddenSelectedProducts.Value.ToString(); selected.FieldName = "ID"; listSearch.Add(selected); } // показывать основные версии if (FilterView.Value.ToString().Contains("mainVers")) { SearchExpression mainVers = new SearchExpression(); mainVers.FieldID = new Guid("BBE170B0-28E4-4738-B365-1038B03F4552"); //основная версия mainVers.FieldValue = "1"; listSearch.Add(mainVers); } // показывать приказные версии if (FilterView.Value.ToString().Contains("prikazVers")) { SearchExpression mainVers = new SearchExpression(); mainVers.FieldCond = Condition.Beable; mainVers.FieldValue = "9A38E338-DD60-4636-BFE3-6A98BAF8AE87"; // номер приказала listSearch.Add(mainVers); } // получить страницу из списка продуктов, попадающих под все заданные условия data = provider.GetList(RequestClassificationTreeID, this.User.ID, OrderExpression, listSearch, new PagingInfo(e.Start, e.Limit)); columns = provider.GetGridColumns(this.User.ID, RequestClassificationTreeID, FieldPlaceHolder.Grid); } if (data != null && data.Tables.Count > 0) { e.Total = data.Tables[1].Rows[0].Field<int>(0); List<object> dataSource = new List<object>(); foreach (DataRow row in data.Tables[2].Rows) { List<object> dataRow = new List<object>(); foreach (GridColumn column in columns) { if (column.GridColumnType == TypeEnum.Boolean) { dataRow.Add(row[column.DataItem].ToString() == "1"); } else if (column.GridColumnType == TypeEnum.Datetime) { try { dataRow.Add(row.Field<DateTime>(column.DataItem).ToString("yyyy-MM-dd HH:mm:ss.fff")); } catch { dataRow.Add(row[column.DataItem].ToString()); } } else { dataRow.Add(row[column.DataItem].ToString()); } } // adding another field dataRow.Add(row["ID"].ToString()); dataRow.Add(ClassifiacationTypeView == ClassifiacationTypeView.Dictionary ? this.RequestClassificationTreeID : Guid.Empty); dataSource.Add(dataRow.ToArray()); } this.Store1.DataSource = dataSource; this.Store1.DataBind(); } }
/*public void BindClassificationView(ITreeProvider provider, Guid parentID, TreeNode parentNode, Guid selectedID) { List<ITreeNode> list = new List<ITreeNode>(); if (!parentID.Equals(Guid.Empty) && parentNode == null) { ITreeNode entity = provider.GetTreeNode(parentID); if (entity == null) return; list.Add(entity); } else { list = provider.GetList(parentID, User.ID, Roles); //List<ITreeNode> list = provider.GetList(parentID); } foreach (ITreeNode item in list) { Basic.ColoredTreeNode node; switch (item.Section) { case TreeNodeSection.Custom: node = new Basic.ColoredTreeNode(item.Name, String.Format("cust-{0}", item.ID)); node.Color = case TreeNodeSection.Default: new Basic.ColoredTreeNode(item.Name, item.ID.ToString()); } = new Basic.ColoredTreeNode(item.Name, item.ID.ToString()); node.Color = item.Color; if (item.ID == selectedID) node.Select(); node.NavigateUrl = string.Format("Grid.aspx?cid={0}&pid={1}", node.Value, this.ClassificationTopNodeID); if (parentNode != null) parentNode.ChildNodes.Add(node); else ClassificationView.Nodes.Add(node); this.BindClassificationView(provider, item.ID, node, selectedID); } }*/ public void BindClassView(ITreeProvider provider, Guid parentID, Ext.Net.TreeNode parentNode, Guid selectedID) { List<ITreeNode> list = new List<ITreeNode>(); if (!parentID.Equals(Guid.Empty) && parentNode == null) { ITreeNode entity = provider.GetTreeNode(parentID); if (entity == null) return; list.Add(entity); } else { list = provider.GetList(parentID, User.ID, Roles); //List<ITreeNode> list = provider.GetList(parentID); } foreach (ITreeNode item in list) { Ext.Net.TreeNode treeNode; if (item.ID.Equals(new Guid("00497ABC-7ADB-11E0-AD88-63F04724019B"))) { // hack for "Wares" treeNode = new Ext.Net.TreeNode(String.Format("ware-{0}", item.ID), item.Name, Ext.Net.Icon.Folder); treeNode.Cls = "TreeNode-Wares"; treeNode.Href = String.Format("/Technology/ListWares.aspx"); } else { switch (item.Section) { case TreeNodeSection.Custom: treeNode = new Ext.Net.TreeNode(String.Format("cust-{0}", item.ID), item.Name, Ext.Net.Icon.Folder); treeNode.Cls = "TreeNode-Custom"; break; case TreeNodeSection.Dictionary: treeNode = new Ext.Net.TreeNode(String.Format("dict-{0}", item.ID), item.Name, Ext.Net.Icon.Folder); treeNode.Cls = "TreeNode-Dictionary"; break; default: treeNode = new Ext.Net.TreeNode(String.Format("dflt-{0}", item.ID), item.Name, Ext.Net.Icon.Folder); treeNode.Cls = "TreeNode-Default"; break; } treeNode.Href = String.Format("/Grid.aspx?cid={0}", item.ID); } if (parentNode != null) parentNode.Nodes.Add(treeNode); else (ClassView.Root[0] as Ext.Net.TreeNode).Nodes.Add(treeNode); if (item.ID == this.RequestClassificationTreeID) { this.selectedNodeID = this.RequestClassificationTreeID; this.selectedNodeText = item.Name; ClassView.SelectNode(treeNode.NodeID); Ext.Net.TreeNodeBase tmpParent = treeNode.ParentNode; while (tmpParent != null) { tmpParent.Expanded = true; tmpParent = tmpParent.ParentNode; } //ClassView.SelectNode(treeNode.NodeID); //ClassView.ExpandChildNodes(treeNode.NodeID); } this.BindClassView(provider, item.ID, treeNode, selectedID); } }
protected void Save_Click(object sender, EventArgs e) { this.Validate(); if (this.IsValid) { // Проверяем, является ли продукт основной версией ProductProvider productProvider = new ProductProvider(); if (productProvider.IsMainVersion(this.ProductID)) { LabelErrorMessage.Text = "[ ! ] Содержащий данную спецификацию продукт является основной версией. Сохранение отменено."; return; } JavaScriptSerializer js = new JavaScriptSerializer(); List<Dictionary<string, string>> rows = js.Deserialize<List<Dictionary<string, string>>>(hiddenStoreData.Value.ToString()); EditConfigurationProvider provider = new EditConfigurationProvider(); List<GridColumn> gridColumns = provider.GetGridColumns(); // Сохраняем данные, полученные от пользователя в списке конфигураций List<Aspect.Domain.Configuration> result = new List<Aspect.Domain.Configuration>(); #region convert Request to list of Configuration foreach (Dictionary<string, string> row in rows) { Guid productID = new Guid(row["ID"]); Aspect.Domain.Configuration conf = new Aspect.Domain.Configuration(); conf.ID = new Guid(row["ConfID"]); conf.ProductID = productID; conf.ProductOwnerID = this.ProductID; conf.UserID = this.User.ID; foreach (GridColumn column in gridColumns) { if (column is EditableGridColumn) { System.Reflection.PropertyInfo prop = typeof(Aspect.Domain.Configuration).GetProperty(column.DataItem); if (prop.PropertyType == typeof(decimal) || prop.PropertyType == typeof(Nullable<decimal>)) { prop.SetValue(conf, Convert.ToDecimal(row[column.DataItem]), null); } else if (prop.PropertyType == typeof(int) || prop.PropertyType == typeof(Nullable<int>)) { prop.SetValue(conf, Convert.ToInt32(row[column.DataItem]), null); } else if (prop.PropertyType == typeof(Guid) || prop.PropertyType == typeof(Nullable<Guid>)) { prop.SetValue(conf, new Guid(row[column.DataItem]), null); } else if (prop.PropertyType == typeof(Boolean) || prop.PropertyType == typeof(Nullable<Boolean>)) { prop.SetValue(conf, Convert.ToBoolean(row[column.DataItem]), null); } else { prop.SetValue(conf, row[column.DataItem], null); } } } result.Add(conf); } #endregion using (CommonDomain domain = new CommonDomain()) { // Проверка на включение материалов #region check_including_material foreach (Aspect.Domain.Configuration conf in result) { Product prod = domain.Products.Single(p => p.ID == conf.ProductID); if (prod._dictNomen.cod >= 1000000) { LabelErrorMessage.Text = "[ ! ] Обнаружены материалы в спецификации. Сохранение отменино."; return; } } #endregion // Проверка на циклы #region check_for_cycles Guid dictNomenID = (Guid) (from p in domain.Products where p.ID == this.ProductID select p).Single()._dictNomenID; foreach (Aspect.Domain.Configuration conf in result) { Product prod = domain.Products.Where(p => p.ID == conf.ProductID).Single(); if (dictNomenID == prod._dictNomenID) { LabelErrorMessage.Text = "[ ! ] Обнаружены циклические включения продуктов в спецификацию. Сохранение отменино."; return; } if (fnCheckContains(dictNomenID, prod.ID)) { LabelErrorMessage.Text = "[ ! ] Обнаружены циклические включения продуктов в спецификацию. Сохранение отменино."; return; } } #endregion } provider.SaveProductConfiguration(this.ProductID, result, this.User.ID); // установка признака "Основная версия" if (MadeBasicVersion.Checked) { productProvider.SetMainVersion(this.User.ID, new List<Guid>{ProductID}); } // устанавливаем основание изменений if (!String.IsNullOrEmpty(ReasonChanges.Text)) { ProductProperty reasonProperty = productProvider.ProductProperties.SingleOrDefault( pr => pr.PropertyID == new Guid("C266B994-9740-41F6-94DD-07EA5B5FA34A") && pr.ProductID == this.ProductID); if (reasonProperty == null) { reasonProperty = new ProductProperty() { ID = Guid.NewGuid(), PropertyID = new Guid("C266B994-9740-41F6-94DD-07EA5B5FA34A"), ProductID = this.ProductID, Value = ReasonChanges.Text }; productProvider.ProductProperties.InsertOnSubmit(reasonProperty); } else { reasonProperty.Value = ReasonChanges.Text; } productProvider.SubmitChanges(); } // Очищаем сообщение об ошибке и обновляем данные о спецификации LabelErrorMessage.Text = ""; this.BindGridColumns2(); this.BindData(new Dictionary<Guid, Guid>()); } }
protected void BindData(Dictionary<Guid, Guid> productsConfigurations) { using (EditConfigurationProvider provider = new EditConfigurationProvider()) { System.Data.DataTable dt = provider.GetList(ProductID).Tables[0]; if (productsConfigurations.Count > 0) { System.Data.DataTable bfDt = provider.GetAppendList(productsConfigurations).Tables[0]; dt.Merge(bfDt); } // FOR NEW using (EditConfigurationProvider prov = new EditConfigurationProvider()) { List<object> lst = new List<object>(); List<ColumnWidth> columnWidths = provider.ColumnWidths.Where(p => p.ClassificationTreeID == new Guid("11110000-0000-0000-0000-000011110001") && p.UserID == this.User.ID).ToList(); List<GridColumn> list = prov.GetGridColumns(); list = list.OrderBy(clm => columnWidths.Exists(w => w.ColumnID == clm.ID) ? columnWidths.Single(w => w.ColumnID == clm.ID).Index : Int32.MaxValue).ToList(); foreach (DataRow row in dt.Rows) { List<object> lst_sub = new List<object>(); foreach (GridColumn column in list) { if (column.GridColumnType == TypeEnum.Boolean) { if (row[column.DataItem].ToString() == "0") lst_sub.Add(false); else lst_sub.Add(true); } else { lst_sub.Add(row[column.DataItem].ToString()); } } // дополнительные поля lst_sub.Add(row["ID"].ToString()); lst_sub.Add(this.RequestClassificationTreeID.ToString()); lst_sub.Add(row["ConfigurationID"].ToString()); lst.Add(lst_sub.ToArray()); } Store1.DataSource = lst; Store1.DataBind(); } //EditConfigurationGrid.DataSource = dt; //EditConfigurationGrid.DataBind(); // загружаем основание изменений ProductProperty reasonProperty = provider.ProductProperties.SingleOrDefault( pr => pr.PropertyID == new Guid("C266B994-9740-41F6-94DD-07EA5B5FA34A") && pr.ProductID == this.ProductID); if (reasonProperty != null) { ReasonChanges.Text = reasonProperty.Value; } } }