コード例 #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());
            }
        }
コード例 #2
0
        private void tsbtnSave_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in dgvPreview.Rows)
            {
                string mouldNo    = row.Cells[1].Value.ToString();
                string partNo     = row.Cells[2].Value.ToString();
                string rev        = row.Cells[3].Value.ToString();
                string fromVendor = row.Cells[4].Value.ToString();
                string toVendor   = row.Cells[5].Value.ToString();
                string remarks    = row.Cells[8].Value.ToString();
                string pcs        = row.Cells[9].Value.ToString();
                string chaseNo    = row.Cells[10].Value.ToString();

                List <string> list = FaList(chaseNo);

                string fa       = "";
                string category = "K";

                if (list.Count == 0)
                {
                    fa = "";
                }
                else if (list.Count == 1)
                {
                    fa       = list[0].ToString();
                    category = "A";
                }
                else
                {
                    fa       = string.Join(",", list.ToArray());
                    category = "A";
                }

                string lastChaseNo = Mould.GetLatestChaseNo();
                string tmNo        = lastChaseNo.Replace("MS", "TM");
                string purG        = Vendor.GetVendorGroup(toVendor);
                string div         = Mould.GetDiv(chaseNo);
                string mouldCode   = Mould.GetMouldCode(chaseNo);
                string itemText    = mouldNo + "MP+" + Mould.GetMouldCode(chaseNo) + "+TM";
                string type        = "TM";
                string isModify    = "False";
                string projectText = partNo + "-" + rev;
                string request     = partNo + rev;
                string quantity    = "1";
                string amount      = "0";
                string currency    = Vendor.GetVendorCurrency(toVendor);
                string status      = "T";
                string owner       = "KDTHK";
                string common      = "Non-Common";
                string model       = mouldNo.Substring(1, 3);

                string query = string.Format("insert into TB_MOULD_MAIN (mm_chaseno, mm_mouldno, mm_itemcode, mm_rev" +
                                             ", mm_div, mm_type, mm_currency, mm_amount, mm_amounthkd, mm_mpa, mm_mouldcode, mm_vendorcode" +
                                             ", mm_status_code, mm_quantity, mm_itemtext, mm_projecttext, mm_request, mm_owner, mm_category" +
                                             ", mm_created, mm_createdby, mm_model, mm_group, mm_po, mm_fixedassetcode" +
                                             ", mm_pcs, mm_ismodify, mm_remarks) values ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}'" +
                                             ", '{13}', '{14}', '{15}', '{16}', '{17}', '{18}', '{19}', '{20}', '{21}', '{22}', '{23}', '{24}', '{25}', '{26}', '{27}')", lastChaseNo,
                                             mouldNo, partNo, rev, div, type, currency, amount, amount, "False", mouldCode, toVendor, status, quantity,
                                             itemText, projectText, request, owner, category, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"),
                                             GlobalService.Owner, model, purG, tmNo, fa, pcs, isModify, remarks);

                DataService.GetInstance().ExecuteNonQuery(query);

                this.SaveTransferHistory(tmNo, mouldNo, partNo, rev, fromVendor, toVendor, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"),
                                         chaseNo, fa, remarks);
            }

            MessageBox.Show("Record has been saved.");

            dgvPreview.Rows.Clear();
        }