Files
Groupware/SubProject/FPJ0000/Project/fSCCheck.cs
2023-03-07 23:11:45 +09:00

312 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 fSCCheck : Form
{
dsPRJ.ProjectsPartDataTable dt;
public fSCCheck(dsPRJ.ProjectsPartDataTable dt_)
{
InitializeComponent();
this.dt = dt_;
this.FormClosed += __Closed;
//this.bs.DataSource = dt;
}
private void __Load(object sender, EventArgs e)
{
//this.sd.Value = DateTime.Now.AddMonths(-1);
//this.dtPdate.Value = DateTime.Now;
textBox1.AllowDrop = true;
this.textBox1.DragDrop += TextBox1_DragDrop;
this.textBox1.DragEnter += TextBox1_DragEnter;
}
private void TextBox1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
private void TextBox1_DragDrop(object sender, DragEventArgs e)
{
var files = (string[])e.Data.GetData(DataFormats.FileDrop, false);
if (files != null && files.Length > 0)
{
var file = files[0];
if (System.IO.File.Exists(file))
{
textBox1.Text = file;
}
}
}
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 SID = "";
string = "";
string = "";
string PO = "";
string = "";
string = "";
this.progressBar1.Value = 0;
this.progressBar1.Maximum = MaxRow - MinRow + 1;
this.dv1.Visible = false;
try
{
for (int r = MinRow; r <= MaxRow; r++)
{
progressBar1.Value += 1;
//필수값을 먼저 확인한다.
if (nudSID.Value > 0) SID = sheet.readStr(r, (int)nudSID.Value - 1).Trim();
if (nudQty.Value > 0) = sheet.readStr(r, (int)nudQty.Value - 1).Replace(",", "").Trim();
if (nudPrice.Value > 0) = sheet.readStr(r, (int)nudPrice.Value - 1).Replace(",", "").Trim();
if (nudPO.Value > 0) PO = sheet.readStr(r, (int)nudPO.Value - 1).Trim();
if (nudSupply.Value > 0) = sheet.readStr(r, (int)nudSupply.Value - 1).Trim();
if (nudName.Value > 0) = sheet.readStr(r, (int)nudName.Value - 1).Trim();
// var qty = 0;
// var price = 0;
//sid 공백과 - _ 제거 200506
SID = SID.Replace(" ", "").Replace("-", "").Replace("_", "").Trim();
//필수자료갸ㅏ 없는 경우처리하지 않음
if (PO.Trim() == "") continue;
var newdr = this.dsPRJ.SCTable.NewSCTableRow();
newdr.PName = ;
newdr.SID = SID;
newdr.Qty = 0;
newdr.Price = 0;
newdr.Supply = ;
newdr.PO = PO;
if ( != "") newdr.Price = decimal.Parse();
if ( != "") newdr.Qty = int.Parse();
this.dsPRJ.SCTable.AddSCTableRow(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.dv1.Visible = true;
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 toolStripButton1_Click_1(object sender, EventArgs e)
{
var dlg = FCOMMON.Util.MsgQ("SID별 수량 검사를 진행합니다. \n\n구매여부가 자동 선택되며 특이 사항은 비고에 추가 됩니다");
if (dlg != DialogResult.Yes) return;
//Sctable 데이터를 sid 별 그룹으로 처리해야함
var sclist = this.dsPRJ.SCTable.GroupBy(t => t.SID);
this.progressBar1.Maximum = sclist.Count() ;
this.progressBar1.Value = 0;
//sc list 의 isd목록을 회전해서,, 파트리스트의 목록과 비교한다.
foreach(var scgrp in sclist)
{
//progress bar
if(this.progressBar1.Value < this.progressBar1.Maximum)
this.progressBar1.Value += 1;
var dr = scgrp.FirstOrDefault();
var sid = dr.SID;
var price = dr.Price;
var supply = dr.Supply;
var qtysum = scgrp.Sum(t => t.Qty);
var ptlist = this.dt.Where(t => t.ItemSid == sid);
var qtysumPt = 0;// ptlist.Sum(t => t.qtybuy);
//sc와 pt 의 수량이 다르면 문제이다
if(qtysum != qtysumPt)
{
var ermsg = "[SC:수량불일치 엑셀:" + qtysum.ToString() + "/파트:" + qtysumPt.ToString() + "]";
foreach (var ptdata in ptlist)
{
var memo = ptdata.memo;
if(memo.StartsWith("[SC:")==false)
{
ptdata.memo = ermsg + memo;// ptdata.memo;
}
else
{
ptdata.memo = ermsg + memo.Substring(memo.IndexOf("]"));
}
ptdata.EndEdit();
}
}
else
{
//수량이 같으면 잘 된거다
// var ermsg = "[SC:수량일치 엑셀:" + qtysum.ToString() + "/파트:" + qtysumPt.ToString() + "]";
foreach (var ptdata in ptlist)
{
//ptdata.bbuy = true;
ptdata.price = price;
ptdata.ItemSupply = supply;
ptdata.ItemSupplyidx = -1;
//var memo = ptdata.memo;
//if (memo.StartsWith("[SC:") == false)
//{
// ptdata.memo = ermsg + memo;// ptdata.memo;
//}
//else
//{
// ptdata.memo = ermsg + memo.Substring(memo.IndexOf("]"));
//}
ptdata.EndEdit();
}
}
}
}
private void toolStripButton2_Click(object sender, EventArgs e)
{
var dlg = FCOMMON.Util.MsgQ("모든 자료의 구매 확정상태가 해제 됩니다");
if (dlg != DialogResult.Yes) return;
foreach (var item in this.dt)
{
// item.bbuy = false;
item.EndEdit();
}
}
}
}