/// <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;
            }
        }
Esempio n. 2
0
        public Message InsertOrUpdateSalesCost(SalesCost_VO vo)
        {
            CostDAC dac = new CostDAC();

            return(dac.InsertOrUpdateSalesCost(vo));
        }
Esempio n. 3
0
        /// <summary>
        /// 영업단가 저장 메서드
        /// </summary>
        /// <param name="vo"></param>
        /// <returns></returns>
        public Message InsertOrUpdateSalesCost(SalesCost_VO vo)
        {
            try
            {
                string sql = "SP_SaveSalesCost";
                using (SqlConnection conn = new SqlConnection(this.ConnectionString))
                {
                    conn.Open();
                    using (SqlCommand cmd = new SqlCommand(sql, conn))
                    {
                        cmd.CommandType = System.Data.CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@P_SC_Code", vo.SC_CODE);
                        cmd.Parameters.AddWithValue("@P_SC_UNITPRICE_CUR", vo.SC_UNITPRICE_CUR);
                        cmd.Parameters.AddWithValue("@P_SC_UNITPRICE_EX", vo.SC_UNITPRICE_EX);
                        cmd.Parameters.AddWithValue("@P_SC_STARTDATE", vo.SC_STARTDATE);
                        cmd.Parameters.AddWithValue("@P_SC_ENDDATE", vo.SC_ENDDATE);
                        cmd.Parameters.AddWithValue("@P_SC_LAST_MDFR", vo.SC_LAST_MDFR);
                        cmd.Parameters.AddWithValue("@P_SC_LAST_MDFY", vo.SC_LAST_MDFY);
                        cmd.Parameters.AddWithValue("@P_SC_USE_YN", vo.SC_USE_YN);
                        cmd.Parameters.AddWithValue("@P_SC_REMARK", vo.SC_REMARK);
                        cmd.Parameters.AddWithValue("@P_COM_Code", vo.COM_Code);
                        cmd.Parameters.AddWithValue("@P_ITEM_Code", vo.ITEM_Code);


                        cmd.Parameters.Add(new SqlParameter("@P_ReturnCode", System.Data.SqlDbType.NVarChar, 5));
                        cmd.Parameters["@P_ReturnCode"].Direction = System.Data.ParameterDirection.Output;
                        cmd.ExecuteNonQuery();
                        conn.Close();

                        string result = cmd.Parameters["@P_ReturnCode"].Value.ToString();

                        Message message = new Message();
                        if (result == "M01")
                        {
                            message.IsSuccess     = true;
                            message.ResultMessage = "성공적으로 등록되었습니다.";
                        }
                        else if (result == "M02")
                        {
                            message.IsSuccess     = true;
                            message.ResultMessage = "성공적으로 수정되었습니다.";
                        }
                        else if (result == "M03")
                        {
                            message.IsSuccess     = false;
                            message.ResultMessage = "시작일 날짜는 이전 시작날짜보다 작을 수 없습니다.";
                        }
                        else if (result == "M00")
                        {
                            message.IsSuccess     = false;
                            message.ResultMessage = "잘못된 실행입니다.";
                        }

                        return(message);
                    }
                }
            }
            catch (Exception err)
            {
                return(new Message(err));
            }
        }
        /// <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;
            }
        }