/// <summary> /// Applies the inventory to a vessel, specifically the part tracker module. Happens in the Editor /// </summary> /// <param name="input">The vessel as a list of parts</param> public static void ApplyInventoryToVessel(IEnumerable <Part> input) { PartInventory copy = ScrapYard.Instance.TheInventory.Copy(); foreach (Part part in input) { //convert it to an inventorypart InventoryPart iPart = new InventoryPart(part); //find a corresponding one in the inventory and remove it InventoryPart inInventory = copy.RemovePart(iPart.ID); if (inInventory == null) { inInventory = copy.RemovePart(iPart, ComparisonStrength.MODULES); } //if one was found... if (inInventory != null) { Logging.DebugLog("Found a part in inventory for " + inInventory.Name); //copy it's part tracker over if (inInventory.TrackerModule != null && part.Modules?.Contains("ModuleSYPartTracker") == true) { ModuleSYPartTracker tracker = part.Modules["ModuleSYPartTracker"] as ModuleSYPartTracker; tracker.TimesRecovered = inInventory.TrackerModule.TimesRecovered; tracker.Inventoried = inInventory.TrackerModule.Inventoried; tracker.ID = inInventory.ID; Logging.Log($"Copied tracker. Recovered {tracker.TimesRecovered} times with id {tracker.ID}"); } } } ScrapYardEvents.OnSYInventoryAppliedToVessel.Fire(); GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship); }
private void sellPart() { //confirm with user string msg = "Are you sure you want to discard the part?"; if (_selling) { msg = $"Are you sure you want to sell the part for {_backingPart.DryCost} funds?"; } MultiOptionDialog diag = new MultiOptionDialog("confirmDiscard", msg, _sellOrDiscard + " Part", HighLogic.UISkin, new DialogGUIButton(_sellOrDiscard, () => { InventoryPart removed = _backingInventory.RemovePart(_backingPart, ComparisonStrength.STRICT); if (removed != null) { Logging.Log($"Sold/Discarded {removed.Name}:{removed.ID}"); if (_selling) { Funding.Instance?.AddFunds(removed.DryCost, TransactionReasons.Vessels); } Updated?.Invoke(this, EventArgs.Empty); } }), new DialogGUIButton("Cancel", () => { })); PopupDialog.SpawnPopupDialog(diag, false, HighLogic.UISkin); }
/// <summary> /// Sells/Discards parts from the inventory. Removes the parts from the inventory and refunds the correct amount. /// </summary> /// <param name="parts">The parts to sell</param> /// <returns>The total value of the sale</returns> public static double SellParts(IEnumerable <InventoryPart> parts) { double totalValue = 0; foreach (InventoryPart part in parts) { double value = 0; if (part.TrackerModule.Inventoried) { InventoryPart inInventory = ScrapYard.Instance.TheInventory.RemovePart(part, ComparisonStrength.STRICT); //strict, we only remove parts that are exact if (inInventory != null) { value = inInventory.DryCost * ScrapYard.Instance.Settings.CurrentSaveSettings.FundsSalePercent / 100.0; Logging.DebugLog($"Selling/Discarding a part in inventory for {inInventory.Name} for {value} funds ({ScrapYard.Instance.Settings.CurrentSaveSettings.OverrideFunds}). id: {inInventory.ID}"); //add funds back if active if (ScrapYard.Instance.Settings.CurrentSaveSettings.OverrideFunds) { Funding.Instance?.AddFunds(value, TransactionReasons.VesselRollout); } } } totalValue += value; } return(totalValue); }
/// <summary> /// Takes a list of InventoryParts and removes any that are in use by the current vessel /// </summary> /// <param name="sourceList">The list of parts to search in</param> /// <returns>A List of parts that aren't being used</returns> public static IList <InventoryPart> FilterOutUsedParts(IEnumerable <InventoryPart> sourceList) { List <InventoryPart> retList = new List <InventoryPart>(sourceList); if (!HighLogic.LoadedSceneIsEditor) { return(retList); } foreach (Part part in EditorLogic.fetch.ship) { InventoryPart iPart = new InventoryPart(part); InventoryPart found = retList.FirstOrDefault(ip => ip.IsSameAs(iPart, ComparisonStrength.STRICT)); if (found != null) { retList.Remove(found); } } if (EditorLogic.SelectedPart != null) { foreach (Part part in EditorLogic.FindPartsInChildren(EditorLogic.SelectedPart)) { InventoryPart iPart = new InventoryPart(part); InventoryPart found = retList.FirstOrDefault(ip => ip.IsSameAs(iPart, ComparisonStrength.STRICT)); if (found != null) { retList.Remove(found); } } } return(retList); }
void Clo() { InventoryPart.SetActive(false); InvOpn = false; Information.GetComponent <Text>().text = "Name: \nAmount: \nMass: "; RightFinger.SetActive(true); }
public static InventoryPart RemoveBrick(InventoryPart brick) { if (brick.QuantityInStore > 0) { brick.QuantityInStore--; } db.Delete(brick); db.Insert(brick); return(brick); }
public static InventoryPart AddBrick(InventoryPart brick) { if (brick.QuantityInStore < brick.QuantityInSet) { brick.QuantityInStore++; } db.Delete(brick); db.Insert(brick); return(brick); }
public PartInstance(PartInventory inventory, InventoryPart iPart, bool selling, Part toApply) { _backingPart = iPart; _backingInventory = inventory; _selling = selling; if (selling) { _sellOrDiscard = "Sell"; } _toApply = toApply; _moduleVM = new InstanceModulesVM(_backingPart); }
/// <summary> /// 取得零件库存 /// </summary> public string GetInventory(string partNo, string Site) { //partNo=cmb_partno.SelectedValue.ToString(); //Site = cmb_site.SelectedValue.ToString(); //string isInv = InventoryPart.GetIsInventory(Site, partNo); //if (isInv == "1") // checkBox1.Checked = true; //else // checkBox1.Checked = false; string invQty = InventoryPart.GetInventoryqty(Site, partNo); return(invQty); }
/// <summary> /// 控制申请数量只能填写数字 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgv1_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { int i = e.ColumnIndex; DataGridViewColumn column = dgv1.Columns[e.ColumnIndex]; if (column.Name == "申请数量") { if (dgv1.Rows[e.RowIndex].Cells[i].Value != null) { string rqty = dgv1.Rows[e.RowIndex].Cells[i].Value.ToString(); if (BaseClass.validateNum(rqty) == false) { MessageBox.Show("请输入数字!!!", "提示"); dgv1.Rows[e.RowIndex].Cells[i].Value = ""; } } } else if (column.Name == "零件号") { if (dgv1.Rows[e.RowIndex].Cells[i].Value != null) { string rqty = dgv1.Rows[e.RowIndex].Cells[i].Value.ToString(); string Site = cmb_site.SelectedValue.ToString(); InventoryPart invpartnew = InventoryPart.FindInvInfor(rqty, Site); if (invpartnew != null) { dgv1.Rows[e.RowIndex].Cells[i].Value = invpartnew.PART_NO; dgv1.Rows[e.RowIndex].Cells[i + 1].Value = invpartnew.description; dgv1.Rows[e.RowIndex].Cells["单位"].Value = invpartnew.unit_meas; } else { MessageBox.Show("无此材料编码"); return; } InventoryPart invpart = InventoryPart.GetOnhandqty(Site, rqty, ProjectId); if (invpart != null) { dgv1.Rows[e.RowIndex].Cells["inventory_qty"].Value = invpart.qty_onhand; dgv1.Rows[e.RowIndex].Cells["JYstock"].Value = invpart.qty_reserved; dgv1.Rows[e.RowIndex].Cells["meo_qty"].Value = Convert.ToDecimal(invpart.qty_onhand) - Convert.ToDecimal(invpart.qty_reserved); } } } } }
/// <summary> /// Removes any inventory parts from the inventory (vessel rollout, KCT construction) /// </summary> /// <param name="input">The vessel as a list of part ConfigNodes.</param> public static void RemovePartsFromInventory(IEnumerable <ConfigNode> input) { foreach (ConfigNode partNode in input) { //convert it to an inventorypart InventoryPart iPart = new InventoryPart(partNode); if (iPart.TrackerModule.Inventoried) { //find a corresponding one in the inventory and remove it InventoryPart inInventory = ScrapYard.Instance.TheInventory.RemovePart(iPart, ComparisonStrength.STRICT); //if one was found... if (inInventory != null) { Logging.DebugLog($"Removed a part in inventory for {inInventory.Name} id: {inInventory.ID}"); //add funds back if active if (ScrapYard.Instance.Settings.CurrentSaveSettings.OverrideFunds) { Funding.Instance?.AddFunds(inInventory.DryCost, TransactionReasons.VesselRollout); } } else { //reset their tracker status Logging.Log($"Found inventory part on vessel that is not in inventory. Resetting. {iPart.Name}:{iPart.ID}"); ConfigNode tracker = partNode.GetNodes("MODULE").FirstOrDefault(n => n.GetValue("name") == "ModuleSYPartTracker"); tracker.SetValue("ID", Guid.NewGuid().ToString()); tracker.SetValue("TimeRecovered", 0); tracker.SetValue("Inventoried", false); } } else { //Not inventortied, so we should enforce that it's a new part (imagine a saved craft, the parts aren't in the inventory anymore //but the tracking data is still saved) ConfigNode tracker = partNode.GetNodes("MODULE").FirstOrDefault(n => n.GetValue("name") == "ModuleSYPartTracker"); if (tracker != null) { tracker.SetValue("ID", Guid.NewGuid().ToString()); tracker.SetValue("TimeRecovered", 0); tracker.SetValue("Inventoried", false); } } } }
public void Refurbish(InventoryPart part) { //check that the module is on the part, then process it IList <ConfigNode> modules = part.ListModules(); for (int i = modules.Count - 1; i >= 0; i--) { ConfigNode module = modules[i]; if (string.Equals(module.GetValue("name"), ModuleName, StringComparison.Ordinal)) { //do refurbishment for (int j = RefurbishmentOperations.Count - 1; j >= 0; j--) { RefurbishmentOperations[j].PerformOperation(module); } } } }
private void cmb_partno_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { //string projectid = cmb_project.SelectedValue.ToString(); string site = cmb_site.SelectedValue.ToString(); string PartNo = cmb_partno.Text.Trim().ToString(); if (PartNo == string.Empty) { MessageBox.Show("请写入零件编号"); return; } DataSet PartNameDS = InventoryPart.FindInvPartDataset(PartNo, site); DataRow row = PartNameDS.Tables[0].NewRow(); row[0] = ""; PartNameDS.Tables[0].Rows.InsertAt(row, 0); cmb_partno.DataSource = PartNameDS.Tables[0].DefaultView; cmb_partno.DisplayMember = "PART_NO"; cmb_partno.ValueMember = "PART_NO"; cmb_partname.DataSource = PartNameDS.Tables[0].DefaultView; if (PartNameDS.Tables[0].Rows.Count == 0) { MessageBox.Show("不存在此零件编号!"); return; } cmb_partname.DisplayMember = "DESCRIPTION"; cmb_partname.ValueMember = "PART_NO"; //InventoryPart pp = InventoryPart.FindInvInfor(partno, site); //if (pp != null) //{ // lbl_name.Text = pp.description; // txt_unit.Text = pp.unit_meas; //} //else // MessageBox.Show("不存在此零件编号!"); } }
/// <summary> /// Splits a list of parts into a list of those that are in the inventory and those that are not /// </summary> /// <param name="input"></param> /// <param name="inInventory"></param> /// <param name="notInInventory"></param> public static void SplitParts(IEnumerable <Part> input, out IList <InventoryPart> inInventory, out IList <InventoryPart> notInInventory) { inInventory = new List <InventoryPart>(); notInInventory = new List <InventoryPart>(); PartInventory InventoryCopy = ScrapYard.Instance.TheInventory.Copy(); foreach (Part part in input) { InventoryPart inputPart = new InventoryPart(part); if (InventoryCopy.RemovePart(inputPart) != null) { inInventory.Add(inputPart); } else { notInInventory.Add(inputPart); } } }
public static void UpdateEditorCost() { if (!ScrapYard.Instance.Settings.CurrentSaveSettings.OverrideFunds) { return; } float dry, fuel; float totalCost = EditorLogic.fetch.ship.GetShipCosts(out dry, out fuel); foreach (Part part in EditorLogic.fetch?.ship?.Parts ?? new List <Part>()) { InventoryPart iPart = new InventoryPart(part); if (iPart.TrackerModule.Inventoried) { totalCost -= iPart.DryCost; } } //set visible cost in editor UI UpdateCostUI(totalCost); }
/// <summary> /// Removes any inventory parts from the inventory (vessel rollout, KCT construction) /// </summary> /// <param name="input">The vessel as a list of parts.</param> public static void RemovePartsFromInventory(IEnumerable <Part> input) { foreach (Part part in input) { InventoryPart iPart = new InventoryPart(part); if (iPart.TrackerModule.Inventoried) { InventoryPart inInventory = ScrapYard.Instance.TheInventory.RemovePart(iPart, ComparisonStrength.STRICT); //strict, we only remove parts that are exact if (inInventory != null) { Logging.DebugLog($"Removed a part in inventory for {inInventory.Name} id: {inInventory.ID}"); //add funds back if active if (ScrapYard.Instance.Settings.CurrentSaveSettings.OverrideFunds) { Funding.Instance?.AddFunds(inInventory.DryCost, TransactionReasons.VesselRollout); } } else { //we couldn't find the appropriate part in the inventory, should we "make it fresh"? Or do we allow this... //I mean, we kind of should allow it. Maybe. Maybe not though. //we do need to verify they havent changed a part after applying it. may as well do it here //but then kct edits need to add all parts back to the inventory. thats fair //basically we say that you cant bring your own inventory parts and must buy ours for 4x the cost :P //reset their tracker status Logging.Log($"Found inventory part on vessel that is not in inventory. Resetting. {iPart.Name}:{iPart.ID}"); (part.Modules["ModuleSYPartTracker"] as ModuleSYPartTracker).MakeFresh(); } } else { //It's not in the inventory, great, but it could be saved (imagine launching a saved craft from the launchpad UI) //KCT gets around this by basically requiring new builds all the time, but that won't fly for UPFM //So we should ALWAYS make them fresh if we can't find it in the inventory, but we don't need to log that (part.Modules["ModuleSYPartTracker"] as ModuleSYPartTracker)?.MakeFresh(); } } }
/// <summary> /// Applies the inventory to a vessel, specifically the part tracker module. Happens in the Editor /// </summary> /// <param name="input">The vessel as a list of part ConfigNodes</param> public static void ApplyInventoryToVessel(IEnumerable <ConfigNode> input) { PartInventory copy = ScrapYard.Instance.TheInventory.Copy(); foreach (ConfigNode partNode in input) { //convert it to an inventorypart InventoryPart iPart = new InventoryPart(partNode); //find a corresponding one in the inventory and remove it InventoryPart inInventory = copy.RemovePart(iPart.ID); if (inInventory == null) { inInventory = copy.RemovePart(iPart, ComparisonStrength.MODULES); } //if one was found... if (inInventory != null) { Logging.DebugLog("Found a part in inventory for " + inInventory.Name); //copy it's part tracker over ConfigNode trackerNode; if (inInventory.TrackerModule != null && (trackerNode = partNode.GetModuleNode("ModuleSYPartTracker")) != null) { string id = inInventory.ID.ToString(); int recovered = inInventory.TrackerModule.TimesRecovered; bool inventoried = inInventory.TrackerModule.Inventoried; trackerNode.SetValue("ID", id); trackerNode.SetValue("TimesRecovered", recovered); trackerNode.SetValue("Inventoried", inventoried); Logging.DebugLog($"Copied tracker. Recovered {recovered} times with id {id}"); } } } ScrapYardEvents.OnSYInventoryAppliedToVessel.Fire(); GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship); }
public void listviewBind(string sql) { //更改并设置列名称以及属性 DataSet ds = PartParameter.QueryPartPara(sql); dgv1.DataSource = ds.Tables[0]; //DataGridViewComboBoxColumn dgvcom = new DataGridViewComboBoxColumn(); //dgvcom.DataSource = PartParameter.QueryPartPara("select name from mm_unit_tab").Tables[0].DefaultView;; //dgvcom.DisplayMember = "name"; //dgvcom.ValueMember = "name"; ////dgv1.Columns.Insert(1, dgvcom); //dgv1.GridColumnStyles[1]=dgvcom; //dgv1.Columns["零件认证"].Width = 100; //dgv1.Columns["单位密度"].ValueType = typeof(); //dgv1.Columns["零件材质"].ValueType = typeof(float); dgv1.Columns["域"].ReadOnly = true; dgv1.Columns["序号"].ReadOnly = true; dgv1.Columns["零件号"].ReadOnly = true; //dgv1.Columns["零件类别"].ReadOnly = true; //dgv1.Columns["零件规格"].ReadOnly = true; //dgv1.Columns["材质"].ReadOnly = true; //dgv1.Columns["证书"].ReadOnly = true; //dgv1.Columns["单位"].ReadOnly = true; dgv1.Columns["parentid"].Visible = false; #region 将库存值填入表格 if (cb_showqty.Checked == true) { dgv1.Columns["项目预留数量"].ReadOnly = true; dgv1.Columns["项目采购数量"].ReadOnly = true; dgv1.Columns["项目可用库存量"].ReadOnly = true; if (dgv1.RowCount != 0) { ProjectCmbItem item = (ProjectCmbItem)cmb_project.SelectedItem; if (item == null) { MessageBox.Show("请选择所查询的项目"); return; } string projectname = item.Value; for (int i = 0; i < dgv1.Rows.Count; i++) { string partno = dgv1.Rows[i].Cells["零件号"].Value.ToString(); InventoryPart part_kucun = InventoryPart.GetOnhandqty(site, partno, projectname.Substring(projectname.Length - 3, 3));; if (part_kucun != null) { dgv1.Rows[i].Cells["项目可用库存量"].Value = part_kucun.qty_onhand; dgv1.Rows[i].Cells["项目采购数量"].Value = Convert.ToDecimal(part_kucun.qty_onhand) - Convert.ToDecimal(part_kucun.qty_reserved); dgv1.Rows[i].Cells["项目预留数量"].Value = part_kucun.qty_reserved; } else { dgv1.Rows[i].Cells["预估量"].Value = 0; //dgv1.Rows[i].Cells[2].Value = "M"; } } //} } } #endregion //#region 设置列的只读性 //int specnum = PartParameter.GetSpecCou(activity); //if (specnum != 0) //{ // if (specnum > 0) // { // string colstr = PartParameter.GetSpecName(activity, "1").Trim(); // dgv1.Columns[colstr].ReadOnly = true; // } // if (specnum > 1) // { // string colstr = PartParameter.GetSpecName(activity, "2").Trim(); // dgv1.Columns[colstr].ReadOnly = true; // } // if (specnum > 2) // { // string colstr = PartParameter.GetSpecName(activity, "3").Trim(); // dgv1.Columns[colstr].ReadOnly = true; // } // if (specnum > 3) // { // string colstr = PartParameter.GetSpecName(activity, "4").Trim(); // dgv1.Columns[colstr].ReadOnly = true; // } //} //#endregion #region 将已设置过的预估值填入表格 //if (dgv1.RowCount != 0) //{ // List<PartParameter> pp = PartParameter.FindPartList(activity, ProjectId,LoginUser,1); // //if (pp.Count != 0) // // { // for (int i = 0; i < dgv1.Rows.Count; i++) // { // int partid = int.Parse(dgv1.Rows[i].Cells["序号"].Value.ToString()); // PartParameter pone = pp.Find(delegate(PartParameter bb) { return bb.ID == partid; }); // if (pone != null) // { // dgv1.Rows[i].Cells["预估量"].Value = pone.PREDICTION_QTY; // //dgv1.Rows[i].Cells[2].Value = pone.UNIT; // } // else // { // dgv1.Rows[i].Cells["预估量"].Value = 0; // //dgv1.Rows[i].Cells[2].Value = "M"; // } // } // //} //} #endregion }
private void button1_Click(object sender, EventArgs e) { if (dgv1.RowCount < 1) { return; } Site = cmb_site.SelectedValue.ToString(); if (Site == string.Empty) { MessageBox.Show("请选择ERP域!"); return; } #region 开始循环比对Excel中的每行的材料号是否都对。 for (int i = 0; i < dgv1.RowCount - 1; i++) { string partno = dgv1.Rows[i].Cells[4].Value.ToString(); if (string.IsNullOrEmpty(partno)) { //MessageBox.Show("第" + (i + 1) + "行此材料编码不存在"); //return; } else { InventoryPart invpartnew = InventoryPart.FindInvInfor(partno, Site); if (invpartnew != null) { } else { MessageBox.Show("第" + (i + 1) + "行ERP中无此材料编码"); return; } } } #endregion string appdir = System.AppDomain.CurrentDomain.BaseDirectory; InitializeWorkbook(@appdir + "Template\\项目MSS明细表.xls"); ISheet sheet1 = hssfworkbook.GetSheet("MSS明细表"); //create cell on rows, since rows do already exist,it's not necessary to create rows again. //sheet1.GetRow(1).GetCell(1).SetCellValue(200200); //sheet1.GetRow(2).GetCell(1).SetCellValue(300); //sheet1.GetRow(3).GetCell(1).SetCellValue(500050); //sheet1.GetRow(4).GetCell(1).SetCellValue(8000); int j = 0, l = 0; #region 开始循环比对Excel中的每行的库存以及申请数量 for (int i = 0; i < dgv1.RowCount; i++) { string partno = dgv1.Rows[i].Cells[4].Value.ToString(); string Project_id = string.Empty; Project_id = dgv1.Rows[i].Cells["Column1"].Value.ToString(); ProjectId = project.FindERPID(Project_id); if (!string.IsNullOrEmpty(partno)) { if (partno.Length < 7) { partno = "0" + partno; } int tt = j + 1; string partname, unitname; InventoryPart invpartnew = InventoryPart.FindInvInfor(partno, Site); if (invpartnew != null) { partname = invpartnew.description; unitname = invpartnew.unit_meas; } else { MessageBox.Show("第" + i + "行ERP中无此材料编码"); return; } //DateTime reqdatestr = Convert.ToDateTime(dgv1.Rows[i].Cells["需求日期"].Value); //string reqreason = dgv1.Rows[i].Cells[4].Value.ToString(); string reqreason = "1001"; string preQty = dgv1.Rows[i].Cells[6].Value.ToString(); string purpose = dgv1.Rows[i].Cells["Column9"].Value.ToString(); string remark = dgv1.Rows[i].Cells["图纸号"].Value.ToString(); Str_Discipline = dgv1.Rows[i].Cells[3].Value.ToString(); string replaceno = ""; InventoryPart invpart = InventoryPart.GetRequiredqty(Site, partno, ProjectId); decimal left_reqqty = 0, reserved_qty = 0; if (invpart != null) { left_reqqty = Convert.ToDecimal(invpart.qty_reserved); reserved_qty = Convert.ToDecimal(invpart.qty_onhand) - Convert.ToDecimal(invpart.qty_issued); } if (!string.IsNullOrEmpty(purpose)) { Str_Area = ProjectBlock.GetAreaByBlock(purpose, ProjectId, Site); } decimal needqty = Convert.ToDecimal(preQty); #region 如果数量不够则考虑替代码的库存以及申请情况 if (Convert.ToDecimal(preQty) > left_reqqty + reserved_qty) { #region 先将标准码数量写入 if (left_reqqty + reserved_qty > 0) { string meo_no = GetPartMEONO(partno, preQty); sheet1.GetRow(j + 5).GetCell(0).SetCellValue(tt.ToString()); sheet1.GetRow(j + 5).GetCell(1).SetCellValue(ProjectId); sheet1.GetRow(j + 5).GetCell(2).SetCellValue(Str_Area); sheet1.GetRow(j + 5).GetCell(3).SetCellValue(Str_FX); sheet1.GetRow(j + 5).GetCell(4).SetCellValue(Str_Discipline); sheet1.GetRow(j + 5).GetCell(5).SetCellValue(ActivityName); sheet1.GetRow(j + 5).GetCell(6).SetCellValue(partno); sheet1.GetRow(j + 5).GetCell(7).SetCellValue(partname); sheet1.GetRow(j + 5).GetCell(9).SetCellValue((left_reqqty + reserved_qty).ToString()); sheet1.GetRow(j + 5).GetCell(10).SetCellValue(unitname); sheet1.GetRow(j + 5).GetCell(8).SetCellValue(meo_no); sheet1.GetRow(j + 5).GetCell(12).SetCellValue(reqreason); sheet1.GetRow(j + 5).GetCell(17).SetCellValue(replaceno); sheet1.GetRow(j + 5).GetCell(15).SetCellValue(remark); sheet1.GetRow(j + 5).GetCell(16).SetCellValue(purpose); j++; } #endregion needqty = Convert.ToDecimal(preQty) - left_reqqty - reserved_qty; #region 替代码的库存数量以及需求数量比对 DataSet ReplaceDS = Ration.QueryPartRationList("select replace_no,part_description from mm_part_standard_tab where part_no ='" + partno + "'"); if (ReplaceDS != null) { int p = ReplaceDS.Tables[0].Rows.Count; for (int k = 0; k < p; k++) { string ReplaceNo = ReplaceDS.Tables[0].Rows[k][0].ToString(); string ReplaceDesc = ReplaceDS.Tables[0].Rows[k][1].ToString(); InventoryPart invparttemp = InventoryPart.GetRequiredqty(Site, ReplaceNo, ProjectId); decimal temp_left_reqqty = 0, temp_reserved_qty = 0; if (invparttemp != null) { temp_left_reqqty = Convert.ToDecimal(invparttemp.qty_reserved); temp_reserved_qty = Convert.ToDecimal(invparttemp.qty_onhand) - Convert.ToDecimal(invparttemp.qty_issued); if (temp_left_reqqty + temp_reserved_qty > 0) { #region 此替代码数量仍然不够 if (Convert.ToDecimal(needqty) > temp_left_reqqty + temp_reserved_qty) { replaceno = replaceno + ReplaceNo + ";"; needqty = needqty - temp_left_reqqty - temp_reserved_qty; string meo_no = GetPartMEONO(ReplaceNo, (temp_left_reqqty + temp_reserved_qty).ToString()); sheet1.GetRow(j + 5).GetCell(0).SetCellValue(tt.ToString()); sheet1.GetRow(j + 5).GetCell(1).SetCellValue(ProjectId); sheet1.GetRow(j + 5).GetCell(2).SetCellValue(Str_Area); sheet1.GetRow(j + 5).GetCell(3).SetCellValue(Str_FX); sheet1.GetRow(j + 5).GetCell(4).SetCellValue(Str_Discipline); sheet1.GetRow(j + 5).GetCell(5).SetCellValue(ActivityName); sheet1.GetRow(j + 5).GetCell(6).SetCellValue(ReplaceNo); sheet1.GetRow(j + 5).GetCell(7).SetCellValue(ReplaceDesc); sheet1.GetRow(j + 5).GetCell(9).SetCellValue((temp_left_reqqty + temp_reserved_qty).ToString()); sheet1.GetRow(j + 5).GetCell(10).SetCellValue(unitname); sheet1.GetRow(j + 5).GetCell(8).SetCellValue(meo_no); sheet1.GetRow(j + 5).GetCell(12).SetCellValue(reqreason); sheet1.GetRow(j + 5).GetCell(17).SetCellValue(partno); sheet1.GetRow(j + 5).GetCell(15).SetCellValue(remark); sheet1.GetRow(j + 5).GetCell(16).SetCellValue(purpose); j++; } #endregion #region 替代码数量可以满足则跳出循环 else { replaceno = replaceno + ReplaceNo + ";"; string meo_no = GetPartMEONO(ReplaceNo, needqty.ToString()); sheet1.GetRow(j + 5).GetCell(0).SetCellValue(tt.ToString()); sheet1.GetRow(j + 5).GetCell(1).SetCellValue(ProjectId); sheet1.GetRow(j + 5).GetCell(2).SetCellValue(Str_Area); sheet1.GetRow(j + 5).GetCell(3).SetCellValue(Str_FX); sheet1.GetRow(j + 5).GetCell(4).SetCellValue(Str_Discipline); sheet1.GetRow(j + 5).GetCell(5).SetCellValue(ActivityName); sheet1.GetRow(j + 5).GetCell(6).SetCellValue(ReplaceNo); sheet1.GetRow(j + 5).GetCell(7).SetCellValue(ReplaceDesc); sheet1.GetRow(j + 5).GetCell(9).SetCellValue(needqty.ToString()); sheet1.GetRow(j + 5).GetCell(10).SetCellValue(unitname); sheet1.GetRow(j + 5).GetCell(8).SetCellValue(meo_no); sheet1.GetRow(j + 5).GetCell(12).SetCellValue(reqreason); sheet1.GetRow(j + 5).GetCell(17).SetCellValue(partno); sheet1.GetRow(j + 5).GetCell(15).SetCellValue(remark); sheet1.GetRow(j + 5).GetCell(16).SetCellValue(purpose); j++; needqty = 0; break; } #endregion } } } } #endregion } #endregion #region 如果本身库存以及申请数量足够 直接写入MEO号以及申请数量 else { needqty = 0; string meo_no = GetPartMEONO(partno, preQty); sheet1.GetRow(j + 5).GetCell(0).SetCellValue(tt.ToString()); sheet1.GetRow(j + 5).GetCell(1).SetCellValue(ProjectId); sheet1.GetRow(j + 5).GetCell(2).SetCellValue(Str_Area); sheet1.GetRow(j + 5).GetCell(3).SetCellValue(Str_FX); sheet1.GetRow(j + 5).GetCell(4).SetCellValue(Str_Discipline); sheet1.GetRow(j + 5).GetCell(5).SetCellValue(ActivityName); sheet1.GetRow(j + 5).GetCell(6).SetCellValue(partno); sheet1.GetRow(j + 5).GetCell(7).SetCellValue(partname); sheet1.GetRow(j + 5).GetCell(9).SetCellValue(preQty); sheet1.GetRow(j + 5).GetCell(10).SetCellValue(unitname); sheet1.GetRow(j + 5).GetCell(8).SetCellValue(meo_no); sheet1.GetRow(j + 5).GetCell(12).SetCellValue(reqreason); sheet1.GetRow(j + 5).GetCell(17).SetCellValue(replaceno); sheet1.GetRow(j + 5).GetCell(15).SetCellValue(remark); sheet1.GetRow(j + 5).GetCell(16).SetCellValue(purpose); j++; } #endregion } } #endregion //Force excel to recalculate all the formula while open sheet1.ForceFormulaRecalculation = true; //create cell on rows, since rows do already exist,it's not necessary to create rows again. //sheet1.GetRow(1).GetCell(1).SetCellValue(200200); //sheet1.GetRow(2).GetCell(1).SetCellValue(300); //sheet1.GetRow(3).GetCell(1).SetCellValue(500050); //sheet1.GetRow(4).GetCell(1).SetCellValue(8000); try { WriteToFile(appdir + "\\导出的标准MSS格式\\" + "标准MSSList.xls"); //WriteToFile(appdir + "\\导出的标准MSS格式\\" + "不足材料列表.xls"); //MessageBox.Show("导出的标准MSS格式MSSList.xls和不足材料列表" + "成功!", "提示消息"); } catch (Exception ex) { MessageBox.Show(ex.Message, "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error); } #region 足MSS的材料信息 InitializeWorkbook(@appdir + "Template\\不足项目MSS明细表.xls"); ISheet sheet2 = hssfworkbook.GetSheet("MSS明细表"); for (int i = 0; i < dgv1.RowCount; i++) { string partno = dgv1.Rows[i].Cells[4].Value.ToString(); if (!string.IsNullOrEmpty(partno)) { string partname, unitname; if (partno.Length < 7) { partno = "0" + partno; } InventoryPart invpartnew = InventoryPart.FindInvInfor(partno, Site); if (invpartnew != null) { partname = invpartnew.description; unitname = invpartnew.unit_meas; } else { MessageBox.Show("第" + i + "行ERP中无此材料编码"); return; } //DateTime reqdatestr = Convert.ToDateTime(dgv1.Rows[i].Cells["需求日期"].Value); string reqreason = "1001"; string preQty = dgv1.Rows[i].Cells[6].Value.ToString(); string purpose = dgv1.Rows[i].Cells["Column9"].Value.ToString(); string remark = dgv1.Rows[i].Cells["图纸号"].Value.ToString(); Str_Discipline = dgv1.Rows[i].Cells[3].Value.ToString(); string replaceno = ""; InventoryPart invpart = InventoryPart.GetRequiredqty(Site, partno, ProjectId); decimal left_reqqty = 0, reserved_qty = 0; if (invpart != null) { left_reqqty = Convert.ToDecimal(invpart.qty_reserved); reserved_qty = Convert.ToDecimal(invpart.qty_onhand) - Convert.ToDecimal(invpart.qty_issued); } decimal needqty = Convert.ToDecimal(preQty); if (Convert.ToDecimal(preQty) > left_reqqty + reserved_qty) { needqty = Convert.ToDecimal(preQty) - left_reqqty - reserved_qty; //decimal replaceqty = 0; DataSet ReplaceDS = Ration.QueryPartRationList("select replace_no from mm_part_standard_tab where part_no ='" + partno + "'"); if (ReplaceDS != null) { int p = ReplaceDS.Tables[0].Rows.Count; for (int k = 0; k < p; k++) { string ReplaceNo = ReplaceDS.Tables[0].Rows[k][0].ToString(); InventoryPart invparttemp = InventoryPart.GetRequiredqty(Site, ReplaceNo, ProjectId); decimal temp_left_reqqty = 0, temp_reserved_qty = 0; if (invparttemp != null) { temp_left_reqqty = Convert.ToDecimal(invparttemp.qty_reserved); temp_reserved_qty = Convert.ToDecimal(invparttemp.qty_onhand) - Convert.ToDecimal(invparttemp.qty_issued); if (temp_left_reqqty + temp_reserved_qty > 0) { if (Convert.ToDecimal(needqty) > temp_left_reqqty + temp_reserved_qty) { replaceno = replaceno + ReplaceNo + ";"; needqty = needqty - temp_left_reqqty - temp_reserved_qty; } else { replaceno = replaceno + ReplaceNo + ";"; needqty = 0; break; } } } } } //if (i + 5 > 10) // sheet1.CreateRow(i + 5); } else { needqty = 0; } if (needqty == 0) { } else { int tt = l + 1; sheet2.GetRow(l + 5).GetCell(0).SetCellValue(tt.ToString()); sheet2.GetRow(l + 5).GetCell(1).SetCellValue(ProjectId); sheet2.GetRow(l + 5).GetCell(2).SetCellValue(Str_Area); sheet2.GetRow(l + 5).GetCell(3).SetCellValue(Str_FX); sheet2.GetRow(l + 5).GetCell(4).SetCellValue(Str_Discipline); sheet2.GetRow(l + 5).GetCell(5).SetCellValue(ActivityName); sheet2.GetRow(l + 5).GetCell(6).SetCellValue(partno); sheet2.GetRow(l + 5).GetCell(7).SetCellValue(partname); sheet2.GetRow(l + 5).GetCell(9).SetCellValue(needqty.ToString()); sheet2.GetRow(l + 5).GetCell(10).SetCellValue(unitname); //sheet2.GetRow(j + 5).GetCell(11).SetCellValue(reqdate); sheet2.GetRow(l + 5).GetCell(12).SetCellValue(reqreason); //sheet2.GetRow(j + 5).GetCell(13).SetCellValue(reqreason); sheet2.GetRow(l + 5).GetCell(15).SetCellValue(remark); sheet2.GetRow(l + 5).GetCell(16).SetCellValue(purpose); //sheet1.GetRow(i + 5).GetCell(17).SetCellValue(replaceno); //if (i + 5 > 14) // sheet2.CreateRow(j + 6); l++; } } } sheet2.ForceFormulaRecalculation = true; #endregion try { //WriteToFile(appdir + "\\导出的标准MSS格式\\" + "标准MSSList.xls"); WriteToFile(appdir + "\\导出的标准MSS格式\\" + "不足材料列表.xls"); MessageBox.Show("导出的标准MSS格式MSSList.xls和不足材料列表" + "成功!", "提示消息"); System.Diagnostics.Process.Start("explorer.exe", appdir + "导出的标准MSS格式"); } catch (Exception ex) { MessageBox.Show(ex.Message, "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Converts the IntermediateInventoryPart into a list of InventoryParts /// </summary> /// <returns>A List of InventoryParts</returns> public List <InventoryPart> ToInventoryParts() { List <InventoryPart> parts = new List <InventoryPart>(); try { //find availablepart AvailablePart aPart = PartLoader.LoadedPartsList.Find(aP => aP.name == PartName); if (aPart == null) { LoggingUtil.LogError(this, $"No AvailablePart found with name '{PartName}'"); return(parts); } //copy the part out Part prefab = copyPart(aPart); //generate an InventoryPart confignode ConfigNode iConfig = new ConfigNode("ScrapYard.InventoryPart"); iConfig.AddValue("_name", PartName); iConfig.AddValue("_id", 0); iConfig.AddValue("_timesRecovered", TimesRecovered); iConfig.AddValue("_inventoried", true); if (ModulesNode != null && ModulesNode.CountNodes > 0) { foreach (ConfigNode module in ModulesNode.GetNodes("MODULE")) { string modName = module.GetValue("name"); //replace module if exists, otherwise add it if (prefab.Modules?.Count > 0) { //look for this module on the partInfo and replace it if (prefab.Modules.Contains(modName)) { prefab.Modules[modName].Load(module); } else { LoggingUtil.LogError(this, $"Prefab didn't have module: {modName}"); } } iConfig.AddNode(module); } } //find the dry cost float dryCost = 0; dryCost = prefab.GetModuleCosts(aPart.cost) + aPart.cost; foreach (PartResource resource in prefab.Resources) { dryCost -= (float)(resource.maxAmount * PartResourceLibrary.Instance.GetDefinition(resource.resourceName).unitCost); } //set the dry cost iConfig.AddValue("_dryCost", dryCost); //create the parts for (int i = 0; i < Count; i++) { InventoryPart iPart = new InventoryPart(); iPart.State = iConfig; //and add it parts.Add(iPart); } } catch (Exception ex) { LoggingUtil.LogException(ex); } return(parts); }
/// <summary> /// Verifies that the inventory parts on the ship in the editor are valid /// </summary> public static void VerifyEditorShip() { //make a copy of the inventory PartInventory copy; using (Logging.Timer.StartNew("Copy")) { copy = ScrapYard.Instance.TheInventory.Copy(); } using (Logging.Timer.StartNew("Check Parts")) { long constTime = 0; long removeTime = 0; long findTime = 0; //long freshTime = 0; //foreach (Part part in EditorLogic.fetch?.ship?.Parts ?? new List<Part>()) List <InventoryPart> editorParts = null; using (Logging.Timer.StartNew("Convert To IParts")) { editorParts = EditorLogic.fetch?.ship?.Parts?.Select(p => new InventoryPart(p))?.ToList(); } if (editorParts != null) { for (int i = 0; i < editorParts.Count; i++) { Stopwatch constWatch = Stopwatch.StartNew(); InventoryPart iPart = editorParts[i];//new InventoryPart(part); constTime += constWatch.ElapsedMilliseconds; //Stopwatch freshWatch = Stopwatch.StartNew(); //if (iPart.ID == null) //{ // (EditorLogic.fetch.ship.Parts[i].Modules["ModuleSYPartTracker"] as ModuleSYPartTracker).MakeFresh(); //} //freshTime += freshWatch.ElapsedMilliseconds; if (iPart.TrackerModule.Inventoried) { Stopwatch remWatch = Stopwatch.StartNew(); InventoryPart inInventory = copy.RemovePart(iPart, ComparisonStrength.STRICT); //strict, we only remove parts that are exact if (inInventory == null) { //reset their tracker status Logging.Log($"Found inventory part on vessel that is not in inventory. Resetting. {iPart.Name}:{iPart.ID}"); (EditorLogic.fetch.ship.Parts[i].Modules["ModuleSYPartTracker"] as ModuleSYPartTracker).MakeFresh(); } removeTime += remWatch.ElapsedMilliseconds; } else { //check that we're not sharing an ID with something in the inventory Stopwatch findWatch = Stopwatch.StartNew(); InventoryPart inInventory = copy.FindPart(iPart.ID); if (inInventory != null) { //found a part that is sharing an ID but shouldn't be Logging.Log($"Found part on vessel with same ID as inventory part, but not matching. Resetting. {iPart.Name}:{iPart.ID}"); (EditorLogic.fetch.ship.Parts[i].Modules["ModuleSYPartTracker"] as ModuleSYPartTracker).MakeFresh(); } findTime += findWatch.ElapsedMilliseconds; } } } Logging.DebugLog($"Constructor: {constTime}"); Logging.DebugLog($"Removal: {removeTime}"); Logging.DebugLog($"Finding: {findTime}"); //Logging.Log($"Freshening: {freshTime}"); } using (Logging.Timer.StartNew("Update Part List")) { //update the part list if visible if (ScrapYard.Instance.InstanceSelectorUI.IsVisible) { ScrapYard.Instance.InstanceSelectorUI.InstanceVM?.UpdatePartList(); } } }
public void CheckImportData() { #region 首先检查要导入的Excel数据中ERP代码是否在ERP系统中存在 string txtfilename = System.Windows.Forms.Application.StartupPath + "\\错误信息.txt"; StreamWriter sw = new StreamWriter(txtfilename, false, Encoding.GetEncoding("gb2312")); int flag = 0; try { for (int i = 0; i < dgv2.Rows.Count - 1; i++) { string partno = dgv2.Rows[i].Cells[4].Value.ToString(); if (!string.IsNullOrEmpty(partno)) { InventoryPart invpartnew = InventoryPart.FindInvInfor(partno, mSite); if (invpartnew == null) { System.Diagnostics.Trace.WriteLine("第" + (i + 1) + "行材料编码 " + partno + " 在ERP中所选择域无此材料编码,请联系ERP操作员,在ERP中添加。"); sw.WriteLine("第" + (i + 1) + "行材料编码 " + partno + " 在ERP中所选择域无此材料编码,请联系ERP操作员,在ERP中添加。", "温馨提示"); flag = 1; } } else { System.Diagnostics.Trace.WriteLine("第" + (i + 1) + "行材料编码 " + partno + " 在没有填写,在ERP中添加活查询后填写。"); sw.WriteLine("第" + (i + 1) + "行材料编码 " + partno + " 在没有填写,在ERP中添加活查询后填写。", "温馨提示"); flag = 1; } if (!string.IsNullOrEmpty(dgv2.Rows[i].Cells[6].Value.ToString())) { string rqty = dgv2.Rows[i].Cells[6].Value.ToString(); if (BaseClass.validateNum(rqty) == false) { System.Diagnostics.Trace.WriteLine("请确认第" + (i + 1) + "行" + partno + " 预估数量输入数字!!!"); sw.WriteLine("请确认第" + (i + 1) + "行" + partno + " 预估数量输入数字!!!", "温馨提示"); flag = 1; } } if (!string.IsNullOrEmpty(dgv2.Rows[i].Cells[7].Value.ToString())) { string rqty = dgv2.Rows[i].Cells[7].Value.ToString(); if (BaseClass.validateNum(rqty) == false) { System.Diagnostics.Trace.WriteLine("请确认第" + (i + 1) + "行 " + partno + " 第一批生产需求数量输入数字!!!"); sw.WriteLine("请确认第" + (i + 1) + "行 " + partno + " 第一批生产需求数量输入数字!!!", "温馨提示"); flag = 1; } } else { System.Diagnostics.Trace.WriteLine("请确认第" + (i + 1) + "行 " + partno + " 第一批生产需求数量没有输入数字!!!"); sw.WriteLine("请确认第" + (i + 1) + "行 " + partno + " 第一批生产需求数量没有输入数字!!!", "温馨提示"); flag = 1; } if (!string.IsNullOrEmpty(dgv2.Rows[i].Cells[9].Value.ToString())) { string rqty = dgv2.Rows[i].Cells[9].Value.ToString(); if (BaseClass.validateNum(rqty) == false) { System.Diagnostics.Trace.WriteLine("请确认第" + (i + 1) + "行 " + partno + " 第一批生产需求数量输入数字!!!"); sw.WriteLine("请确认第" + (i + 1) + "行 " + partno + " 第一批生产需求数量输入数字!!!", "温馨提示"); flag = 1; } } else { System.Diagnostics.Trace.WriteLine("请确认第" + (i + 1) + "行 " + partno + " 第二批生产需求数量没有输入数字!!!"); sw.WriteLine("请确认第" + (i + 1) + "行 " + partno + " 第二批生产需求数量没有输入数字!!!", "温馨提示"); flag = 1; } } if (flag == 1) { sw.Close(); MessageBox.Show("要导入的预估文件数据有误,请检查!"); System.Diagnostics.Process.Start("explorer.exe", txtfilename); return; } #endregion DialogResult dgresult = MessageBox.Show("确定要将预估结果进行导入吗?", "操作确认", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dgresult == DialogResult.No) { return; } #region 首先将上次的预估结果保存为历史记录(按照预估人,专业,区域进行覆盖) PartParameter.DeleteEstimate(mSite, ProjectId, DisciplineId); #endregion ImportDataHanlder ImportData = new ImportDataHanlder(ImportParaData); ImportData.BeginInvoke(null, null); } catch (Exception et) { MessageBox.Show(et.Message); } finally { MessageBox.Show("预估数据导入成功!!!", "操作提示"); } }
private void OnSYInventoryChanged(InventoryPart data0, bool data1) { willFail = false; chanceOfFailure = baseChanceOfFailure; Initialise(); }
void Invento() { InventoryPart.SetActive(true); InvOpn = true; RightFinger.SetActive(false); }
public static void Download(int num, string name) { var source = "http://fcds.cs.put.poznan.pl/MyWeb/BL/" + num.ToString() + ".xml"; var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), num + ".xml"); var client = new WebClient(); client.DownloadFile(source, path); string line; var file = new StreamReader(path); InventoryPart part = new InventoryPart(); Inventory inv = new Inventory(num, name, 1, 0); db.Insert(inv); int idx = num; while ((line = file.ReadLine()) != null) { idx++; char[] charsToTrim = { '*', ' ', '\'' }; line = line.Trim(charsToTrim); var mylist = line.Split(">"); switch (mylist[0]) { case "<ITEM": part = new InventoryPart(); part.Id = idx; break; case "<ITEMTYPE": var type = mylist[1].Split("<")[0]; part.TypeID = 0; //int.Parse(type); W bazie na Pana stronie yo ma być integer, ale w xmlach są chary break; case "<QTY": var quantity = mylist[1].Split("<")[0]; part.QuantityInSet = int.Parse(quantity); break; case "<ITEMID": var itemid = mylist[1].Split("<")[0]; int test; if (int.TryParse(itemid, out test)) { part.ItemID = test; } else { part.ItemID = itemid.Length; } break; case "<COLOR": var color = mylist[1].Split("<")[0]; part.ColorID = int.Parse(color); break; case "<EXTRA": if (mylist[1][1] == 'N') { part.Extra = 0; } else { part.Extra = 1; } break; case "</ITEM": part.InventoryID = num; db.Insert(part); break; default: break; } } }
public InstanceModulesVM(InventoryPart part) { _backingPart = part; }