277 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			277 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using FCOMMON;
 | |
| 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 fProjectPartImport : fBase
 | |
|     {
 | |
|         int ProjectIndex = -1;
 | |
|         public fProjectPartImport(int pidx_)
 | |
|         {
 | |
|             InitializeComponent();
 | |
|             this.ProjectIndex = pidx_;
 | |
|             this.FormClosed += __Closed;
 | |
| 
 | |
|             var taPrj = new dsPRJTableAdapters.ProjectsTableAdapter();
 | |
|             var dt = taPrj.GetbyIDX(pidx_);
 | |
|             if (dt.Rows.Count < 1)
 | |
|             {
 | |
|                 btView.Enabled = false;
 | |
|                 this.Text = "파트리스트 가져오기( 프로젝트 데이터 없음 )";
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 var dr = dt.Rows[0] as dsPRJ.ProjectsRow;
 | |
|                 this.Text = "파트리스트 가져오기(" + dr.name + ")";
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         private void __Load(object sender, EventArgs e)
 | |
|         {
 | |
|             EnsureVisibleAndUsableSize();
 | |
|         }
 | |
| 
 | |
|         void __Closed(object sender, FormClosedEventArgs e)
 | |
|         {
 | |
| 
 | |
|         }
 | |
| 
 | |
|         private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 | |
|         {
 | |
|             OpenFileDialog od = new OpenFileDialog();
 | |
|             od.Filter = "excel|*.xlsx|all files|*.*";
 | |
|             od.RestoreDirectory = true;
 | |
|             od.FilterIndex = 1;
 | |
|             od.RestoreDirectory = true;
 | |
|             if (od.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;
 | |
|             textBox1.Text = od.FileName;
 | |
|         }
 | |
| 
 | |
|         private void button1_Click(object sender, EventArgs e)
 | |
|         {
 | |
| 
 | |
|             if (textBox1.Text == "")
 | |
|             {
 | |
|                 FCOMMON.Util.MsgE("파일을 선택하세요");
 | |
|                 textBox1.Focus();
 | |
|                 return;
 | |
|             }
 | |
|             if (!System.IO.File.Exists(textBox1.Text))
 | |
|             {
 | |
|                 FCOMMON.Util.MsgE("입력하신 파일이 존재하지 않습니다.");
 | |
|                 textBox1.Focus();
 | |
|                 textBox1.SelectAll();
 | |
|                 return;
 | |
|             }
 | |
| 
 | |
|             this.dsPRJ.ProjectsPart.Clear();
 | |
|             this.dsPRJ.ProjectsPart.AcceptChanges();
 | |
| 
 | |
|             libxl.Book book;// = new libxl.BinBook();
 | |
|             book = new libxl.XmlBook();
 | |
|             book.setKey(FCOMMON.info.libxlCompany, FCOMMON.info.libxlKey);
 | |
|             try
 | |
|             {
 | |
|                 book.load(textBox1.Text);
 | |
|             }
 | |
|             catch (Exception ex)
 | |
|             {
 | |
|                 FCOMMON.Util.MsgE(ex.Message);
 | |
|                 return;
 | |
|             }
 | |
| 
 | |
|             int sheetNum = (int)numericUpDown1.Value;
 | |
|             if (sheetNum > book.sheetCount())
 | |
|             {
 | |
|                 FCOMMON.Util.MsgE("입력한 시트 번호는 존재하지 않습니다.");
 | |
|                 book = null;
 | |
|                 return;
 | |
|             }
 | |
|             var sheet = book.getSheet(sheetNum - 1);
 | |
|             var MaxRow = sheet.lastRow();
 | |
|             var MinRow = sheet.firstRow();
 | |
| 
 | |
|             MaxRow = (int)Math.Min(MaxRow, nudE.Value - 1);
 | |
|             MinRow = (int)Math.Max(MinRow, nudS.Value - 1);
 | |
| 
 | |
| 
 | |
|             string no = "";
 | |
|             string SID = "";
 | |
|             string 품명 = "";
 | |
|             string 규격 = "";
 | |
|             string 단가 = "";
 | |
|             string 수량1 = "";
 | |
|             string 수량N = "";
 | |
|             string 단위 = "";
 | |
|             string 제조사 = "";
 | |
|             string 공급사 = "";
 | |
|             //string 그룹 = "";
 | |
|             string 비고 = "";
 | |
|             string 소분류 = "";
 | |
|             string 납기일 = "";
 | |
|             string 중분류 = "";
 | |
|           
 | |
| 
 | |
|             this.progressBar1.Value = 0;
 | |
|             this.progressBar1.Maximum = MaxRow - MinRow + 1;
 | |
|             this.dataGridView1.Visible = false;
 | |
|             decimal sumamt = 0;
 | |
|             try
 | |
|             {
 | |
|                 for (int r = MinRow; r <= MaxRow; r++)
 | |
|                 {
 | |
|                     progressBar1.Value += 1;
 | |
| 
 | |
|                     //필수값을 먼저 확인한다.
 | |
|                     if (nudNo.Value > 0) no = sheet.readStr(r, (int)nudNo.Value - 1).Trim();
 | |
|                     if (nudSid.Value > 0) SID = sheet.readStr(r, (int)nudSid.Value - 1).Trim();
 | |
|                     if (nudName.Value > 0) 품명 = sheet.readStr(r, (int)this.nudName.Value - 1).Trim();
 | |
|                     if (nudModel.Value > 0) 규격 = sheet.readStr(r, (int)this.nudModel.Value - 1).Trim();
 | |
|                     if (nudPrice.Value > 0) 단가 = sheet.readStr(r, (int)this.nudPrice.Value - 1).Replace(",", "").Trim();
 | |
|                     if (nudQty.Value > 0) 수량1 = sheet.readStr(r, (int)nudQty.Value - 1).Replace(",", "").Trim();
 | |
|                     if (nudQtyN.Value > 0) 수량N = sheet.readStr(r, (int)nudQtyN.Value - 1).Replace(",", "").Trim();
 | |
| 
 | |
|                     if (nudUnit.Value > 0) 단위 = sheet.readStr(r, (int)nudUnit.Value - 1).Trim();
 | |
|                     if (nudManu.Value > 0) 제조사 = sheet.readStr(r, (int)nudManu.Value - 1).Trim();
 | |
|                     if (nudSupply.Value > 0) 공급사 = sheet.readStr(r, (int)nudSupply.Value - 1).Trim();
 | |
|                     //if (nudGrp.Value > 0) 그룹 = sheet.readStr(r, (int)nudGrp.Value - 1).Trim();
 | |
|                     if (nudMemo.Value > 0) 비고 = sheet.readStr(r, (int)nudMemo.Value - 1).Trim();
 | |
|                     if (nudLowDiv.Value > 0) 소분류 = sheet.readStr(r, (int)nudLowDiv.Value - 1).Trim();
 | |
|                     if (nudNapKi.Value > 0) 납기일 = sheet.readStr(r, (int)nudNapKi.Value - 1).Trim();
 | |
|                     if (nudMidDiv.Value > 0) 중분류 = sheet.readStr(r, (int)nudMidDiv.Value - 1).Trim();
 | |
| 
 | |
|                     //sid 공백과 - _ 제거  200506
 | |
|                     SID = SID.Replace(" ", "").Replace("-", "").Replace("_", "").Trim();
 | |
| 
 | |
|                     //필수자료갸ㅏ 없는 경우처리하지 않음
 | |
|                     if (품명.Trim() == "") continue;
 | |
| 
 | |
|                     var newdr = this.dsPRJ.ProjectsPart.NewProjectsPartRow();
 | |
|                     newdr.wuid = FCOMMON.info.Login.no;
 | |
|                     newdr.wdate = DateTime.Now;
 | |
|                     newdr.import = true;
 | |
|                     newdr.Project = this.ProjectIndex;
 | |
| 
 | |
|                     if (no != "") newdr.no = int.Parse(no);
 | |
|                     newdr.ItemSid = SID;
 | |
|                     newdr.ItemName = 품명;
 | |
|                     newdr.ItemModel = 규격;
 | |
|                     if (단가 != "") newdr.price = decimal.Parse(단가);
 | |
|                     if (수량1 != "") newdr.qty = int.Parse(수량1);
 | |
|                     if (수량N != "") newdr.qtyn = int.Parse(수량N);
 | |
|                     newdr.amt = newdr.price * newdr.qty;
 | |
|                     newdr.amtn = newdr.price * newdr.qtyn;
 | |
|                     newdr.ItemUnit = 단위;
 | |
|                     newdr.ItemManu = 제조사;
 | |
| 
 | |
|                     newdr.ItemSupply = 공급사;
 | |
|                     newdr.ItemSupplyidx = -1;
 | |
|                     if (공급사 != "")
 | |
|                     {
 | |
|                         int idx;
 | |
|                         string nameK, nameE;
 | |
|                         if (FCOMMON.DBM.getFindSupply(공급사, out idx, out nameK, out nameE))
 | |
|                         {
 | |
|                             newdr.ItemSupply = nameK;
 | |
|                             newdr.ItemSupplyidx = idx;
 | |
|                         }
 | |
|                     }
 | |
| 
 | |
|                     newdr.ItemGroup = 중분류;
 | |
|                     newdr.option1 = 소분류;
 | |
|                     newdr.option2 = 납기일;
 | |
|                     newdr.memo = 비고;
 | |
|                     sumamt += newdr.amt;
 | |
| 
 | |
|                     this.dsPRJ.ProjectsPart.AddProjectsPartRow(newdr);
 | |
|                 }
 | |
|                 //this.dsPRJ.ProjectsPart.AcceptChanges();
 | |
|             }
 | |
|             catch (Exception ex)
 | |
|             {
 | |
|                 FCOMMON.Util.MsgE("불러오는 중 오류 발생\n" + ex.Message);
 | |
|             }
 | |
|             //
 | |
|             book = null;
 | |
| 
 | |
|             sbSum.Text = string.Format("합계:{0:N0}원", sumamt);
 | |
|             //this.bs.DataSource = dt;
 | |
|             //this.bn.BindingSource = this.bs;
 | |
|             //this.dataGridView1.AutoGenerateColumns = true;
 | |
|             //this.dataGridView1.DataSource = this.bs;
 | |
|             this.dataGridView1.Visible = true;
 | |
|             this.dataGridView1.AutoResizeColumns();
 | |
| 
 | |
|             if (this.bs.Count < 1)
 | |
|             {
 | |
|                 FCOMMON.Util.MsgE("입력된 자료가 없습니다.\n\n지정된 엑셀의 1번째 칸에 값이 없다면 입력되지 않습니다.");
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         private void button2_Click(object sender, EventArgs e)
 | |
|         {
 | |
|             var dlg = FCOMMON.Util.MsgQ("데이터의 SID를 ITEM정보와 확인하여 업데이트 합니다.");
 | |
|             if (dlg != System.Windows.Forms.DialogResult.Yes) return;
 | |
| 
 | |
|             var i = FCOMMON.DBM.UpdateItemIndexbySID();
 | |
|             FCOMMON.Util.MsgI(i.ToString() + "건의 자료가 업데이트 되었습니다.");
 | |
| 
 | |
| 
 | |
|         }
 | |
| 
 | |
|         private void numericUpDown6_ValueChanged(object sender, EventArgs e)
 | |
|         {
 | |
|             var ctl = sender as NumericUpDown;
 | |
|             if (ctl.Value == 0) ctl.BackColor = Color.Gray;
 | |
|             else ctl.BackColor = Color.White;
 | |
|         }
 | |
| 
 | |
|         private void toolStripButton1_Click(object sender, EventArgs e)
 | |
|         {
 | |
|             //저장버튼
 | |
|             if (dsPRJ.ProjectsPart.Rows.Count < 1)
 | |
|             {
 | |
|                 FCOMMON.Util.MsgE("등록 가능한 자료가 없습니다.");
 | |
|                 return;
 | |
|             }
 | |
| 
 | |
|             System.Text.StringBuilder sb = new StringBuilder();
 | |
|             sb.AppendLine("다음 자료를 추가하시겠습니까?");
 | |
|             sb.AppendLine();
 | |
|             sb.AppendLine("'저장 완료' 메세지가 나올때 까지 기다려 주세요.");
 | |
|             sb.AppendLine();
 | |
|             sb.AppendLine("실행 하려면 '예' 를 누르세요");
 | |
|             var dlg = FCOMMON.Util.MsgQ(sb.ToString());
 | |
|             if (dlg != System.Windows.Forms.DialogResult.Yes) return;
 | |
| 
 | |
|             ta.Update(this.dsPRJ.ProjectsPart);
 | |
|             dsPRJ.ProjectsPart.AcceptChanges();
 | |
|             FCOMMON.Util.MsgI("Save OK");
 | |
|         }
 | |
| 
 | |
|         private void btDelAll_Click(object sender, EventArgs e)
 | |
|         {
 | |
|             var dlg = FCOMMON.Util.MsgQ("파트리스트를 모두 삭제하시겠습니까?");
 | |
|             if (dlg != System.Windows.Forms.DialogResult.Yes) return;
 | |
|             var cnt = ta.DeleteProject(this.ProjectIndex);
 | |
|             FCOMMON.Util.MsgI(string.Format("{0}건의 자료가 삭제 되었습니다.", cnt));
 | |
| 
 | |
|         }
 | |
| 
 | |
|         private void btDelImp_Click(object sender, EventArgs e)
 | |
|         {
 | |
|             var dlg = FCOMMON.Util.MsgQ("가져온 파트리스트 자룔를 모두 삭제하시겠습니까?");
 | |
|             if (dlg != System.Windows.Forms.DialogResult.Yes) return;
 | |
|             var cnt = ta.DeleteImport(this.ProjectIndex);
 | |
|             FCOMMON.Util.MsgI(string.Format("{0}건의 자료가 삭제 되었습니다.", cnt));
 | |
|         }
 | |
|     }
 | |
| }
 | 
