246 lines
		
	
	
		
			9.3 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			246 lines
		
	
	
		
			9.3 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| 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;
 | |
| 
 | |
| namespace FPJ0000
 | |
| {
 | |
|     public partial class fPartList : Form
 | |
|     {
 | |
|         int ProjectIndex = -1;
 | |
|         public fPartList(int idx_)
 | |
|         {
 | |
|             InitializeComponent();
 | |
|             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)
 | |
|         {
 | |
|             var form = this as Form;
 | |
|             FCOMMON.Util.SetFormStatus(ref form, this.Name, false);
 | |
|         }
 | |
| 
 | |
|         private void fPartList_Load(object sender, EventArgs e)
 | |
|         {
 | |
| 
 | |
|             var form = this as Form;
 | |
|             FCOMMON.Util.SetFormStatus(ref form, this.Name, true);
 | |
|             this.Show();
 | |
|             Application.DoEvents();
 | |
|             RefreshData();
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
|         }
 | |
|         void RefreshData()
 | |
|         {
 | |
|             this.ta.FillByIDX(this.dsPRJ.Projects, this.ProjectIndex);
 | |
|             this.taPart.Fill(this.dsPRJ.ProjectsPart, this.ProjectIndex);
 | |
| 
 | |
|             //로딩후에 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();
 | |
|             this.dv1.AutoResizeColumns();
 | |
|             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() + "건의 자료가 업데이트 되었습니다.");
 | |
|             }
 | |
|             catch (Exception ex)
 | |
|             {
 | |
|                 FCOMMON.Util.MsgE(ex.Message);
 | |
|             }
 | |
| 
 | |
|         }
 | |
| 
 | |
|         private void toolStripButton2_Click(object sender, EventArgs e)
 | |
|         {
 | |
|             var f = new fRPartList(this.ProjectIndex);
 | |
|             f.Show();
 | |
|         }
 | |
| 
 | |
|         private void dv1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
 | |
