Esempio n. 1
0
        private void grid_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            conDataGridView  grd  = (conDataGridView)sender;
            DataGridViewCell cell = grd[e.ColumnIndex, e.RowIndex];

            cell.Style.BackColor = Color.White;


            if (grd.Columns[e.ColumnIndex].ToolTipText.IndexOf("명칭") >= 0 && grd._KeyInput == "enter")
            {
                string    item_nm    = (string)grd.Rows[e.RowIndex].Cells["ITEM_NM"].Value;
                wnDm      wDm        = new wnDm();
                DataTable dt         = new DataTable();
                String    sqlcontion = "";
                if (txt_cust_cd.Text != "" & Common.p_saupNo == "1278113487")
                {
                    sqlcontion += "and A.cust_CD = '" + txt_cust_cd.Text + "'";
                }
                else
                {
                    txt_cust_cd.Tag = "NOT매출제품";
                }
                dt = wDm.fn_Item_List("where ITEM_NM like '%" + item_nm + "%' " + sqlcontion, txt_cust_cd.Text.ToString());

                if (dt.Rows.Count > 1)
                { //row가 2줄이 넘을 경우 팝업으로 넘어간다.
                    string sResult = wConst.call_pop_item2(grd, dt, e.RowIndex, item_nm, txt_cust_cd.Text);

                    if (sResult != "")
                    {
                    }
                    //itemPlanGridAdd();
                    itemJumunGridAdd();
                }
                else if (dt.Rows.Count == 1) //row가 1일 경우 해당 row에 값을 자동 입력한다.
                {
                    grd.Rows[e.RowIndex].Cells["ITEM_NM"].Value = dt.Rows[0]["ITEM_NM"].ToString();
                    grd.Rows[e.RowIndex].Cells["ITEM_CD"].Value = dt.Rows[0]["ITEM_CD"].ToString();
                    grd.Rows[e.RowIndex].Cells["SPEC"].Value    = dt.Rows[0]["SPEC"].ToString();

                    grd.Rows[e.RowIndex].Cells["UNIT_CD"].Value   = dt.Rows[0]["UNIT_CD"].ToString();
                    grd.Rows[e.RowIndex].Cells["UNIT_NM"].Value   = dt.Rows[0]["UNIT_NM"].ToString();
                    grd.Rows[e.RowIndex].Cells["TOTAL_AMT"].Value = "1";
                    grd.Rows[e.RowIndex].Cells["UNIT_AMT"].Value  = "1";

                    grd.Rows[e.RowIndex].Cells["PRICE"].Value = dt.Rows[0]["OUTPUT_PRICE"].ToString();

                    itemJumunGridAdd();
                }
                else
                { //row가 없는 경우
                    MessageBox.Show("데이터가 없습니다.");
                    itemJumunGrid.Rows.RemoveAt(itemJumunGrid.SelectedRows[0].Index);
                    itemJumunGrid.CurrentCell = itemJumunGrid[2, itemJumunGrid.Rows.Count];
                }

                wConst.f_Calc_Price(grd, e.RowIndex, "TOTAL_AMT", "PRICE");
            }

            if (grd.Columns[e.ColumnIndex].ToolTipText.IndexOf("수량") >= 0 ||
                grd.Columns[e.ColumnIndex].ToolTipText.IndexOf("단가") >= 0 ||
                grd.Columns[e.ColumnIndex].ToolTipText.IndexOf("금액") >= 0)
            {
                string total_amt = (string)grd.Rows[e.RowIndex].Cells["TOTAL_AMT"].Value;
                string price     = (string)grd.Rows[e.RowIndex].Cells["PRICE"].Value;

                if (total_amt != null)
                {
                    total_amt = total_amt.ToString().Replace(" ", "");
                    if (total_amt == "")
                    {
                        grd.Rows[e.RowIndex].Cells["TOTAL_AMT"].Value = "0";
                    }
                }
                else
                {
                    grd.Rows[e.RowIndex].Cells["TOTAL_AMT"].Value = "0";
                }

                if (price != null)
                {
                    price = price.ToString().Replace(" ", "");
                    if (price == "")
                    {
                        grd.Rows[e.RowIndex].Cells["PRICE"].Value = "0";
                    }
                }
                else
                {
                    grd.Rows[e.RowIndex].Cells["PRICE"].Value = "0";
                }

                //if (total_amt == "" || total_amt == null)
                //{
                //    grd.Rows[e.RowIndex].Cells["TOTAL_AMT"].Value = "0";
                //}
                //if (price == "" || price == null)
                //{
                //    grd.Rows[e.RowIndex].Cells["PRICE"].Value = "0";
                //}

                wConst.f_Calc_Price(grd, e.RowIndex, "TOTAL_AMT", "PRICE");
            }
        }