Esempio n. 1
0
        /// <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
            MaterialCost_VO vo = new MaterialCost_VO();

            vo.COM_Code         = cboCompany.SelectedValue.ToString();
            vo.ITEM_Code        = cboItem.SelectedValue.ToString();
            vo.MC_UNITPRICE_CUR = int.Parse(txtNowPrice.Text);
            vo.MC_UNITPRICE_EX  = int.Parse(txtExPrice.Text);
            vo.MC_STARTDATE     = dtpStartDate.Value.ToShortDateString();
            vo.MC_ENDDATE       = Convert.ToDateTime(txtEndDate.Text).ToShortDateString();
            vo.MC_USE_YN        = cboUseYN.Text;
            vo.MC_Code          = 0; //등록
            if (InsertOrUpdate == 2)
            {
                vo.MC_Code = int.Parse(txtCode.Text); //수정
            }
            vo.MC_LAST_MDFR = LoginInfo.UserInfo.LI_ID;
            vo.MC_LAST_MDFY = txtMDFDate.Text;
            vo.MC_REMARK    = txtRemark.Text.Trim();

            //서비스호출
            CostService service = new CostService();
            var         msg     = service.InsertOrUpdateMaterialCost(vo);

            if (msg.IsSuccess)
            {
                MessageBox.Show(msg.ResultMessage);
                this.Close();
            }
            else
            {
                MessageBox.Show(msg.ResultMessage);
                return;
            }
        }
Esempio n. 2
0
        /// <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
                        MaterialCost_VO vo = new MaterialCost_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.MC_UNITPRICE_CUR = (dt.Rows[i][2] != null) ? Convert.ToInt32(dt.Rows[i][2]) : 0;
                        vo.MC_UNITPRICE_EX  = 0;
                        vo.MC_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.MC_ENDDATE       = "2099-01-01";
                        vo.MC_USE_YN        = (dt.Rows[i][4] != null) ? dt.Rows[i][4].ToString() : "";
                        vo.MC_Code          = 0;
                        vo.MC_LAST_MDFR     = LoginInfo.UserInfo.LI_ID;
                        vo.MC_LAST_MDFY     = DateTime.Now.ToShortDateString();
                        vo.MC_REMARK        = (dt.Rows[i][5] != null) ? dt.Rows[i][5].ToString() : "";

                        //서비스호출
                        CostService service = new CostService();
                        var         msg     = service.InsertOrUpdateMaterialCost(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;
            }
        }