/// <summary> /// 저장이벤트 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnOK_Click(object sender, EventArgs e) { //유효성 검사 if (!(txtNowPrice.Text.Trim().Length > 0)) { MessageBox.Show("현재단가는 입력 필수값입니다.", "필수 입력", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!(txtExPrice.Text.Trim().Length > 0)) { MessageBox.Show("이전단가는 입력 필수값입니다.", "필수 입력", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //전달할 VO SalesCost_VO vo = new SalesCost_VO(); vo.COM_Code = cboCompany.SelectedValue.ToString(); vo.ITEM_Code = cboItem.SelectedValue.ToString(); vo.SC_UNITPRICE_CUR = int.Parse(txtNowPrice.Text); vo.SC_UNITPRICE_EX = int.Parse(txtExPrice.Text); vo.SC_STARTDATE = dtpStartDate.Value.ToShortDateString(); vo.SC_ENDDATE = Convert.ToDateTime(txtEndDate.Text).ToShortDateString(); vo.SC_USE_YN = cboUseYN.Text; vo.SC_CODE = 0; //등록 if (InsertOrUpdate == 2) { vo.SC_CODE = int.Parse(txtCode.Text); //수정 } vo.SC_LAST_MDFR = LoginInfo.UserInfo.LI_ID; vo.SC_LAST_MDFY = txtMDFDate.Text; vo.SC_REMARK = txtRemark.Text.Trim(); //서비스호출 CostService service = new CostService(); var msg = service.InsertOrUpdateSalesCost(vo); if (msg.IsSuccess) { MessageBox.Show(msg.ResultMessage); this.Close(); } else { MessageBox.Show(msg.ResultMessage); return; } }
/// <summary> /// 엑셀 파일 읽어와서 등록하는 메서드 /// </summary> private void GetExcelFile() { Excel.Application xlApp = null; Excel.Workbook xlWorkBook = null; Excel.Worksheet xlWorkSheet = null; DataTable dt = new DataTable(); try { xlApp = new Excel.Application(); xlWorkBook = xlApp.Workbooks.Open(openFileName); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); Excel.Range range = xlWorkSheet.UsedRange; object[,] data = range.Value; for (int i = 1; i <= range.Columns.Count; i++) { dt.Columns.Add(data[1, i].ToString(), typeof(string)); } for (int r = 2; r <= range.Rows.Count; r++) { DataRow dr = dt.Rows.Add(); for (int c = 1; c <= range.Columns.Count; c++) { dr[c - 1] = data[r, c]; } } xlWorkBook.Close(true); xlApp.Quit(); if (dt.Rows.Count > 0) { //DB에 저장 for (int i = 0; i < dt.Rows.Count; i++) { //전달할 VO SalesCost_VO vo = new SalesCost_VO(); vo.COM_Code = (dt.Rows[i][0] != null) ? dt.Rows[i][0].ToString() : ""; vo.ITEM_Code = (dt.Rows[i][1] != null) ? dt.Rows[i][1].ToString() : ""; vo.SC_UNITPRICE_CUR = (dt.Rows[i][2] != null) ? Convert.ToInt32(dt.Rows[i][2]) : 0; vo.SC_UNITPRICE_EX = 0; vo.SC_STARTDATE = (dt.Rows[i][3] != null) ? DateTime.ParseExact(dt.Rows[i][3].ToString(), "yyyy-MM-dd tt hh:mm:ss", null, System.Globalization.DateTimeStyles.AssumeLocal).ToString("yyyy-MM-dd HH:mm:ss") : ""; vo.SC_ENDDATE = "2099-01-01"; vo.SC_USE_YN = (dt.Rows[i][4] != null) ? dt.Rows[i][4].ToString() : ""; vo.SC_CODE = 0; vo.SC_LAST_MDFR = LoginInfo.UserInfo.LI_ID; vo.SC_LAST_MDFY = DateTime.Now.ToShortDateString(); vo.SC_REMARK = (dt.Rows[i][5] != null) ? dt.Rows[i][5].ToString() : ""; //서비스호출 CostService service = new CostService(); var msg = service.InsertOrUpdateSalesCost(vo); if (msg.IsSuccess) { MessageBox.Show(msg.ResultMessage); this.Close(); } else { MessageBox.Show(msg.ResultMessage); return; } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if (xlApp != null) { releaseObject(xlWorkSheet); releaseObject(xlWorkBook); releaseObject(xlApp); } this.DialogResult = DialogResult.OK; } }