using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using util = FCOMMON.Util; namespace FPJ0000 { public partial class fPartList : FCOMMON.fBase { string fn_fpcolsize = ""; int ProjectIndex = -1; int colidx_itemname = -1; int colidx_item = -1; int colidx_qty = -1; int colidx_amt = -1; int colidx_price = -1; int colidx_model = -1; int colidx_supply = -1; int colidx_supplyidx = -1; int colidx_sid = -1; public fPartList(int idx_) { InitializeComponent(); fn_fpcolsize = util.MakeFilePath(util.CurrentPath, "formSetting", "fp_" + this.Name + ".ini"); this.ProjectIndex = idx_; this.FormClosed += fPartList_FormClosed; this.KeyPreview = true; this.KeyDown += fPartList_KeyDown; this.dsPRJ.ProjectsPart.TableNewRow += ProjectsPart_TableNewRow; } void ProjectsPart_TableNewRow(object sender, DataTableNewRowEventArgs e) { e.Row["wuid"] = FCOMMON.info.Login.no; e.Row["wdate"] = DateTime.Now; e.Row["Project"] = this.ProjectIndex; } void fPartList_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Escape) this.Close(); } void fPartList_FormClosed(object sender, FormClosedEventArgs e) { } private void fPartList_Load(object sender, EventArgs e) { //열번호찾기 foreach(FarPoint.Win.Spread.Column col in this.fpSpread1.ActiveSheet.Columns) { string colname = col.DataField.ToLower(); if (colname == "itemmodel") colidx_model = col.Index; else if (colname == "itemname") colidx_itemname = col.Index; else if (colname == "item") colidx_item = col.Index; else if (colname == "qty") colidx_qty = col.Index; else if (colname == "price") colidx_price = col.Index; else if (colname == "amt") colidx_amt = col.Index; else if (colname == "supplyidx") colidx_supplyidx = col.Index; else if (col.Label.ToLower() == "supply") colidx_supply = col.Index; else if (col.Label.ToLower() == "sid") colidx_sid = col.Index; } this.Show(); Application.DoEvents(); RefreshData(); FPUtil.ColSizeLoad(ref this.fpSpread1, fn_fpcolsize); } void RefreshData() { if(dsPRJ.HasChanges()) { var dlg = FCOMMON.Util.MsgQ("변경 사항이 있습니다. 갱신하면 변경 내용이 손실 됩니다.\n지금 갱신 하겠습니까?"); if (dlg != System.Windows.Forms.DialogResult.Yes) return; } try { this.ta.FillByIDX(this.dsPRJ.Projects, this.ProjectIndex); this.taPart.Fill(this.dsPRJ.ProjectsPart, this.ProjectIndex); } catch (Exception ex) { FCOMMON.Util.MsgE(ex.Message); } //로딩후에 sid 와 suuply 를 조회해준다. //foreach (dsPRJ.ProjectsPartRow dr in this.dsPRJ.ProjectsPart.Rows) //{ // if (dr.IsItemNull() || dr.Item < 0) continue; // var iteminfo = FCOMMON.DBM.getItemInfo(dr.Item); // if (iteminfo.idx != -1) // { // dr.SID = iteminfo.sid; // //dr.Supply = iteminfo.supply; // } //} //this.dsPRJ.AcceptChanges(); RefreshSum(); } void RefreshSum() { decimal sum = 0; foreach (dsPRJ.ProjectsPartRow dr in this.dsPRJ.ProjectsPart.Rows) { if (dr.RowState == DataRowState.Deleted || dr.RowState == DataRowState.Detached) continue; sum += dr.amt; } lbSum.Text = sum.ToString("N0"); } private void toolStripButton1_Click(object sender, EventArgs e) { this.Validate(); this.bs.EndEdit(); this.bsPart.EndEdit(); try { var cnt = this.tam.UpdateAll(this.dsPRJ); FCOMMON.Util.MsgI(cnt.ToString() + "건의 자료가 업데이트 되었습니다."); this.dsPRJ.AcceptChanges(); } catch (Exception ex) { FCOMMON.Util.MsgE(ex.Message); } } private void toolStripButton2_Click(object sender, EventArgs e) { var f = new rPartList(this.ProjectIndex); f.Show(); } private void exportListToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog sd = new SaveFileDialog(); sd.Filter = "excel|*.xls"; if(sd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { fpSpread1.SaveExcel(sd.FileName, FarPoint.Excel.ExcelSaveFlags.SaveAsViewed | FarPoint.Excel.ExcelSaveFlags.NoFormulas | FarPoint.Excel.ExcelSaveFlags.SaveCustomColumnHeaders ); } //dv1.ExportData("partlist.csv"); } private void autoToolStripMenuItem_Click(object sender, EventArgs e) { this.fpSpread1.ActiveSheet.DataAutoSizeColumns = true; for (int i = 0; i < this.fpSpread1.ActiveSheet.Rows.Count; i++) this.fpSpread1.ActiveSheet.SetRowHeight(i, 25); //dv1.AutoResizeColumns(); } private void resetToolStripMenuItem_Click(object sender, EventArgs e) { foreach (FarPoint.Win.Spread.Column col in this.fpSpread1.ActiveSheet.Columns) { col.Width = 100; } } private void saveToolStripMenuItem_Click(object sender, EventArgs e) { FPUtil.ColsizeSave(this.fpSpread1, fn_fpcolsize); } private void loadToolStripMenuItem_Click(object sender, EventArgs e) { FPUtil.ColSizeLoad(ref this.fpSpread1, fn_fpcolsize); } private void fpSpread1_EditModeOff(object sender, EventArgs e) { int Colidx = this.fpSpread1.ActiveSheet.ActiveColumnIndex; int Rowidx = this.fpSpread1.ActiveSheet.ActiveRowIndex; var taItem = new FCM0000.dsMSSQLTableAdapters.ItemsTableAdapter(); switch (this.fpSpread1.ActiveSheet.Columns[Colidx].DataField.ToLower()) { case "supplyname": var valuen1 = fpSpread1.ActiveSheet.Cells[Rowidx, Colidx].Value;//.Rows[Rowidx].Cells[e.ColumnIndex].Value; if (valuen1 != null) { string inputtext1 = valuen1.ToString().Trim(); if (inputtext1 != "") { FCM0000.fLovSupply f = new FCM0000.fLovSupply(inputtext1); if(f.ShowDialog() == System.Windows.Forms.DialogResult.OK) { fpSpread1.ActiveSheet.Cells[Rowidx, colidx_supply].Value = f.Title; fpSpread1.ActiveSheet.Cells[Rowidx, colidx_supplyidx].Value = f.Index; } else { //fpSpread1.ActiveSheet.Cells[Rowidx, colidx_supply].Value = string.Empty; fpSpread1.ActiveSheet.Cells[Rowidx, colidx_supplyidx].Value = -1; } } } break; case "itemname": var valuen = fpSpread1.ActiveSheet.Cells[Rowidx, Colidx].Value;//.Rows[Rowidx].Cells[e.ColumnIndex].Value; if (valuen != null) { string inputtext = valuen.ToString().Trim(); if (inputtext != "") { //검색을 실행해서 보여준다. var SearchDT = taItem.GetSearch("%" + inputtext + "%"); if (SearchDT == null || SearchDT.Rows.Count < 1) { //FCOMMON.Util.MsgE("검색 결과가 없습니다."); fpSpread1.ActiveSheet.ActiveColumnIndex += 2; return; } else { //검색된 결과를 표시해서 보여준다. var f = new FCM0000.fLovItem("%" + inputtext + "%"); if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK) { //var c = fpSpread1.ActiveSheet.Columns["sdf"]; fpSpread1.ActiveSheet.Cells[Rowidx, colidx_item].Value = f.item; fpSpread1.ActiveSheet.Cells[Rowidx, colidx_itemname].Value = f.itemName; fpSpread1.ActiveSheet.Cells[Rowidx, colidx_sid].Value = f.SID; fpSpread1.ActiveSheet.Cells[Rowidx, colidx_supplyidx].Value = f.itemSupplyidx; fpSpread1.ActiveSheet.Cells[Rowidx, colidx_supply].Value = f.itemSupply; if (f.itemmodel != "") fpSpread1.ActiveSheet.Cells[Rowidx, colidx_model].Value = f.itemmodel; if (f.itemprice != 0) fpSpread1.ActiveSheet.Cells[Rowidx, colidx_price].Value = f.itemprice; var valueq1 = fpSpread1.ActiveSheet.Cells[Rowidx, colidx_qty].Value; var valuep1 = fpSpread1.ActiveSheet.Cells[Rowidx, colidx_price].Value; Int32 iQty = 0; decimal iPrice = 0; if (valueq1 != null && valueq1.ToString() != "") iQty = (Int32)valueq1; if (valuep1 != null && valuep1.ToString() != "") iPrice = (decimal)valuep1; decimal iAmt = iQty * iPrice; fpSpread1.ActiveSheet.Cells[Rowidx, colidx_amt].Value = iAmt; } } } } break; case "price": case "qty": var valueq = fpSpread1.ActiveSheet.Cells[Rowidx, colidx_qty].Value; var valuep = fpSpread1.ActiveSheet.Cells[Rowidx, colidx_price].Value; Int32 iQty1 = 0; decimal iPrice1 = 0; if (valueq != null && valueq.ToString() != "") iQty1 = (Int32)valueq; if (valuep != null && valuep.ToString() != "") iPrice1 = (decimal)valuep; var amt = iQty1 * iPrice1; fpSpread1.ActiveSheet.Cells[Rowidx, colidx_amt].Value = amt; //dv1.Rows[e.RowIndex].Cells["dvc_amt"].Value = amt; RefreshSum(); break; } } private void btRefresh_Click(object sender, EventArgs e) { RefreshData(); } private void toolStripButton3_Click(object sender, EventArgs e) { var f = new fProjectPartImport(ProjectIndex); f.ShowDialog(); this.RefreshData(); } private void toolStripButton4_Click(object sender, EventArgs e) { var f = new fProjectPartToPurchase(ProjectIndex); f.ShowDialog(); } } }