public static ProductDatabase TestDataBase() { ProductDatabase result = new ProductDatabase(); result.AddProduct(ProductFactory.CreateProduct("Компьютер", "Пронин")); result.AddProduct(ProductFactory.CreateProduct("Монитор", "Пелых")); result.AddProduct(ProductFactory.CreateProduct("Принтер", "Пронин")); return(result); }
public override void Run() { Console.Clear(); Console.WriteLine(MenuSystem.Path); ProductDatabase productManager = ProductDatabase.GetInstance(); Console.Write("Name: "); string name = Console.ReadLine(); //name.IsMandatory(ref name); Console.Write("Description: "); string desc = Console.ReadLine(); //desc.IsMandatory(ref desc); Console.Write("Manufacturer: "); string manufacturer = Console.ReadLine(); //manufacturer.IsMandatory(ref manufacturer); double price = -1; Console.Write("Price: "); bool flag = Double.TryParse("" + Console.ReadLine(), out price); while (price < 0 || !flag) { Console.WriteLine("Price is mandatory, it cannot be empty. Please enter price again."); flag = Double.TryParse("" + Console.ReadLine(), out price); } Console.WriteLine(); Dictionary <string, dynamic> product = new Dictionary <string, dynamic>() { { "Name", name }, { "Manufacturer", manufacturer }, { "Description", desc }, { "SellingPrice", price } }; productManager.AddProduct(product); Console.WriteLine("Press any key to exit."); Console.ReadKey(); }
public static ProductDatabase LoadFromXml(string path) { ProductDatabase result = new ProductDatabase(); XDocument mainBaseDoc; try { mainBaseDoc = XDocument.Load(path); } catch (Exception ex) { DataController.ShowErrorWindow(ex.Message); return(result); } var xmlList = mainBaseDoc.Descendants("Product").ToList(); int i = 0; foreach (XElement elem in xmlList) { i++; int number = i; string name = (string)elem.Element("Name"); string exploitationPlace = (string)elem.Element("ExploitationPlace"); string index = (string)elem.Element("Index"); string factoryNumber = (string)elem.Element("FactoryNumber"); string inventoryNumber = (string)elem.Element("InventoryNumber"); string bbtNomenclature = (string)elem.Element("BbtNomenclature"); string purpose = (string)elem.Element("Purpose"); string manufacturer = (string)elem.Element("Manufacturer"); string guarantee = (string)elem.Element("Guarantee"); string exploitationPeriod = (string)elem.Element("ExploitationPeriod"); string confirmationDoc = (string)elem.Element("ConfirmationDoc"); string confirmationNumber = (string)elem.Element("ConfirmationNumber"); string orderNumber = (string)elem.Element("OrderNumber"); string primaryCost = (string)elem.Element("PrimaryCost"); double aurum = (double)elem.Element("Aurum"); double argentum = (double)elem.Element("Argentum"); double mpg = (double)elem.Element("Mpg"); double platinum = (double)elem.Element("Platinum"); string responsiblePerson = (string)elem.Element("ResponsiblePerson"); string condition = (string)elem.Element("Condition"); string serviceDate = (string)elem.Element("ServiceDate"); int write_off = (int)elem.Element("Write_off"); string comment = (string)elem.Element("Comment"); string state = (string)elem.Element("State"); string exploitationDate = (string)elem.Element("ExploitationDate"); string endDate = (string)elem.Element("EndDate"); string receivingDate = (string)elem.Element("ReceivingDate"); string productionDate = (string)elem.Element("ProductionDate"); Product prod = new Product(number, name, index, exploitationPlace, factoryNumber, inventoryNumber, bbtNomenclature, purpose, manufacturer, productionDate, guarantee, endDate, exploitationPeriod, confirmationDoc, confirmationNumber, receivingDate, orderNumber, exploitationDate, primaryCost, aurum, argentum, platinum, mpg, responsiblePerson, condition, serviceDate, write_off, comment, false, state); result.AddProduct(prod); } RaiseDatabaseUpdateInfo(); return(result); }
public static ProductDatabase LoadFromXls(string path) { Process[] excelProcsOld = Process.GetProcessesByName("EXCEL"); Excel.Application excelApp = new Excel.Application(); Excel.Workbooks workbooks; Excel.Workbook excelBook; workbooks = excelApp.Workbooks; excelBook = workbooks.Add(path); Excel.Worksheet excelSheet = (Excel.Worksheet)(excelBook.Sheets[1]); int lastRow = excelSheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Row; int lastColumnNumber = excelSheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Column; string lastColumn = DigToSymb(lastColumnNumber); int beginningIndex = Int32.Parse(DataController.dataContext.BeginRange); RaiseProgressInfo(0); int prevProg = 0; ProductDatabase result = new ProductDatabase(); int maxIndex = lastRow; int divided = maxIndex / 10; System.Array MyValues = (System.Array)excelSheet.get_Range("A1", lastColumn + lastRow.ToString()).Cells.Value; for (int i = beginningIndex; i <= lastRow; i++) { for (int j = 1; j < lastColumnNumber; j++) { if (MyValues.GetValue(i, j) == null) { MyValues.SetValue("", i, j); } } } for (int index = beginningIndex; index <= lastRow; index++) { if ((index / divided) != prevProg) { prevProg = index / divided; RaiseProgressInfo(prevProg * 10); } /*System.Array MyValues = (System.Array)excelSheet.get_Range("A" + * index.ToString(), lastColumn + index.ToString()).Cells.Value;*/ string name = "", ind = "", exPlace = "", facNum = "", invNum = "", bbtNom = "", purp = "", manufac = "", prodDate = "", guar = "", endDate = "", exPer = "", confDoc = "", confNum = "", recDate = "", ordNum = "", expDate = "", primCost = "", resp = "", cond = "", servDate = "", comm = ""; double aur = 0, arg = 0, plat = 0, mpg = 0; int write = 0; try { name = MyValues.GetValue(index, SymbToDig(DataController.dataContext.NameColumn)).ToString(); ind = MyValues.GetValue(index, SymbToDig(DataController.dataContext.IndexColumn)).ToString(); exPlace = MyValues.GetValue(index, SymbToDig(DataController.dataContext.ExploitationPlaceColumn)).ToString(); facNum = MyValues.GetValue(index, SymbToDig(DataController.dataContext.FactoryNumberColumn)).ToString(); invNum = MyValues.GetValue(index, SymbToDig(DataController.dataContext.InventoryNumberColumn)).ToString(); bbtNom = MyValues.GetValue(index, SymbToDig(DataController.dataContext.BbtNomenclatureColumn)).ToString(); purp = MyValues.GetValue(index, SymbToDig(DataController.dataContext.PurposeColumn)).ToString(); manufac = MyValues.GetValue(index, SymbToDig(DataController.dataContext.ManufacturerColumn)).ToString(); prodDate = MyValues.GetValue(index, SymbToDig(DataController.dataContext.ProductionDateColumn)).ToString(); guar = MyValues.GetValue(index, SymbToDig(DataController.dataContext.GuaranteeColumn)).ToString(); endDate = MyValues.GetValue(index, SymbToDig(DataController.dataContext.EndDateColumn)).ToString(); exPer = MyValues.GetValue(index, SymbToDig(DataController.dataContext.ExploitationPeriodColumn)).ToString(); confDoc = MyValues.GetValue(index, SymbToDig(DataController.dataContext.ConfirmationDocColumn)).ToString(); confNum = MyValues.GetValue(index, SymbToDig(DataController.dataContext.ConfirmationNumberColumn)).ToString(); recDate = MyValues.GetValue(index, SymbToDig(DataController.dataContext.ReceivingDateColumn)).ToString(); ordNum = MyValues.GetValue(index, SymbToDig(DataController.dataContext.OrderNumberColumn)).ToString(); expDate = MyValues.GetValue(index, SymbToDig(DataController.dataContext.ExploitationDateColumn)).ToString(); primCost = MyValues.GetValue(index, SymbToDig(DataController.dataContext.PrimaryCostColumn)).ToString(); resp = MyValues.GetValue(index, SymbToDig(DataController.dataContext.ResponsiblePersonColumn)).ToString(); cond = MyValues.GetValue(index, SymbToDig(DataController.dataContext.ConditionColumn)).ToString(); servDate = MyValues.GetValue(index, SymbToDig(DataController.dataContext.ServiceDateColumn)).ToString(); comm = MyValues.GetValue(index, SymbToDig(DataController.dataContext.CommentColumn)).ToString(); Double.TryParse(MyValues.GetValue(index, SymbToDig(DataController.dataContext.AurumColumn)).ToString(), out aur); Double.TryParse(MyValues.GetValue(index, SymbToDig(DataController.dataContext.ArgentumColumn)).ToString(), out arg); Double.TryParse(MyValues.GetValue(index, SymbToDig(DataController.dataContext.PlatinumColumn)).ToString(), out plat); Double.TryParse(MyValues.GetValue(index, SymbToDig(DataController.dataContext.MpgColumn)).ToString(), out mpg); Int32.TryParse(MyValues.GetValue(index, SymbToDig(DataController.dataContext.Write_offColumn)).ToString(), out write); /*facPlace = MyValues.GetValue(1, 1).ToString(); * name=MyValues.GetValue(1, 2).ToString(); * ind = MyValues.GetValue(1, 3).ToString(); * facNum = MyValues.GetValue(1, 4).ToString(); * invNum = ""; * bbtNom = MyValues.GetValue(1, 8).ToString(); * purp = MyValues.GetValue(1, 9).ToString(); * manufac = MyValues.GetValue(1, 10).ToString(); * guar = MyValues.GetValue(1, 12).ToString(); * exPer = MyValues.GetValue(1, 15).ToString(); * confDoc=MyValues.GetValue(1, 16).ToString(); * confNum = MyValues.GetValue(1, 17).ToString(); * ordNum = MyValues.GetValue(1, 21).ToString(); * primCost = MyValues.GetValue(1, 23).ToString(); * resp = MyValues.GetValue(1, 28).ToString(); * cond = MyValues.GetValue(1, 33).ToString(); */ } catch (Exception ex) { DataController.ShowErrorWindow("Строка " + index.ToString() + "не импортирована"); continue; } result.AddProduct(new Product(0, name, ind, exPlace, facNum, invNum, bbtNom, purp, manufac, prodDate, guar, endDate, exPlace, confDoc, confNum, recDate, ordNum, expDate, primCost, aur, arg, plat, mpg, resp, cond, servDate, write, comm)); } Marshal.ReleaseComObject(excelSheet); //Marshal.ReleaseComObject(sheets); excelBook.Close(true); Marshal.ReleaseComObject(excelBook); Marshal.ReleaseComObject(workbooks); excelApp.Quit(); Marshal.ReleaseComObject(excelApp); excelSheet = null; excelBook = null; excelApp = null; Process[] excelProcsNew = Process.GetProcessesByName("EXCEL"); foreach (Process procNew in excelProcsNew) { int exist = 0; foreach (Process procOld in excelProcsOld) { if (procNew.Id == procOld.Id) { exist++; } } if (exist == 0) { procNew.Kill(); } } RaiseDatabaseUpdateInfo(); return(result); }
public IActionResult Add([FromForm] string productName) { logger.LogInformation("Adding product {0}", productName); ProductDatabase.AddProduct(productName, User.Identity.Name); return(RedirectToAction("Index")); }