private int GetIndexOfRowCategory(DataGridView dataGrid, int id) { for (int i = 0; i < dataGrid.Rows.Count; i += 1) { SCOptionCategory row = new SCOptionCategory(); // or.DataBoundItem; row = this.RowToCategory(dataGrid.Rows[i]); if (row.OID == id) { return(i); } } return(0); }
public SCOptionCategory RowToCategory(DataGridViewRow row) { SCOptionCategory sc = new SCOptionCategory(); int number = -1; bool tmp = Int32.TryParse(row.Cells[0].Value.ToString(), out number); if (tmp) { sc.OID = number; } else { sc.OID = -1; } return(sc); }
public SCOptionBase getOptionBase(string name, string text) { string type = name.Substring(0, 1); Int32 value = Int32.Parse(name.Substring(1)); if (type.Equals("C")) { return(SCOptionCategory.getByOID(value)); } else if (type.Equals("O")) { return(SCOption.getByOID(value)); } else { return(SCOptionDetail.getByOID(value)); } }
private void addRow(TreeNode Node) { var item = getOptionBase(Node.Name, Node.Text); if (item != null) { //Add List OptionCategories ContractOption rtn = null; if (item.GetType() == typeof(SCOptionCategory)) { SCOptionCategory catetory = (SCOptionCategory)item; rtn = new ContractOption(); rtn.OptionCategoryOID = item.OID; rtn.Name = item.Name; rtn.PartNr = item.ItemNo; rtn.PartName = item.ItemName; rtn.LabourCode = item.WrksId; rtn.LabourName = item.WrksName; rtn.BaseSelPr = item.SelPr; rtn.PurchasePr = item.BuyPr; rtn.BasePurchasePr = item.BuyPr; rtn.InvoiceFlag = catetory.InvoiceFlag; } else if (item.GetType() == typeof(SCOption)) { rtn = new ContractOption(); TreeNode parent = Node.Parent; Int32 cateId = Int32.Parse(parent.Name.Substring(1)); SCOption option = (SCOption)item; rtn.OptionCategoryOID = cateId; rtn.OptionOID = option.OID; rtn.Name = option.Name; rtn.PartNr = option.ItemNo; rtn.PartName = option.ItemName; rtn.LabourCode = option.WrksId; rtn.LabourName = option.WrksName; rtn.BaseSelPr = option.SelPr; rtn.PurchasePr = option.BuyPr; rtn.BasePurchasePr = option.BuyPr; } else { rtn = new ContractOption(); TreeNode scOption = Node.Parent; Int32 optionOID = Int32.Parse(scOption.Name.Substring(1)); TreeNode scCate = scOption.Parent; Int32 cateOID = Int32.Parse(scCate.Name.Substring(1)); SCOptionDetail detail = (SCOptionDetail)item; rtn.OptionCategoryOID = cateOID; rtn.OptionOID = optionOID; rtn.OptionDetailOID = detail.OID; rtn.Name = detail.Name; rtn.PartNr = detail.ItemNo; rtn.PartName = detail.ItemName; rtn.LabourCode = detail.WrksId; rtn.LabourName = detail.WrksName; rtn.BaseSelPr = detail.SelPr; rtn.PurchasePr = detail.BuyPr; rtn.BasePurchasePr = detail.BuyPr; } if (rtn != null) { rtn.ContractOID = ContractFrm.objContract.ContractOID; //Update info try { ContractOption finded = ContractFrm.objContract.listContractOptions.Single(s => s.OptionCategoryOID == rtn.OptionCategoryOID && s.OptionOID == rtn.OptionOID && s.OptionDetailOID == rtn.OptionDetailOID); rtn.Info = finded.Info; rtn.PartialPayer = finded.PartialPayer; rtn.Quantity = finded.Quantity; if (finded.SalePr <= 0 && rtn.BaseSelPr > 0) { rtn.SalePr = rtn.BaseSelPr; } else { rtn.SalePr = finded.SalePr; } rtn.PurchasePr = finded.PurchasePr; //rtn.BaseSelPr = finded.BaseSelPr; } catch (System.InvalidOperationException ex) { rtn.Quantity = 1; rtn.SalePr = rtn.BaseSelPr; rtn.PurchasePr = rtn.BasePurchasePr; _log.Error("ContractFrm.objContract.listContractOptions Single not contain exactly one element: " + rtn.toString(), ex); } if (!listOptionDetailTmp.ContainsKey(Node.Name)) { addToDic(rtn); } //Add to grid try { ContractOption finded = listOptionDetail.Single(s => s.OptionCategoryOID == rtn.OptionCategoryOID && s.OptionOID == rtn.OptionOID && s.OptionDetailOID == rtn.OptionDetailOID); finded.Info = rtn.Info; finded.PartialPayer = rtn.PartialPayer; finded.Quantity = rtn.Quantity; finded.SalePr = rtn.SalePr; finded.BaseSelPr = rtn.BaseSelPr; finded.PurchasePr = rtn.PurchasePr; } catch (System.InvalidOperationException ex) { _log.Error("listOptionDetail Single not contain exactly one element: " + rtn.toString(), ex); //Add to list listOptionDetail.Add(rtn); //Add to grid DataRow drToAdd = ObjectUtils.FillDataToRow(dataTable.NewRow(), rtn); dataTable.Rows.Add(drToAdd); } } } }