|         {
 | |
|             if (e.ColumnIndex < 0 || e.RowIndex < 0) return;
 | |
|             var col = dv1.Columns[e.ColumnIndex];
 | |
|             var taItem = new FCM0000.dsMSSQLTableAdapters.ItemsTableAdapter();
 | |
|             switch (col.DataPropertyName)
 | |
|             {
 | |
|                 case "ItemName":
 | |
|                     var valuen = dv1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
 | |
|                     if (valuen != null)
 | |
|                     {
 | |
|                         string inputtext = valuen.ToString().Trim();
 | |
|                         if (inputtext == "")
 | |
|                         {
 | |
|                             dv1.Rows[e.RowIndex].Cells["dvc_itemName"].Value = inputtext;
 | |
|                         }
 | |
|                         else
 | |
|                         {
 | |
|                             //검색을 실행해서 보여준다.
 | |
| 
 | |
|                             var SearchDT = taItem.GetSearch("%" + inputtext + "%");
 | |
|                             if (SearchDT == null || SearchDT.Rows.Count < 1)
 | |
|                             {
 | |
|                                 //FCOMMON.Util.MsgE("검색 결과가 없습니다.");
 | |
|                                 return;
 | |
|                             }
 | |
|                             else
 | |
|                             {
 | |
|                                 //검색된 결과를 표시해서 보여준다.
 | |
|                                 var f = new FCM0000.fLovItem("%" + inputtext + "%");
 | |
|                                 if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK)
 | |
|                                 {
 | |
|                                     dv1.Rows[e.RowIndex].Cells["dvc_item"].Value = f.item;
 | |
|                                     dv1.Rows[e.RowIndex].Cells["dvc_itemname"].Value = f.itemName;
 | |
| 
 | |
|                                     dv1.Rows[e.RowIndex].Cells["dvc_sid"].Value = f.SID;
 | |
|                                     dv1.Rows[e.RowIndex].Cells["dvc_supply"].Value = f.itemSupply;
 | |
| 
 | |
|                                     if(f.itemmodel != "")
 | |
|                                         dv1.Rows[e.RowIndex].Cells["dvc_model"].Value = f.itemmodel;
 | |
| 
 | |
|                                     if(f.itemprice != 0)
 | |
|                                         dv1.Rows[e.RowIndex].Cells["dvc_price"].Value = f.itemprice;
 | |
| 
 | |
|                                     var valueq1 = dv1.Rows[e.RowIndex].Cells["dvc_qty"].Value;
 | |
|                                     var valuep1 = dv1.Rows[e.RowIndex].Cells["dvc_price"].Value;
 | |
| 
 | |
|                                     Int32 iQty = 0;
 | |
|                                     decimal iPrice = 0;
 | |
|                                     if (valueq1 != null) iQty = (Int32)valueq1;
 | |
|                                     if (valuep1 != null) iPrice = (decimal)valuep1;
 | |
|                                     decimal iAmt = iQty * iPrice;
 | |
|                                     dv1.Rows[e.RowIndex].Cells["dvc_amt"].Value = iAmt;
 | |
|                                 }
 | |
|                             }
 | |
|                         }
 | |
|                     }
 | |
|                     break;
 | |
|                 case "item":
 | |
|                     var value = dv1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
 | |
|                     if (value != null)
 | |
|                     {
 | |
|                         int idx = (int)value;
 | |
|                         if (idx != -1)
 | |
|                         {
 | |
|                             var item = taItem.GetIDX(idx);
 | |
|                             if (item.Count == 1)
 | |
|                             {
 | |
|                                 //1개만 찾았다면 그것을 사용한다.
 | |
|                                 var itemnameValue = item[0]["name"];
 | |
|                                 var itemmodel = item[0]["model"];
 | |
|                                 var itemprice = item[0]["price"];
 | |
| 
 | |
|                                 var itemSID = item[0]["sid"];
 | |
|                                 var itemSupply = item[0]["supply"];
 | |
| 
 | |
|                                 if (itemprice != null)
 | |
|                                 {
 | |
|                                     var price = (decimal)itemprice;
 | |
|                                     if(price != 0)
 | |
|                                         dv1.Rows[e.RowIndex].Cells["dvc_price"].Value = (decimal)itemprice;
 | |
|                                 }
 | |
|                                     
 | |
| 
 | |
|                                 if (itemnameValue != null)
 | |
|                                     dv1.Rows[e.RowIndex].Cells["dvc_itemname"].Value = itemnameValue.ToString();
 | |
| 
 | |
|                                 if (itemmodel != null)
 | |
|                                     dv1.Rows[e.RowIndex].Cells["dvc_model"].Value = itemmodel.ToString();
 | |
| 
 | |
|                                 if (itemSID != null)
 | |
|                                     dv1.Rows[e.RowIndex].Cells["dvc_sid"].Value = itemSID.ToString();
 | |
| 
 | |
|                                 if (itemSupply != null)
 | |
|                                     dv1.Rows[e.RowIndex].Cells["dvc_supply"].Value = itemSupply.ToString();
 | |
| 
 | |
| 
 | |
|                             }
 | |
|                             else
 | |
|                             {
 | |
|                                 FCOMMON.Util.MsgE("해당 아이템이 존재하지 않습니다.");
 | |
|                                 dv1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = DBNull.Value;
 | |
|                             }
 | |
|                         }
 | |
|                     }
 | |
|                     break;
 | |
|                 case "price":
 | |
|                 case "qty":
 | |
|                     var valueq = dv1.Rows[e.RowIndex].Cells["dvc_qty"].Value;
 | |
|                     var valuep = dv1.Rows[e.RowIndex].Cells["dvc_price"].Value;
 | |
|                     var amt = (Int32)valueq * (decimal)valuep;
 | |
|                     dv1.Rows[e.RowIndex].Cells["dvc_amt"].Value = amt;
 | |
|                     RefreshSum();
 | |
|                     break;
 | |
|                
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         private void autoSizeColumnToolStripMenuItem_Click(object sender, EventArgs e)
 | |
|         {
 | |
|             dv1.AutoResizeColumns();
 | |
|         }
 | |
| 
 | |
|         private void exportListToolStripMenuItem_Click(object sender, EventArgs e)
 | |
|         {
 | |
|             dv1.ExportData("partlist.csv");
 | |
|         }
 | |
| 
 | |
|         private void dv1_DataError(object sender, DataGridViewDataErrorEventArgs e)
 | |
|         {
 | |
| 
 | |
|         }
 | |
|     }
 | |
| }
 | 
