/// <summary> /// загрузка данных по сырью из xml файла /// </summary> /// <param name="root">узел со списком компонент</param> /// <param name="par">родительская структура</param> /// <returns></returns> public static BindingList <DataBase> LoadManyFromXml(XmlNode root, DataBase par, ReceptVersion curVer) { BindingList <DataBase> ret = new BindingList <DataBase>(); switch (curVer) { case ReceptVersion.Version0: throw new NotImplementedException("not implemented"); case ReceptVersion.Version1: foreach (XmlNode curNode in root.ChildNodes) { if (curNode.Name.Equals("recept")) { ret.Add(DataRecept.LoadFromXml(curNode, par, curVer)); } else // это лист с сырьем { DataRaw curRaw = new DataRaw(par); curRaw.BeginUpdate(); foreach (XmlNode curRawNode in curNode.ChildNodes) { switch (curRawNode.Name) { case "quantity": curRaw.Quantity = Convert.ToDecimal(curRawNode.InnerText, CultureInfo.CurrentCulture); break; case "comment": curRaw.Comment = curRawNode.InnerText; break; case "brutto": curRaw.myBrutto = Convert.ToDecimal(curRawNode.InnerText, CultureInfo.CurrentCulture); break; case "rawStruct": curRaw.myRawStruct = DataRawStruct.LoadFromXml(curRawNode, curRaw, DataBaseType.RawType); break; case "processLoss": curRaw.myProcessLoss = DataRawStruct.LoadFromXml(curRawNode, curRaw, DataBaseType.ProcessLossType); break; } } curRaw.EndUpdate(false); curRaw.IsChanged = false; ret.Add(curRaw); } } break; default: throw new NotImplementedException("not implemented"); } return(ret); }
//public override bool Contains(DataBase child) //{ // return false; // //throw new Exception("The method or operation is not implemented."); //} public static DataRaw LoadOneFromXml(XmlNode root, DataBase par, ReceptVersion curVer) { DataRaw ret = new DataRaw(par); ret.BeginUpdate(); switch (curVer) { case ReceptVersion.Version0: foreach (XmlNode props in root.ChildNodes) { switch (props.Name) { case "name": ret.Name = props.InnerText; break; case "number": ret.RawStruct.Id = int.Parse(props.InnerText, CultureInfo.CurrentCulture); break; case "water": ret.RawStruct.Water = Convert.ToDecimal(props.InnerText, CultureInfo.CurrentCulture); break; case "gir": ret.RawStruct.fat = Convert.ToDecimal(props.InnerText, CultureInfo.CurrentCulture); break; case "belki": ret.RawStruct.protein = Convert.ToDecimal(props.InnerText, CultureInfo.CurrentCulture); break; case "sahar": ret.RawStruct.saccharides = Convert.ToDecimal(props.InnerText, CultureInfo.CurrentCulture); break; case "kkal": ret.RawStruct.Caloric = Convert.ToDecimal(props.InnerText, CultureInfo.CurrentCulture); break; case "comment": ret.Comment = props.InnerText; break; case "value": ret.Quantity = Convert.ToDecimal(props.InnerText, CultureInfo.CurrentCulture); break; } } break; case ReceptVersion.Version1: throw new NotImplementedException("not implemented"); default: throw new NotImplementedException("not implemented"); } ret.EndUpdate(false); ret.IsChanged = false; return(ret); }