Files
Groupware/SubProject/FPJ0000/Project/fProjectPartImport.cs
2020-04-14 21:11:56 +09:00

271 lines
11 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 fProjectPartImport : Form
{
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)
{
//this.sd.Value = DateTime.Now.AddMonths(-1);
//this.dtPdate.Value = DateTime.Now;
}
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 = "";
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);
if (nudSid.Value > 0) SID = sheet.readStr(r, (int)nudSid.Value - 1);
if (nudName.Value > 0) = sheet.readStr(r, (int)this.nudName.Value - 1);
if (nudModel.Value > 0) = sheet.readStr(r, (int)this.nudModel.Value - 1);
if (nudPrice.Value > 0) = sheet.readStr(r, (int)this.nudPrice.Value - 1).Replace(",", "");
if (nudQty.Value > 0) = sheet.readStr(r, (int)nudQty.Value - 1).Replace(",", "");
if (nudUnit.Value > 0) = sheet.readStr(r, (int)nudUnit.Value - 1);
if (nudManu.Value > 0) = sheet.readStr(r, (int)nudManu.Value - 1);
if (nudSupply.Value > 0) = sheet.readStr(r, (int)nudSupply.Value - 1);
if (nudGrp.Value > 0) = sheet.readStr(r, (int)nudGrp.Value - 1);
if (nudMemo.Value > 0) = sheet.readStr(r, (int)nudMemo.Value - 1);
if (nudBuwi.Value > 0) = sheet.readStr(r, (int)nudBuwi.Value - 1);
if (nudNapKi.Value > 0) = sheet.readStr(r, (int)nudNapKi.Value - 1);
if (numericUpDown2.Value > 0) = sheet.readStr(r, (int)numericUpDown2.Value - 1);
//필수자료갸ㅏ 없는 경우처리하지 않음
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 ( != "") newdr.qty = int.Parse();
newdr.amt = newdr.price * newdr.qty;
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.ItemGroup = ;
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));
}
}
}