예제 #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (CheckDataList().Count > 0)
            {
                foreach (int index in CheckDataList())
                {
                    dgvInput.Rows[index].DefaultCellStyle.BackColor = Color.Red;
                    dgvInput.Rows[index].DefaultCellStyle.ForeColor = Color.White;
                }
                return;
            }

            foreach (DataGridViewRow row in dgvInput.Rows)
            {
                string mouldNo   = row.Cells[1].Value.ToString();
                string partNo    = row.Cells[2].Value.ToString();
                string rev       = row.Cells[3].Value.ToString();
                string vendor    = row.Cells[4].Value.ToString();
                string model     = row.Cells[5].Value.ToString();
                string div       = row.Cells[6].Value.ToString();
                string mouldCode = row.Cells[7].Value.ToString();
                string currency  = row.Cells[8].Value.ToString();
                string amount    = row.Cells[9].Value.ToString();
                string mpa       = row.Cells[10].Value == "Yes" ? "True" : "False";
                string remarks   = row.Cells[11].Value.ToString();
                string modify    = row.Cells[12].Value == "Yes" ? "True" : "False";
                string pcs       = row.Cells[13].Value.ToString();
                string oem       = row.Cells[14].Value.ToString();
                string pbase     = row.Cells[15].Value.ToString();
                string pgroup    = row.Cells[16].Value.ToString();

                string chaseno     = Mould.GetLatestChaseNo();
                string projectText = partNo + "-" + rev;
                string request     = partNo + rev;
                string itemText    = mpa == "Yes" ? mouldNo + "MP+" + mouldCode + "+" + div + "*" : mouldNo + "MP+" + mouldCode + "+" + div;
                string instock50   = mpa == "Yes" ? "Yes" : "#N/A";
                string quantity    = mpa == "Yes" ? "2" : "1";

                string accountCode = oem != "" ? Oem.GetAccountCode(oem) : "";
                string costCentre  = oem != "" ? Oem.GetCostCentre(oem) : "";

                decimal cAmount = currency == "JPY" ? Convert.ToDecimal(amount) * Convert.ToDecimal(Amount.GetMonthlyJpyRate(DateTime.Today.ToString("yyyy"), DateTime.Today.ToString("MM")))
                    : Amount.AmountWithRate(currency, amount);

                string amountHkd = cAmount.ToString("#.##");

                cAmount = cAmount / Convert.ToInt32(pcs);

                string category = "A";
                string status   = "";

                if (cAmount < 10000)
                {
                    category = "K";
                    status   = cAmount == 0 ? "K" : "U";
                }
                else
                {
                    category = (mouldCode.StartsWith("8") && mouldCode != "8") || (oem != "") ? "K" : "A";
                    status   = (mouldCode.StartsWith("8") && mouldCode != "8") || (oem != "") ? "U" : "F";
                }

                string po = div == "TM" ? chaseno.Replace("MS", "TM") : "";

                string created   = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                string createdby = GlobalService.Owner;

                string query = string.Format("insert into TB_MOULD_MAIN (m_chaseno, m_mouldno, m_itemcode" +
                                             ", m_rev, m_div, m_currency, m_amount, m_amounthkd, m_mpa, m_quantity, m_pcs" +
                                             ", m_itemtext, m_request, m_projecttext, m_model, m_po, m_category, m_vendor" +
                                             ", m_group, m_mouldcode, m_status, m_remarks, m_oem, m_instock50" +
                                             ", m_created, m_createdby, m_accountcode, m_costcenter, m_productbase) values" +
                                             " ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}', '{13}', '{14}', '{15}', '{16}', '{17}'" +
                                             ", '{18}', '{19}', '{20}', N'{21}', '{22}', '{23}', '{24}', N'{25}', '{26}', '{27}', '{28}')", chaseno, mouldNo, partNo,
                                             rev, div, currency, amount, amountHkd, mpa, quantity, pcs, itemText, request, projectText, model, po,
                                             category, vendor, pgroup, mouldCode, status, remarks, oem, instock50, created, createdby,
                                             accountCode, costCentre, pbase);

                DataService.GetInstance().ExecuteNonQuery(query);
            }

            if (SavedEvent != null)
            {
                SavedEvent(this, new EventArgs());
            }
        }