private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                foreach (DataRow row in uploadTable.Rows)
                {
                    string chaseno   = row.ItemArray[0].ToString();
                    string ulInStock = row.ItemArray[16].ToString();

                    string ulInStock50 = row.ItemArray[15].ToString();

                    if (ulInStock50 != "" && !ulInStock50.Contains("---") && ulInStock50 != "Received" && ulInStock50 != "一回合格入庫" && ulInStock50 != "已拆單、以合格同時入庫")
                    {
                        string vendorcode = DataChecking.getVendorCodeByChaseNo(chaseno);

                        string payterm = DataChecking.getPayTerm(vendorcode);

                        ulInStock50 = ImportXlsUtil.ParseDateTime(ulInStock50).ToString("yyyy/MM/dd");

                        string paymonth = "";

                        if (payterm == "HK01")
                        {
                            paymonth = ImportXlsUtil.ParseDateTime(ulInStock50).AddMonths(1).ToString("yyyy/MM/dd");
                        }
                        else if (payterm == "HK02")
                        {
                            paymonth = ImportXlsUtil.ParseDateTime(ulInStock50).AddMonths(2).ToString("yyyy/MM/dd");
                        }

                        string query = string.Format("update tb_betamould set tm_st_code = 'HS', tm_instockdate50 = '{0}', tm_moulditemviewer = 'Yes', tm_paydate = '{1}' where tm_chaseno = '{2}'", ulInStock50, paymonth, chaseno);

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

                    if (ulInStock != "" && ulInStock != "Received" && ulInStock != "#N/A")
                    {
                        string vendorcode = DataChecking.getVendorCodeByChaseNo(chaseno);

                        string payterm = DataChecking.getPayTerm(vendorcode);

                        string paymonth = "";

                        if (payterm == "HK01")
                        {
                            paymonth = ImportXlsUtil.ParseDateTime(ulInStock).AddMonths(1).ToString("yyyy/MM/dd");
                        }

                        else if (payterm == "HK02")
                        {
                            paymonth = ImportXlsUtil.ParseDateTime(ulInStock).AddMonths(2).ToString("yyyy/MM/dd");
                        }

                        ulInStock = ImportXlsUtil.ParseDateTime(ulInStock).ToString("yyyy/MM/dd");

                        if (ulInStock == "0001/03/02")
                        {
                            ulInStock = "";
                        }

                        string query = string.Format("update tb_betamould set tm_st_code = 'S', tm_instockdate = '{0}', tm_paydate = '{1}', tm_nofac = 'False', tm_moulditemviewer = 'Yes' where tm_chaseno = '{2}'", ulInStock, paymonth, chaseno);

                        DataService.GetInstance().ExecuteNonQuery(query);

                        string expenseText = string.Format("update tb_expensetransfer set et_poinstock = '{0}' where et_chaseno = '{1}'", ulInStock, chaseno);

                        DataService.GetInstance().ExecuteNonQuery(expenseText);

                        string query2 = string.Format("update TB_FA_APPROVAL set f_remarks = N'已入庫' where f_mould = '{0}'", chaseno);
                        DataServiceNew.GetInstance().ExecuteNonQuery(query2);
                    }
                }

                MessageBox.Show("Data uploaded");
            }
            catch
            {
                MessageBox.Show("Invalid Data Format");
            }
        }
        private void search()
        {
            this.txtCheckdate.Clear();
            this.txtCav.Clear();
            this.txtWeight.Clear();
            this.txtEquipment.Clear();
            this.txtShot.Clear();
            this.txtLength.Clear();
            this.txtWidth.Clear();
            this.txtHeight.Clear();
            this.txtInstockRemarks.Clear();

            this.dgvResult.Rows.Clear();
            this.dgvPreview.Rows.Clear();

            string po = txtPo.Text;

            if (!DataChecking.isValidPo(po))
            {
                if (po.StartsWith("12") && po.EndsWith("10"))
                {
                    string tmpo = po.Substring(0, po.Length - 2);
                    tmpo = tmpo + "20";

                    if (DataChecking.isValidPo(tmpo))
                    {
                        switch (MessageBox.Show("Temporary receive PO: " + po + " ?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                        {
                        case DialogResult.Yes:

                            string poText = string.Format("insert into tb_temppo (tp_po) values ('{0}')", po);
                            DataService.GetInstance().ExecuteNonQuery(poText);

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

                        case DialogResult.No:
                            break;
                        }

                        return;
                    }
                    else
                    {
                        MessageBox.Show("Invalid PO No.");
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("Invalid PO No.");
                    return;
                }
            }

            if (DataChecking.IsPoRmb(po))
            {
                foreach (CheckBox checkbox in tbCheckbox.Controls)
                {
                    checkbox.Enabled = false;
                    checkbox.Checked = false;
                }

                this.getDataByPo(po);

                tmpPo = po;

                if (checkPoIsMpa(po))
                {
                    pictureBox1.BackgroundImage = Properties.Resources.tick;

                    ckbNormal.Enabled   = false;
                    ckbTransfer.Enabled = false;

                    string is50 = DataChecking.getInstock50ByPo(po);

                    if (is50 == "Yes")
                    {
                        ckbFirst50.Enabled  = true;
                        ckbSecond50.Enabled = false;
                        ckbPo1.Enabled      = true;
                        ckbPo2.Enabled      = true;
                    }
                    else
                    {
                        ckbFirst50.Enabled  = false;
                        ckbSecond50.Enabled = true;
                        ckbPo1.Enabled      = false;
                        ckbPo2.Enabled      = false;
                    }
                }
                else
                {
                    pictureBox1.BackgroundImage = Properties.Resources.cross;

                    string type = DataChecking.getTypeByPo(po);

                    if (type == "New" || type == "Modify")
                    {
                        ckbNormal.Enabled   = true;
                        ckbTransfer.Enabled = false;
                    }
                    else
                    {
                        ckbNormal.Enabled   = false;
                        ckbTransfer.Enabled = true;
                    }

                    ckbFirst50.Enabled  = false;
                    ckbSecond50.Enabled = false;
                    ckbPo1.Enabled      = false;
                    ckbPo2.Enabled      = false;
                }

                btnPreview.Enabled = true;
            }
            else
            {
                string currentInStockdate = DataChecking.getInStockDateByPo(po);

                if (currentInStockdate == "Received")
                {
                    switch (MessageBox.Show("PO: " + po + " data already received. Do you want to modify it?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                    {
                    case DialogResult.Yes:
                        break;

                    case DialogResult.No:
                        foreach (CheckBox checkbox in tbCheckbox.Controls)
                        {
                            checkbox.Enabled = true;
                            checkbox.Checked = false;
                        }
                        pictureBox1.BackgroundImage = null;
                        return;
                    }
                }

                this.getDataByPo(po);

                tmpPo = po;

                if (checkPoIsMpa(po))
                {
                    pictureBox1.BackgroundImage = Properties.Resources.tick;

                    ckbNormal.Enabled   = false;
                    ckbTransfer.Enabled = false;

                    string is50 = DataChecking.getInstock50ByPo(po);

                    if (is50 == "Yes")
                    {
                        ckbFirst50.Enabled  = true;
                        ckbSecond50.Enabled = false;
                        ckbPo1.Enabled      = true;
                        ckbPo2.Enabled      = true;
                    }
                    else
                    {
                        ckbFirst50.Enabled  = false;
                        ckbSecond50.Enabled = true;
                        ckbPo1.Enabled      = false;
                        ckbPo2.Enabled      = false;
                    }
                }
                else
                {
                    pictureBox1.BackgroundImage = Properties.Resources.cross;

                    string type = DataChecking.getTypeByPo(po);

                    if (type == "New" || type == "Modify")
                    {
                        ckbNormal.Enabled   = true;
                        ckbTransfer.Enabled = false;
                    }
                    else
                    {
                        ckbNormal.Enabled   = false;
                        ckbTransfer.Enabled = true;
                    }

                    ckbFirst50.Enabled  = false;
                    ckbSecond50.Enabled = false;
                    ckbPo1.Enabled      = false;
                    ckbPo2.Enabled      = false;
                }

                btnPreview.Enabled = true;
            }
        }
        private void loadPreviewData(string chaseno, string po, string itemcode, string rev, string mouldno, string mouldcode, string vendor, string vendorname,
                                     string tmpfac, string fac, string currency, string amount, string issued)
        {
            dgvPreview.Rows.Clear();

            if (fac == "")
            {
                fac = "-";
            }

            if (ckbNormal.Checked)
            {
                instockdate50 = "-----";
                instockdate   = "Received";

                inputRequired = true;

                dgvPreview.Rows.Add(new object[] { chaseno, po, itemcode, rev, mouldno, mouldcode, vendor, vendorname, tmpfac, fac, currency, amount, issued, "-----", "Received" });
            }

            else if (ckbFirst50.Checked)
            {
                instockdate50 = "Received";
                instockdate   = "#N/A";

                inputRequired = false;

                dgvPreview.Rows.Add(new object[] { chaseno, po, itemcode, rev, mouldno, mouldcode, vendor, vendorname, tmpfac, fac, currency, amount, issued, "Received", "#N/A" });
            }

            else if (ckbSecond50.Checked)
            {
                instockdate = "Received";

                inputRequired = true;

                string tmpinstock50 = DataChecking.getInstock50ByPo(po);
                instockdate50 = tmpinstock50;

                dgvPreview.Rows.Add(new object[] { chaseno, po, itemcode, rev, mouldno, mouldcode, vendor, vendorname, tmpfac, fac, currency, amount, issued, tmpinstock50, "Received" });
            }

            else if (ckbPo1.Checked)
            {
                instockdate50 = "一回合格入庫";
                instockdate   = "Received";

                inputRequired = true;

                if (tmpfac != "")
                {
                    dgvPreview.Rows.Add(new object[] { chaseno, po, itemcode, rev, mouldno, mouldcode, vendor, vendorname, tmpfac, "-", currency, amount, issued, "一回合格入庫", "Received" });
                }

                dgvPreview.Rows.Add(new object[] { chaseno, po, itemcode, rev, mouldno, mouldcode, vendor, vendorname, "-", fac, currency, amount, issued, "一回合格入庫", "Received" });
            }

            else if (ckbPo2.Checked)
            {
                instockdate50 = "已拆單、以合格同時入庫";
                instockdate   = "Received";

                inputRequired = true;

                if (tmpfac != "")
                {
                    dgvPreview.Rows.Add(new object[] { chaseno, po, itemcode, rev, mouldno, mouldcode, vendor, vendorname, tmpfac, "-", currency, amount, issued, "已拆單、以合格同時入庫", "Received" });
                }

                dgvPreview.Rows.Add(new object[] { chaseno, po, itemcode, rev, mouldno, mouldcode, vendor, vendorname, "-", fac, currency, amount, issued, "已拆單、以合格同時入庫", "Received" });
            }

            else
            {
                instockdate50 = "-----";
                instockdate   = DateTime.Today.ToString("yyyy/MM/dd");

                inputRequired = false;

                if (tmpfac == "")
                {
                    tmpfac = "-";
                }
                dgvPreview.Rows.Add(new object[] { chaseno, po, itemcode, rev, mouldno, mouldcode, vendor, vendorname, tmpfac, fac, currency, amount, issued, "-----", DateTime.Today.ToString("yyyy/MM/dd") });
            }
        }
        private void btnReceive_Click(object sender, EventArgs e)
        {
            List <int> count = new List <int>();

            foreach (Control control in tbCheckbox.Controls)
            {
                CheckBox ckb = (CheckBox)control;
                if (ckb.Checked == true)
                {
                    count.Add(1);
                }
            }

            bool isRmb = DataChecking.IsPoRmb(txtPo.Text.Trim());

            if (count.Count == 0 && !isRmb)
            {
                MessageBox.Show("Nothing selected. Please click Modify Spec if you want to update Mould Spec only");
                return;
            }

            string checkdate = "", cav = "", weight = "", accessory = "", camera = "", length = "", width = "", height = "", instockremarks = "";

            checkdate = txtCheckdate.Text;

            if (!string.IsNullOrEmpty(txtCav.Text))
            {
                cav = txtCav.Text;
            }

            if (!string.IsNullOrEmpty(txtWeight.Text))
            {
                weight = txtWeight.Text;
            }

            if (!string.IsNullOrEmpty(txtEquipment.Text))
            {
                accessory = txtEquipment.Text;
            }

            if (!string.IsNullOrEmpty(txtShot.Text))
            {
                camera = txtShot.Text;
            }

            if (!string.IsNullOrEmpty(txtLength.Text))
            {
                length = txtLength.Text;
            }

            if (!string.IsNullOrEmpty(txtWidth.Text))
            {
                width = txtWidth.Text;
            }

            if (!string.IsNullOrEmpty(txtHeight.Text))
            {
                height = txtHeight.Text;
            }

            if (!string.IsNullOrEmpty(txtInstockRemarks.Text))
            {
                instockremarks = txtInstockRemarks.Text;
            }

            string calpo = txtPo.Text;

            int thismonth     = DateTime.Today.Month;
            int selectedmonth = dpCheckDate.Value.Month;

            /*checkdate = dpCheckDate.Value.ToString("yyyy/MM/dd");
             *
             * int result = thismonth - selectedmonth;
             *
             * if (result > 3 || result < -3)
             * {
             *  switch (MessageBox.Show("Checkdate selection out of range (+ / - 3 months). Keep modifying?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
             *  {
             *      case DialogResult.Yes:
             *
             *          break;
             *
             *      case DialogResult.No:
             *          return;
             *  }
             * }*/

            if (isRmb)
            {
                string query = string.Format("update tb_betamould set tm_instockdate50 = '{0}', tm_instockdate = '{1}', tm_checkdate = '{2}', tm_cav = '{3}'" +
                                             ", tm_weight = '{4}', tm_accessory = '{5}', tm_camera = '{6}', tm_vertical = '{7}', tm_horizontal = '{8}', tm_height = '{9}', tm_moulditemviewer = 'Yes', tm_st_code = 'PR', tm_instockremarks = '{10}'" +
                                             " where tm_po = '{11}'", instockdate50, instockdate, checkdate, cav, weight, accessory, camera, length, width, height, instockremarks, tmpPo);

                //Debug.WriteLine(query);
                DataService.GetInstance().ExecuteNonQuery(query);
            }
            else
            {
                if (inputRequired)
                {
                    if (string.IsNullOrEmpty(checkdate))
                    {
                        MessageBox.Show("檢查合格日 cannot be null");
                        return;
                    }

                    string query = string.Format("update tb_betamould set tm_instockdate50 = '{0}', tm_instockdate = '{1}', tm_checkdate = '{2}', tm_cav = '{3}'" +
                                                 ", tm_weight = '{4}', tm_accessory = '{5}', tm_camera = '{6}', tm_vertical = '{7}', tm_horizontal = '{8}', tm_height = '{9}', tm_moulditemviewer = 'Yes', tm_st_code = 'PR', tm_instockremarks = '{10}'" +
                                                 " where tm_po = '{11}'", instockdate50, instockdate, checkdate, cav, weight, accessory, camera, length, width, height, instockremarks, tmpPo);

                    DataService.GetInstance().ExecuteNonQuery(query);

                    //MessageBox.Show("Record has been saved");
                }
                else
                {
                    string type = DataChecking.getTypeByPo(calpo);

                    if (type == "New" || type == "Modify")
                    {
                        string query = string.Format("update tb_betamould set tm_instockdate50 = '{0}', tm_instockdate = '{1}', tm_checkdate = '{2}', tm_cav = '{3}'" +
                                                     ", tm_weight = '{4}', tm_accessory = '{5}', tm_camera = '{6}', tm_vertical = '{7}', tm_horizontal = '{8}', tm_height = '{9}', tm_moulditemviewer = 'Yes', tm_st_code = 'PR', tm_instockremarks = '{10}'" +
                                                     " where tm_po = '{11}'", instockdate50, instockdate, checkdate, cav, weight, accessory, camera, length, width, height, instockremarks, tmpPo);

                        DataService.GetInstance().ExecuteNonQuery(query);
                    }
                    else
                    {
                        List <string> polist = new List <string>();

                        string text = string.Format("select tm_po from tb_betamould where tm_po like '{0}%'", calpo);

                        GlobalService.reader = DataService.GetInstance().ExecuteReader(text);

                        while (GlobalService.reader.Read())
                        {
                            string po = GlobalService.reader.GetString(0);
                            polist.Add(po);
                        }
                        GlobalService.reader.Close();
                        GlobalService.reader.Dispose();

                        for (int i = 0; i < polist.Count; i++)
                        {
                            string targetpo = polist[i];

                            string query = string.Format("update tb_betamould set tm_instockdate50 = '{0}', tm_instockdate = '{1}', tm_checkdate = '{2}', tm_cav = '{3}'" +
                                                         ", tm_weight = '{4}', tm_accessory = '{5}', tm_camera = '{6}', tm_vertical = '{7}', tm_horizontal = '{8}', tm_height = '{9}', tm_instockremarks = '{10}', tm_moulditemviewer = 'Yes', tm_st_code = 'S'" +
                                                         " where tm_po = '{11}'", instockdate50, instockdate, checkdate, cav, weight, accessory, camera, length, width, height, instockremarks, targetpo);

                            DataService.GetInstance().ExecuteNonQuery(query);
                        }
                    }
                }
            }
            MessageBox.Show("Record has been saved");
            //dpCheckDate.Value = DateTime.Today;
            this.cancel();
        }
Beispiel #5
0
        private void bgworker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                DataTable tmptable = new DataTable();

                tmptable = ImportXlsUtil.TranslateToTable(filename);

                int errorcount = 1;

                List <int> indexlist = new List <int>();

                foreach (DataRow row in tmptable.Rows)
                {
                    errorcount += 1;

                    string chaseno = row.ItemArray[2].ToString();

                    Debug.WriteLine("CHASE NO" + chaseno + "ROW: " + errorcount);
                    string status = DataChecking.getStatusByChaseno(chaseno);

                    Debug.WriteLine("STATUS: " + status);

                    string p2003no      = row.ItemArray[12].ToString();
                    string p2003ans     = row.ItemArray[13].ToString();
                    string p2003result  = row.ItemArray[14].ToString();
                    string p2003updated = row.ItemArray[15].ToString();

                    string p2004no      = row.ItemArray[16].ToString();
                    string p2004ans     = row.ItemArray[17].ToString();
                    string p2004result  = row.ItemArray[18].ToString();
                    string p2004updated = row.ItemArray[19].ToString();

                    string kdcno      = row.ItemArray[20].ToString();
                    string kdcissued  = row.ItemArray[21].ToString();
                    string kdcrps     = row.ItemArray[22].ToString();
                    string kdcseisan  = row.ItemArray[23].ToString();
                    string kdcresult  = row.ItemArray[24].ToString();
                    string kdcupdated = row.ItemArray[25].ToString();

                    string assetdesc    = row.ItemArray[26].ToString();
                    string capdate      = row.ItemArray[27].ToString();
                    string acquishkd    = row.ItemArray[28].ToString();
                    string accumhkd     = row.ItemArray[29].ToString();
                    string closingmonth = row.ItemArray[30].ToString();
                    string bookhkd1     = row.ItemArray[31].ToString();
                    string fy           = row.ItemArray[32].ToString();
                    string bookhkd2     = row.ItemArray[33].ToString();
                    //string nav = row.ItemArray[33].ToString();

                    string disposalringi          = row.ItemArray[34].ToString();
                    string disposalreportno       = row.ItemArray[35].ToString();
                    string disposalreportissued   = row.ItemArray[36].ToString();
                    string disposalreportrecieved = row.ItemArray[37].ToString();
                    string vendorresult           = row.ItemArray[38].ToString();
                    string fadisposal             = row.ItemArray[39].ToString();
                    string disposalremarks        = row.ItemArray[40].ToString();

                    string query = "";

                    string disposalText = "";

                    if (status == "D1")//待廃棄 - 調整依賴中
                    {
                        if ((p2003result == "OK" || p2003result == "可") && (p2004result == "OK" || p2004result == "可"))
                        {
                            if (check2003IsValid(p2003no, p2003ans, p2003updated) && check2004IsValid(p2004no, p2004ans, p2004updated))
                            {
                                p2003updated = ImportXlsUtil.ParseDateTime(p2003updated).ToString("yyyy/MM/dd");
                                p2004updated = ImportXlsUtil.ParseDateTime(p2004updated).ToString("yyyy/MM/dd");

                                query = string.Format("update tb_betamould set tm_st_code = 'D2' where tm_chaseno = '{0}'", chaseno);

                                disposalText = string.Format("update tb_disposaldetail set dd_2003no = '{0}', dd_2003answer = '{1}', dd_2003result = '{2}'" +
                                                             ", dd_2003updated = '{3}', dd_2004no = '{4}', dd_2004answer = '{5}', dd_2004result = '{6}', dd_2004updated = '{7}', dd_disposalremarks = '{8}'  where" +
                                                             " dd_chaseno = '{9}'", p2003no, p2003ans, p2003result, p2003updated, p2004no, p2004ans, p2004result, p2004updated, disposalremarks,
                                                             chaseno);
                            }
                            else
                            {
                                indexlist.Add(errorcount);
                            }
                        }

                        if (p2003result == "不可" || p2004result == "不可")
                        {
                            query = RollBackQuery(chaseno);

                            disposalText = DeleteQuery(chaseno);
                        }
                    }

                    else if (status == "D2")//待廃棄 - 日本生産本部確認中
                    {
                        if (kdcresult == "OK" || kdcresult == "可")
                        {
                            if (checkKdcIsValid(kdcno, kdcrps, kdcseisan, kdcupdated))
                            {
                                kdcupdated = ImportXlsUtil.ParseDateTime(kdcupdated).ToString("yyyy/MM/dd");

                                string fac = DataChecking.isFixedAssetExists(chaseno) ? DataChecking.getFixedAssetCode(chaseno) : "";

                                if (fac != "")
                                {
                                    query = string.Format("update tb_betamould set tm_st_code = 'D4' where tm_chaseno = '{0}'", chaseno);
                                }
                                else
                                {
                                    query = string.Format("update tb_betamould set tm_st_code = 'D3' where tm_chaseno = '{0}'", chaseno);
                                }

                                /*disposalText = string.Format("update tb_disposaldetail set dd_kdcno = '{0}', dd_kdcrps = '{1}', dd_kdcseisan = '{2}'" +
                                 *      ", dd_kdcupdated = '{3}', dd_kdcresult = '{4}', dd_kdcissued = '{6}', dd_disposalremarks = '{7}' where dd_chaseno = '{5}'", kdcno, kdcrps, kdcseisan, kdcupdated, kdcresult, chaseno, kdcissued, disposalremarks);*/

                                disposalText = string.Format("update tb_disposaldetail set dd_kdcrps = '{0}', dd_kdcseisan = '{1}'" +
                                                             ", dd_kdcupdated = '{2}', dd_kdcresult = '{3}', dd_kdcissued = '{5}', dd_disposalremarks = '{6}' where dd_chaseno = '{4}'", kdcrps, kdcseisan, kdcupdated, kdcresult, chaseno, kdcissued, disposalremarks);
                            }
                            else
                            {
                                indexlist.Add(errorcount);
                            }
                        }

                        if (kdcresult == "不可")
                        {
                            query = RollBackQuery(chaseno);

                            disposalText = DeleteQuery(chaseno);
                        }
                    }

                    else if (status == "D3")//待廃棄 - 日本生産本部確認完了
                    {
                        disposalreportissued = ImportXlsUtil.ParseDateTime(disposalreportissued).ToString("yyyy/MM/dd");

                        //disposalreportrecieved = ImportXlsUtil.ParseDateTime(disposalreportrecieved).ToString("yyyy/MM/dd");

                        if (checkDisposalReportValid(disposalreportno, disposalreportissued))
                        {
                            query = string.Format("update tb_betamould set tm_st_code = 'D6' where tm_chaseno = '{0}'", chaseno);

                            disposalText = string.Format("update tb_disposaldetail set dd_reportno = '{0}', dd_reportissued = '{1}', dd_disposalremarks = '{3}'" +
                                                         " where dd_chaseno = '{2}'", disposalreportno, disposalreportissued, chaseno, disposalremarks);
                        }
                        else
                        {
                            indexlist.Add(errorcount);
                        }
                    }

                    else if (status == "D4")//待廃棄 - 固定資産確認
                    {
                        if (checkFaValid(assetdesc, capdate, acquishkd, accumhkd, closingmonth, bookhkd1, fy, bookhkd2))
                        {
                            capdate      = ImportXlsUtil.ParseDateTime(capdate).ToString("yyyy/MM/dd");
                            closingmonth = ImportXlsUtil.ParseDateTime(closingmonth).ToString("yyyy/MM/dd");
                            fy           = ImportXlsUtil.ParseDateTime(fy).ToString("yyyy/MM/dd");

                            if (bookhkd1 != "0" && bookhkd1 != "")
                            {
                                query = string.Format("update tb_betamould set tm_st_code = 'D5' where tm_chaseno = '{0}'", chaseno);

                                disposalText = string.Format("update tb_disposaldetail set dd_assetdesc = '{0}', dd_capdate = '{1}', dd_acquishkd = '{2}'" +
                                                             ", dd_accumhkd = '{3}', dd_closing = '{4}', dd_bookhkd = '{5}', dd_fy = '{6}', dd_bookhkd2 = '{7}', dd_disposalremarks = '{9}' where dd_chaseno = '{8}'",
                                                             assetdesc, capdate, acquishkd, accumhkd, closingmonth, bookhkd1, fy, bookhkd2, chaseno, disposalremarks);
                            }
                            else
                            {
                                if (checkDisposalReportValid(disposalreportno, disposalreportissued))
                                {
                                    disposalreportissued = ImportXlsUtil.ParseDateTime(disposalreportissued).ToString("yyyy/MM/dd");

                                    //disposalreportrecieved = ImportXlsUtil.ParseDateTime(disposalreportrecieved).ToString("yyyy/MM/dd");

                                    query = string.Format("update tb_betamould set tm_st_code = 'D6' where tm_chaseno = '{0}'", chaseno);

                                    disposalText = string.Format("update tb_disposaldetail set dd_reportno = '{0}', dd_reportissued = '{1}', dd_disposalremarks = '{3}'" +
                                                                 " where dd_chaseno = '{2}'", disposalreportno, disposalreportissued,
                                                                 chaseno, disposalremarks);
                                }
                                else
                                {
                                    indexlist.Add(errorcount);
                                }
                            }
                        }
                        else
                        {
                            indexlist.Add(errorcount);
                        }
                    }

                    else if (status == "D5")//待廃棄 - 廃棄稟議書申請
                    {
                        if (disposalringi != "")
                        {
                            if (checkRingiValid(disposalringi))
                            {
                                //disposalreportrecieved = ImportXlsUtil.ParseDateTime(disposalreportrecieved).ToString("yyyy/MM/dd");

                                //query = string.Format("update tb_betamould set tm_st_code = 'D6' where tm_chaseno = '{0}'", chaseno);

                                disposalText = string.Format("update tb_disposaldetail set dd_disposalringi = '{0}' where dd_chaseno = '{1}'", disposalringi, chaseno);

                                Debug.WriteLine("Disposal Text: " + disposalText);

                                if (checkDisposalReportValid(disposalreportno, disposalreportissued))
                                {
                                    query = string.Format("update tb_betamould set tm_st_code = 'D6' where tm_chaseno = '{0}'", chaseno);

                                    disposalText = string.Format("update tb_disposaldetail set dd_reportno = '{0}', dd_reportissued = '{1}'" +
                                                                 ", dd_disposalringi = '{2}', dd_disposalremarks = '{4}' where dd_chaseno = '{3}'", disposalreportno, disposalreportissued,
                                                                 disposalringi, chaseno, disposalremarks);
                                }
                            }
                            else
                            {
                                indexlist.Add(errorcount);
                            }
                        }
                        else
                        {
                            query = RollBackQuery(chaseno);

                            disposalText = DeleteQuery(chaseno);
                        }
                    }

                    else if (status == "D6")//待廃棄 - 廃棄報告書発行済
                    {
                        if (vendorresult == "OK" || vendorresult == "可")
                        {
                            disposalreportissued = ImportXlsUtil.ParseDateTime(disposalreportissued).ToString("yyyy/MM/dd");

                            disposalreportrecieved = ImportXlsUtil.ParseDateTime(disposalreportrecieved).ToString("yyyy/MM/dd");

                            query = string.Format("update tb_betamould set tm_st_code = 'D7' where tm_chaseno = '{0}'", chaseno);

                            disposalText = string.Format("update tb_disposaldetail set dd_reportreceived = '{0}', dd_vendorresult = '{1}', dd_disposalremarks = '{3}' where dd_chaseno = '{2}'", disposalreportrecieved, vendorresult, chaseno, disposalremarks);
                        }
                        else
                        {
                            query = RollBackQuery(chaseno);

                            disposalText = DeleteQuery(chaseno);
                        }
                    }

                    else if (status == "D7")//待廃棄 - 廃棄報告書回収済
                    {
                        string fac = DataChecking.isFixedAssetExists(chaseno) ? DataChecking.getFixedAssetCode(chaseno) : "";

                        if (fac != "")
                        {
                            if (checkFaDisposalValid(fadisposal))
                            {
                                fadisposal = ImportXlsUtil.ParseDateTime(fadisposal).ToString("yyyy/MM/dd");

                                query = string.Format("update tb_betamould set tm_st_code = 'D8' where tm_chaseno = '{0}'", chaseno);

                                disposalText = string.Format("update tb_disposaldetail set dd_fadisposaldate = '{0}', dd_disposalremarks = '{1}'" +
                                                             " where dd_chaseno = '{2}'", fadisposal, disposalremarks, chaseno);
                            }
                            else
                            {
                                indexlist.Add(errorcount);
                            }
                        }
                    }

                    else if (status == "D8")//待廃棄 - 固定資産廃棄申請済
                    {
                    }

                    else
                    {
                        indexlist.Add(errorcount);
                    }

                    if (query != "")
                    {
                        DataService.GetInstance().ExecuteNonQuery(query);
                    }

                    if (disposalText != "")
                    {
                        DataService.GetInstance().ExecuteNonQuery(disposalText);
                    }
                }

                if (indexlist.Count != 0)
                {
                    StringBuilder builder = new StringBuilder();
                    builder.AppendLine("Following rows contain invalid data");

                    for (int i = 0; i < indexlist.Count; i++)
                    {
                        int rowindex = indexlist[i];

                        builder.Append("Row: " + rowindex).AppendLine();
                    }

                    MessageBox.Show(builder + "");
                }

                else
                {
                    MessageBox.Show("Record has been saved");
                }
                //this.loadData();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message + ex.StackTrace);
                MessageBox.Show("Invalid data format in upload file");
            }
        }
Beispiel #6
0
        private void btnGo_Click(object sender, EventArgs e)
        {
            if (!DataChecking.isValidVendor(txtVendorAfter.Text))
            {
                MessageBox.Show("Invalid vendor code");
                return;
            }

            string itemcode = txtItemcode.Text;
            string rev      = txtRev.Text;
            string mouldno  = cbMouldno.SelectedItem.ToString();

            string chaseno      = DataChecking.getChaseNoByItem(itemcode, rev, mouldno);
            string fee          = txtFee.Text;
            string vendorbefore = DataChecking.getVendorByItem(itemcode, rev, mouldno);
            string vendorafter  = txtVendorAfter.Text;

            string ringi = "", fa = "";

            try
            {
                ringi = DataChecking.getRingiByItem(itemcode, rev, mouldno);
                fa    = DataChecking.getFixedAssetCode(chaseno);
            }
            catch
            {
                ringi = "";
                fa    = "";
            }

            if (string.IsNullOrEmpty(txtFee.Text) || txtFee.Text == "0")
            {
                dgvTransferPreview.Rows.Add(new object[] { chaseno, mouldno, itemcode, rev, "0", vendorbefore, vendorafter, ringi, fa });
            }
            else
            {
                if (ringiList.Count != 0)
                {
                    for (int i = 0; i < ringiList.Count; i++)
                    {
                        string ringiInList = ringiList[i].Ringi;

                        decimal balance = Convert.ToDecimal(ringiList[i].Balance);

                        decimal dFee = Convert.ToDecimal(fee);
                        if (dFee > balance)
                        {
                            availableRingi = false;
                        }

                        dgvTransferPreview.Rows.Add(new object[] { chaseno, mouldno, itemcode, rev, fee, vendorbefore, vendorafter, ringi, fa });
                    }
                }
                else
                {
                    dgvTransferPreview.Rows.Add(new object[] { chaseno, mouldno, itemcode, rev, fee, vendorbefore, vendorafter, ringi, fa });
                }
            }

            dgvTransferPreview.Sort(dgvTransferPreview.Columns[0], ListSortDirection.Ascending);
        }
        private void loadData(string chaseno)
        {
            string query = string.Format("select tm_mouldno, tm_itemcode, tm_rev" +
                                         ", tm_oemasset, tm_remarks, tm_vendor_code, tm_mouldcode_code, tm_status, tm_type, tm_owner, tm_model from tb_betamould where tm_chaseno = '{0}'", chaseno);

            Debug.WriteLine(query);
            string mouldno = "", itemcode = "", rev = "", oemasset = "", remarks = "", vendor = "", mouldcode = "", status = "", type = "", owner = "";

            GlobalService.reader = DataService.GetInstance().ExecuteReader(query);

            while (GlobalService.reader.Read())
            {
                mouldno   = GlobalService.reader.GetString(0);
                itemcode  = GlobalService.reader.GetString(1);
                rev       = GlobalService.reader.GetString(2);
                oemasset  = GlobalService.reader.GetString(3);
                remarks   = GlobalService.reader.GetString(4);
                vendor    = GlobalService.reader.GetString(5);
                mouldcode = GlobalService.reader.GetString(6);
                status    = GlobalService.reader.GetString(7);
                type      = GlobalService.reader.GetString(8);
                owner     = GlobalService.reader.GetString(9);
                gModel    = GlobalService.reader.GetString(10);
            }
            GlobalService.reader.Close();
            GlobalService.reader.Dispose();

            //if (status == "New" || status == "Modify")
            // txtDiv.Text = "Modify";

            txtDiv.Text  = "Modify";
            txtType.Text = type;

            lblChaseno.Text  = chaseno.StartsWith("CM") ? DataChecking.GetLastCnChaseNo() : DataChecking.getLastChaseNo();
            txtMouldno.Text  = mouldno;
            txtItemcode.Text = itemcode;
            txtOemasset.Text = oemasset;
            txtRemarks.Text  = remarks;

            txtVendor.Text     = vendor;
            lblVendorname.Text = DataChecking.getVendorName(vendor);
            lblGroup.Text      = DataChecking.getVendorGroup(vendor);
            lblPurchaser.Text  = DataChecking.getVendorPerson(vendor);
            lblCurrency.Text   = DataChecking.getCurrency(vendor);

            cbOwner.SelectedItem = owner;

            try
            {
                cbGroup.Items.Clear();
                string singleGroup = DataChecking.getVendorGroup(vendor);
                string text        = string.Format("select v_remarks from tb_vendor where v_code = '{0}'", vendor);

                GlobalService.reader = DataService.GetInstance().ExecuteReader(text);

                if (GlobalService.reader.HasRows)
                {
                    while (GlobalService.reader.Read())
                    {
                        remarks = GlobalService.reader.GetString(0);
                    }
                }

                GlobalService.reader.Close();
                GlobalService.reader.Dispose();

                if (remarks != "")
                {
                    string[] remark = Split(remarks);
                    foreach (string item in remark)
                    {
                        cbGroup.Items.Add(item);
                    }
                }
                else
                {
                    cbGroup.Items.Add(singleGroup);
                }

                cbGroup.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message + ex.StackTrace);
            }

            txtMouldCode.Text = mouldcode;
            this.loadMouldCode(mouldcode);
        }
Beispiel #8
0
        sendToFile()
        {
            DataTable pdfTable = new DataTable();

            pdfTable.Columns.Add("Chase No.");
            pdfTable.Columns.Add("Item Text");
            pdfTable.Columns.Add("Item Code");
            pdfTable.Columns.Add("Ringi");
            pdfTable.Columns.Add("Vendor");

            List <int> indexList = new List <int>();

            foreach (DataGridViewRow row in dgvRingiItemList.Rows)
            {
                string isSelected = row.Cells[13].FormattedValue.ToString();

                if (isSelected == "True")
                {
                    string chaseno      = row.Cells[0].Value.ToString().Trim();
                    string mouldno      = row.Cells[1].Value.ToString();
                    string rev          = row.Cells[3].Value.ToString();
                    string currency     = row.Cells[4].Value.ToString();
                    string amount       = row.Cells[5].Value.ToString();
                    string amounthkd    = row.Cells[6].Value.ToString();
                    string itemtext     = row.Cells[7].Value.ToString();
                    string itemcode     = row.Cells[2].Value.ToString();
                    string ringi        = row.Cells[9].Value.ToString();
                    string vendor       = row.Cells[8].Value.ToString();
                    string vendorname   = DataChecking.getVendorName(vendor);
                    string resultVendor = vendor + " " + vendorname;
                    string remarks      = row.Cells[12].Value.ToString();

                    string ringitext = string.Format("update tb_betamould set tm_ringi_code = '{0}', tm_modify = 'Yes', tm_ringiRemarks = '{1}' where tm_chaseno = '{2}'", ringi.Trim(), remarks, chaseno);
                    DataService.GetInstance().ExecuteNonQuery(ringitext);

                    string inserttext = string.Format("insert into tb_ringirelations (rr_chaseno, rr_mouldno, rr_itemcode, rr_rev, rr_ringi) values ('{0}', '{1}', '{2}', '{3}', '{4}')", chaseno, mouldno, itemcode, rev, ringi.Trim());
                    DataService.GetInstance().ExecuteNonQuery(inserttext);

                    string updatetext = string.Format("update tb_ringi set rg_balance = convert(decimal,rg_balance) - convert(decimal,'{0}') where rg_no = '{1}'", amounthkd, ringi.Trim());
                    DataService.GetInstance().ExecuteNonQuery(updatetext);

                    string logText = string.Format("insert into tb_log (log_module, log_fromvalue, log_tovalue, log_user, log_datetime, log_chaseno, log_message) values" +
                                                   " ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}')", "Quotation", "-", ringi, AdUtil.getUsername("kmhk.local"), DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), chaseno, "Assign Ringi");
                    DataService.GetInstance().ExecuteNonQuery(logText);

                    string delText = string.Format("delete from tb_tempringi where tmp_chaseno = '{0}'", chaseno);
                    DataService.GetInstance().ExecuteNonQuery(delText);

                    string expenseText = string.Format("update tb_expensetransfer set et_ringino = '{0}' where et_chaseno = '{1}'", ringi.Trim(), chaseno);

                    DataService.GetInstance().ExecuteNonQuery(expenseText);

                    pdfTable.Rows.Add(new object[] { chaseno, itemtext, itemcode, ringi, resultVendor });
                }
                else
                {
                    continue;
                }
            }

            foreach (DataColumn col in pdfTable.Columns)
            {
                Debug.WriteLine("Column: " + col);
            }

            foreach (DataRow row in pdfTable.Rows)
            {
                Debug.WriteLine(row.ItemArray[0].ToString() + row.ItemArray[1].ToString() + row.ItemArray[2].ToString() + row.ItemArray[3].ToString() + row.ItemArray[4].ToString());
            }
            ExportPdfUtil.ExportFixedAssetCode(pdfTable);

            Process.Start("http://km-square.km.local/kmhk-portal/General/BizSys/Lists/Fixed%20Assets%20Acquisition/NewForm.aspx?RootFolder=%2Fkmhk%2Dportal%2FGeneral%2FBizSys%2FLists%2FFixed%20Assets%20Acquisition&ContentTypeId=0x0100779070611ECD5E4AB0AE8AF49C2BA323&Source=http%3A%2F%2Fkm%2Dsquare%2Ekm%2Elocal%2Fkmhk%2Dportal%2FGeneral%2FBizSys%2FLists%2FFixed%2520Assets%2520Acquisition%2FApplication%2Easpx");

            this.loadData();
        }
Beispiel #9
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in dgvQuotationDetail.Rows)
            {
                string mouldno   = row.Cells[0].Value.ToString();
                string itemcode  = row.Cells[1].Value.ToString();
                string rev       = row.Cells[2].Value.ToString();
                string model     = row.Cells[3].Value.ToString();
                string status    = row.Cells[4].Value.ToString();
                string currency  = row.Cells[6].Value.ToString();
                string amount    = row.Cells[7].Value.ToString();
                string mpa       = row.Cells[8].FormattedValue.ToString();
                string vendor    = row.Cells[9].Value.ToString();
                string mouldcode = row.Cells[5].Value.ToString();
                string oemasset  = row.Cells[10].Value.ToString();
                string remarks   = row.Cells[11].Value.ToString();
                //string setmould = row.Cells[11].Value.ToString();
                string accountcode = row.Cells[12].Value.ToString();
                string costcentre  = row.Cells[13].Value.ToString();
                string pcs         = row.Cells[14].Value.ToString();

                string pgroup = cbGroup.SelectedItem.ToString();
                string modify = row.Cells[15].FormattedValue.ToString();

                string setitemcode = row.Cells[16].Value.ToString();

                string vnonly   = row.Cells[17].Value.ToString();
                string cnvnonly = row.Cells[18].Value.ToString();

                string owner = row.Cells[19].Value.ToString().Trim();
                string is50  = row.Cells[20].Value.ToString().Trim();

                string projecttext = itemcode + "-" + rev;
                string request     = itemcode + rev;

                string chaseno = owner == "KDTCN" ? DataChecking.GetLastCnChaseNo() : DataChecking.getLastChaseNo();

                string itemtext = "";
                string type     = "Single";

                if (!string.IsNullOrEmpty(setitemcode) && setitemcode != "" && setitemcode != "N/A")
                {
                    type = "Set";
                }

                string instockdate50 = "";

                if (mpa == "False")
                {
                    itemtext      = mouldno + "MP+" + mouldcode + "+" + status;
                    instockdate50 = "#N/A";
                }
                else
                {
                    itemtext      = mouldno + "MP+" + mouldcode + "+" + status + "*";
                    instockdate50 = "Yes";
                }

                string quantity = "";

                string qstatus  = "";
                string category = "A";

                decimal calAmount = 0;
                string  year      = DateTime.Today.ToString("yyyy");
                string  month     = DateTime.Today.ToString("MM");
                string  jpyrate   = DataChecking.getJpyRate(year, month);

                if (transferMode == "From KDC")
                {
                    calAmount = Convert.ToDecimal(amount) * Convert.ToDecimal(jpyrate);
                }
                else
                {
                    calAmount = DataChecking.amountWithRate(currency, amount);
                }

                string amounthkd = calAmount.ToString("#.##");

                quantity = Convert.ToDecimal(amounthkd) >= 10000 && mpa == "True" ? "2" : "1";

                int piece = Convert.ToInt32(pcs);

                calAmount = calAmount / piece;

                string po = "";

                decimal tax = 0;

                if (owner == "KDTCN")
                {
                    qstatus = "U";

                    amounthkd = "-";

                    double ta = Convert.ToDouble(amount);

                    category = ta >= 5000 ? "A" : "K";

                    tax = Convert.ToDecimal(ta * 0.17);
                }
                else
                {
                    if (calAmount < 10000)
                    {
                        if (calAmount == 0)
                        {
                            qstatus = "K";
                        }
                        else
                        {
                            qstatus = "U";
                        }

                        category = "K";
                    }
                    else
                    {
                        if (mouldcode.StartsWith("8") && mouldcode != "8")
                        {
                            qstatus  = "U";
                            category = "K";
                        }
                        else if (oemasset != "")
                        {
                            qstatus  = "U";
                            category = "K";
                        }
                        else
                        {
                            qstatus = "F";
                        }
                    }


                    if (status == "TM")
                    {
                        qstatus = "T";
                        if (calAmount < 10000)
                        {
                            category = "K";
                        }

                        else
                        {
                            category = "A";
                            qstatus  = "F";
                        }

                        po = chaseno.Replace("MS", "TM");
                    }
                }

                string common = "Non-Common";

                string insertText = "";

                if (accountcode == "N/A")
                {
                    accountcode = "";
                }

                if (costcentre == "N/A")
                {
                    costcentre = "";
                }

                if ((mpa == "True" || is50 == "Yes") && owner == "KDTCN")
                {
                    //double tmAmount = Convert.ToDouble(amount) / 2;
                    //double tmTax = Convert.ToDouble(tax) / 2;

                    if (!itemtext.EndsWith("*"))
                    {
                        itemtext = itemtext + "*";
                    }

                    insertText = string.Format("insert into tb_betamould (tm_chaseno, tm_mouldno, tm_itemcode, tm_rev, tm_status, tm_type, tm_currency, tm_amount, tm_amounthkd" +
                                               ", tm_mpa, tm_mouldcode_code, tm_vendor_code, tm_st_code, tm_qty, tm_itemtext, tm_projecttext, tm_request, tm_owner, tm_category, tm_indate, tm_common, tm_oemasset, tm_rm, tm_createdby, tm_model, tm_group, tm_accountcode, tm_costcentre, tm_ismodify, tm_instockdate50, tm_pcs, tm_po, tm_vnonly, tm_cnvnonly, tm_is50, tm_tax, tm_checkdate2) values" +
                                               " ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}', '{13}', '{14}', '{15}', '{16}', '{17}', '{18}', '{19}', '{20}', '{21}', N'{22}', N'{23}', '{24}', '{25}', '{26}', '{27}', '{28}', '{29}', '{30}', '{31}', '{32}', '{33}', '{34}', '{35}', '{36}')", chaseno, mouldno, itemcode, rev, status, type,
                                               currency, amount, amounthkd, mpa, mouldcode, vendor, qstatus, "1", itemtext, projecttext, request, owner, category, DateTime.Today.ToString("yyyy/MM/dd"), common, oemasset, remarks, AdUtil.getUsername("kmhk.local"), model, pgroup, accountcode, costcentre, modify, instockdate50, pcs, po, vnonly, cnvnonly, is50, tax, pgroup);
                    DataService.GetInstance().ExecuteNonQuery(insertText);

                    /*string is50ChaseNo = DataChecking.GetLastCnChaseNo();
                     *
                     * string insertText2 = string.Format("insert into tb_betamould (tm_chaseno, tm_mouldno, tm_itemcode, tm_rev, tm_status, tm_type, tm_currency, tm_amount, tm_amounthkd" +
                     *  ", tm_mpa, tm_mouldcode_code, tm_vendor_code, tm_st_code, tm_qty, tm_itemtext, tm_projecttext, tm_request, tm_owner, tm_category, tm_indate, tm_common, tm_oemasset, tm_rm, tm_createdby, tm_model, tm_group, tm_accountcode, tm_costcentre, tm_ismodify, tm_instockdate50, tm_pcs, tm_po, tm_vnonly, tm_cnvnonly, tm_is50, tm_tax, tm_checkdate2) values" +
                     *  " ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}', '{13}', '{14}', '{15}', '{16}', '{17}', '{18}', '{19}', '{20}', '{21}', N'{22}', N'{23}', '{24}', '{25}', '{26}', '{27}', '{28}', '{29}', '{30}', '{31}', '{32}', '{33}', '{34}', '{35}', '{36}')", is50ChaseNo, mouldno, itemcode, rev, status, type,
                     *  currency, tmAmount, amounthkd, mpa, mouldcode, vendor, qstatus, "1", itemtext, projecttext, request, owner, category, DateTime.Today.ToString("yyyy/MM/dd"), common, oemasset, remarks, AdUtil.getUsername("kmhk.local"), model, pgroup, accountcode, costcentre, modify, instockdate50, pcs, po, vnonly, cnvnonly, is50, tmTax, pgroup);
                     * DataService.GetInstance().ExecuteNonQuery(insertText2);*/
                }
                else
                {
                    insertText = string.Format("insert into tb_betamould (tm_chaseno, tm_mouldno, tm_itemcode, tm_rev, tm_status, tm_type, tm_currency, tm_amount, tm_amounthkd" +
                                               ", tm_mpa, tm_mouldcode_code, tm_vendor_code, tm_st_code, tm_qty, tm_itemtext, tm_projecttext, tm_request, tm_owner, tm_category, tm_indate, tm_common, tm_oemasset, tm_rm, tm_createdby, tm_model, tm_group, tm_accountcode, tm_costcentre, tm_ismodify, tm_instockdate50, tm_pcs, tm_po, tm_vnonly, tm_cnvnonly, tm_is50, tm_tax, tm_checkdate2) values" +
                                               " ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}', '{13}', '{14}', '{15}', '{16}', '{17}', '{18}', '{19}', '{20}', '{21}', N'{22}', N'{23}', '{24}', '{25}', '{26}', '{27}', '{28}', '{29}', '{30}', '{31}', '{32}', '{33}', '{34}', '{35}', '{36}')", chaseno, mouldno, itemcode, rev, status, type,
                                               currency, amount, amounthkd, mpa, mouldcode, vendor, qstatus, quantity, itemtext, projecttext, request, owner, category, DateTime.Today.ToString("yyyy/MM/dd"), common, oemasset, remarks, AdUtil.getUsername("kmhk.local"), model, pgroup, accountcode, costcentre, modify, instockdate50, pcs, po, vnonly, cnvnonly, is50, tax, pgroup);
                    DataService.GetInstance().ExecuteNonQuery(insertText);
                }

                if (!string.IsNullOrEmpty(setitemcode) && setitemcode != "" && setitemcode != "N/A")
                {
                    string setText = string.Format("if not exists (select * from tb_setcommon where sc_itemcode = '{0}' and sc_mouldno = '{1}') begin" +
                                                   " insert into tb_setcommon (sc_itemcode, sc_mouldno, sc_oldmouldno, sc_type) values ('{0}', '{1}', '{1}', 'Set') end", setitemcode, mouldno, mouldno);

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

                if (oemasset != "")
                {
                    string oemcontent = DataChecking.getOemContent(oemasset);
                    string vendorname = DataChecking.getVendorName(vendor);

                    string query = String.Format("insert into tb_expensetransfer(et_date, et_asset, et_partno, et_rev, et_mouldno, et_type, et_mouldcode, et_cur, et_amount" +
                                                 ", et_vendorcode, et_vendor, et_chaseno, et_remarks) values ('{0}', '{1}', '{2}', '{3}'" +
                                                 ", '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}')", DateTime.Today.ToString("yyyy/MM/dd"), oemcontent, itemcode,
                                                 rev, mouldno, status, mouldcode, currency, amount, vendor, vendorname, chaseno, remarks);

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

                /*if (setmould == "False")
                 * {
                 *  insertText = string.Format("insert into tb_betamould (tm_chaseno, tm_mouldno, tm_itemcode, tm_rev, tm_status, tm_type, tm_currency, tm_amount, tm_amounthkd" +
                 *      ", tm_mpa, tm_mouldcode_code, tm_vendor_code, tm_st_code, tm_qty, tm_itemtext, tm_projecttext, tm_request, tm_owner, tm_category, tm_indate, tm_common, tm_oemasset, tm_rm, tm_createdby, tm_model, tm_group, tm_accountcode, tm_costcentre) 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}')", chaseno, mouldno, itemcode, rev, status, type,
                 *      currency, amount, amounthkd, mpa, mouldcode, vendor, qstatus, quantity, itemtext, projecttext, request, owner, category, DateTime.Today.ToString("yyyy/MM/dd"), common, oemasset, remarks, AdUtil.getUsername("kmhk.local"), model, pgroup, accountcode, costcentre);
                 *  DataService.GetInstance().ExecuteNonQuery(insertText);
                 * }
                 * else
                 * {
                 *  insertText = string.Format("insert into tb_betamould (tm_chaseno, tm_mouldno, tm_itemcode, tm_rev, tm_status, tm_type, tm_currency, tm_amount, tm_amounthkd" +
                 *      ", tm_mpa, tm_mouldcode_code, tm_vendor_code, tm_st_code, tm_qty, tm_itemtext, tm_projecttext, tm_request, tm_owner, tm_category, tm_indate, tm_common, tm_oemasset, tm_rm, tm_createdby, tm_model, tm_group, tm_accountcode, tm_costcentre) 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}')", chaseno, mouldno, itemcode, rev, status, "Set",
                 *      currency, amount, amounthkd, mpa, mouldcode, vendor, qstatus, quantity, itemtext, projecttext, request, owner, category, DateTime.Today.ToString("yyyy/MM/dd"), common, oemasset, remarks, AdUtil.getUsername("kmhk.local"), model, pgroup, accountcode, costcentre);
                 *  DataService.GetInstance().ExecuteNonQuery(insertText);
                 *
                 *  string updateText = string.Format("update tb_betamould set tm_status = 'Set' where tm_mouldno = '{0}'", mouldno);
                 *  DataService.GetInstance().ExecuteNonQuery(updateText);
                 *
                 * }*/

                string logText = string.Format("insert into tb_log (log_module, log_fromvalue, log_tovalue, log_user, log_datetime, log_chaseno, log_message)" +
                                               " values ('{0}', '{1}', '{2}', N'{3}', '{4}', '{5}', '{6}')", "Quotation", "-", "-", AdUtil.getUsername("kmhk.local"), DateTime.Now.ToString("yyyy/MM/dd"), chaseno, "New Item");

                DataService.GetInstance().ExecuteNonQuery(logText);

                if (transferMode != "From Vendor")
                {
                    string tmchaseno   = chaseno.Replace("MS", "TM");
                    string ownerbefore = cbFromOwner.SelectedItem.ToString();

                    this.saveTransferHistory(mouldno, itemcode, rev, status, ownerbefore, "KDTHK", vendor, vendor, amount, tmchaseno);
                }
            }

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

            if (formClose != null)
            {
                formClose(this, new EventArgs());
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                string sourceChaseNo = lblChaseno.Text;

                string  mouldno  = txtMouldno.Text;
                string  itemcode = txtItemcode.Text;
                string  rev      = txtRev.Text;
                decimal amount   = Convert.ToDecimal(txtAmount.Text);
                string  oemasset = txtOemasset.Text;
                string  remarks  = txtRemarks.Text;
                string  pcs      = txtPcs.Text;
                string  type     = txtType.Text;
                //string owner = txtOwner.Text;
                string owner  = cbOwner.SelectedItem.ToString();
                string pgroup = cbGroup.SelectedItem.ToString();
                string vendor = txtVendor.Text;

                string mouldcode = txtMouldCode.Text;

                string model = gModel;

                if (rev.Length == 1)
                {
                    rev = "0" + rev;
                }

                string modify = "";

                if (ckbModify.Checked)
                {
                    modify = "True";
                }
                else
                {
                    modify = "False";
                }

                bool mpa;

                if (ckbMpa.Checked)
                {
                    mpa = true;
                }
                else
                {
                    mpa = false;
                }

                if (!DataChecking.isValidVendor(vendor))
                {
                    MessageBox.Show("Invalid vendor code");
                    return;
                }

                if (!DataChecking.isValidMouldCode(mouldcode))
                {
                    MessageBox.Show("Invalid mould code");
                    return;
                }

                string curr = "";

                string year    = DateTime.Today.ToString("yyyy");
                string month   = DateTime.Today.ToString("MM");
                string jpyrate = DataChecking.getJpyRate(year, month);

                if (lblCurrency.Text.Contains("JPY"))
                {
                    curr = "JPY";
                }
                else
                {
                    curr = DataChecking.getCurrency(vendor);
                }

                decimal calAmount = 0;

                if (lblCurrency.Text.Contains("JPY"))
                {
                    calAmount = Convert.ToDecimal(amount) * Convert.ToDecimal(jpyrate);
                }
                else
                {
                    calAmount = DataChecking.amountWithRate(curr, amount.ToString());
                }

                string itemtext = "";

                if (!mpa)
                {
                    itemtext = mouldno + "MP+" + mouldcode + "+Modify";
                }
                else
                {
                    itemtext = mouldno + "MP+" + mouldcode + "+Modify*";
                }

                string projecttext = itemcode + "-" + rev;
                string request     = itemcode + rev;

                decimal tmpAmount = amount / Convert.ToInt32(pcs);

                //string currency = DataChecking.getCurrency(vendor);

                //string common = DataChecking.getCommon(mouldno, itemcode);
                string common = DataChecking.getCommonByMouldNo(mouldno);

                string quantity = "";

                calAmount = calAmount / Convert.ToInt32(pcs);

                string amounthkd = calAmount.ToString("#.##");

                quantity = Convert.ToDecimal(amounthkd) >= 10000 && mpa ? "2" : "1";

                string qstatus  = "";
                string category = "A";

                decimal tax = 0;

                string chaseno = sourceChaseNo.StartsWith("CM") ? DataChecking.GetLastCnChaseNo() : DataChecking.getLastChaseNo();

                string accountcode = sourceChaseNo.StartsWith("CM") ? "" : "5005020002";
                string costcentre  = sourceChaseNo.StartsWith("CM") ? "" : "1404000029";

                if (sourceChaseNo.StartsWith("CM"))
                {
                    qstatus = "U";

                    amounthkd = "-";

                    double ta = Convert.ToDouble(amount);

                    category = ta >= 5000 ? "A" : "K";

                    tax = Convert.ToDecimal(ta * 0.17);
                }
                else
                {
                    if (calAmount < 10000)
                    {
                        if (calAmount == 0)
                        {
                            qstatus = "K";
                        }
                        else
                        {
                            qstatus = "U";
                        }

                        category = "K";
                    }
                    else
                    {
                        if (mouldcode.StartsWith("8") && mouldcode != "8")
                        {
                            qstatus  = "U";
                            category = "K";
                        }
                        else if (oemasset != "")
                        {
                            qstatus  = "U";
                            category = "K";
                        }
                        else
                        {
                            qstatus     = "F";
                            accountcode = "";
                            costcentre  = "";
                            category    = "A";
                        }
                    }
                }

                if (oemasset != "")
                {
                    if (oemasset.Length == 1)
                    {
                        oemasset = "0" + oemasset;
                    }

                    if (!DataChecking.validOem(oemasset))
                    {
                        MessageBox.Show("Invalid OEM");
                        return;
                    }

                    accountcode = DataChecking.getAccountCode(oemasset);
                    costcentre  = DataChecking.getCostCentre(oemasset);
                }

                //string model = itemcode.Substring(2, 3);

                string insertText = string.Format("insert into tb_betamould (tm_chaseno, tm_mouldno, tm_itemcode, tm_rev, tm_status, tm_type, tm_currency, tm_amount, tm_amounthkd" +
                                                  ", tm_mpa, tm_mouldcode_code, tm_vendor_code, tm_st_code, tm_qty, tm_itemtext, tm_projecttext, tm_request, tm_owner, tm_category, tm_indate, tm_common, tm_oemasset, tm_rm, tm_createdby, tm_model, tm_group, tm_accountcode, tm_costcentre, tm_ismodify, tm_pcs) values" +
                                                  " ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}', '{13}', '{14}', '{15}', '{16}', '{17}', '{18}', '{19}', '{20}', '{21}', N'{22}', N'{23}', '{24}', '{25}', '{26}', '{27}', '{28}', '{29}')", chaseno, mouldno, itemcode, rev, "Modify", type,
                                                  curr, amount, amounthkd, mpa, mouldcode, vendor, qstatus, quantity, itemtext, projecttext, request, owner, category, DateTime.Today.ToString("yyyy/MM/dd"), common, oemasset, remarks, AdUtil.getUsername("kmhk.local"), model, pgroup, accountcode, costcentre, modify, pcs);
                DataService.GetInstance().ExecuteNonQuery(insertText);

                string logText = string.Format("insert into tb_log (log_module, log_fromvalue, log_tovalue, log_user, log_datetime, log_chaseno, log_message)" +
                                               " values ('{0}', '{1}', '{2}', N'{3}', '{4}', '{5}', '{6}')", "Quotation", "-", "-", AdUtil.getUsername("kmhk.local"), DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), chaseno, "Modify Item");

                DataService.GetInstance().ExecuteNonQuery(logText);

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

                if (formClose != null)
                {
                    formClose(this, new EventArgs());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
            }
        }
Beispiel #11
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            errInput.Clear();

            if (string.IsNullOrEmpty(txtNew.Text))
            {
                errInput.SetError(txtNew, "Please enter the number of items");
                return;
            }

            if (string.IsNullOrEmpty(txtModify.Text))
            {
                errInput.SetError(txtModify, "Please enter the number of items");
                return;
            }

            int number       = Convert.ToInt32(txtNew.Text);
            int modifynumber = Convert.ToInt32(txtModify.Text);

            string itemcode = txtPartno.Text;
            string rev      = txtRev.Text;
            string vendor   = txtVendor.Text;
            string mouldno  = "";
            string oemasset = txtOemAsset.Text;
            string remarks  = txtRemarks.Text;
            string pcs      = txtPcs.Text;

            string model = "";

            string accountcode = "";

            string costcentre = "";

            if (itemcode.Length == 12 || itemcode.Length == 15)
            {
                if (string.IsNullOrEmpty(txtModel.Text))
                {
                    MessageBox.Show("Please input Model");
                    return;
                }
                model = txtModel.Text;
            }
            else if (itemcode.Length == 8)
            {
                model = itemcode.Substring(0, 3);
            }

            else
            {
                if (itemcode.StartsWith("1"))
                {
                    model = itemcode.Substring(3, 3);
                }
                else
                {
                    model = itemcode.Substring(2, 3);
                }
            }

            if (!DataChecking.isValidVendor(vendor))
            {
                errInput.SetError(txtVendor, "Invalid Vendor Code");
                return;
            }

            if (cbGroup.SelectedItem == null)
            {
                errInput.SetError(cbGroup, "Please select a group first");
                return;
            }

            if (itemcode.Length != 8 && itemcode.Length != 10 && itemcode.Length != 12 && itemcode.Length != 15)
            {
                errInput.SetError(txtPartno, "Item Code length must be 8 / 10 / 12 / 15 digits");
                return;
            }

            string owner = rbtnKDTHK.Checked ? "KDTHK" : "KDTCN";

            if (oemasset != "")
            {
                if (oemasset.Length == 1)
                {
                    oemasset = "0" + oemasset;
                }

                if (!DataChecking.validOem(oemasset))
                {
                    errInput.SetError(txtOemAsset, "Invalid OEM");
                    return;
                }

                accountcode = DataChecking.getAccountCode(oemasset);

                costcentre = DataChecking.getCostCentre(oemasset);
            }

            string setitemcode = "N/A";

            if (!string.IsNullOrEmpty(txtItemcodeSet.Text))
            {
                setitemcode = txtItemcodeSet.Text;
            }

            if (rev.Length == 1)
            {
                rev = "0" + rev;
            }

            string fromOwner = "";

            if (cbFromOwner.SelectedIndex == 0)
            {
                fromOwner = "From Vendor";
            }
            else if (cbFromOwner.SelectedIndex == 1)
            {
                fromOwner = "From KDC";
            }
            else if (cbFromOwner.SelectedIndex == 2)
            {
                fromOwner = "From KDTCN";
            }
            else if (cbFromOwner.SelectedIndex == 3)
            {
                fromOwner = "From KDTVN";
            }

            transferMode = fromOwner;

            string currency = "";

            string tmpMould = "";

            if (fromOwner == "From KDC")
            {
                currency = "JPY";
            }
            else
            {
                currency = DataChecking.getCurrency(vendor);
            }

            string ismodify = "False";

            if (ckbIsModify.Checked)
            {
                ismodify = "True";
            }

            string vnonly = cbProductionBase.SelectedIndex == 2 ? "True" : "False";

            string cnvnonly = cbProductionBase.SelectedIndex == 1 ? "True" : "False";



            if (number != 0)
            {
                if (!DataChecking.isItemCodeExists2(itemcode))
                {
                    tmpMould = "K" + itemcode + "01";
                }
                else
                {
                    tmpMould = "K" + itemcode + DataChecking.getLastThree2(itemcode);
                }

                if (transferMode == "From Vendor")
                {
                    dgvQuotationDetail.Rows.Add(new object[] { tmpMould, itemcode, rev, model, "New", "", currency, "0", "False", vendor, oemasset, remarks, accountcode, costcentre, pcs, ismodify, setitemcode, vnonly, cnvnonly, owner, "No" });
                }
                else
                {
                    dgvQuotationDetail.Rows.Add(new object[] { tmpMould, itemcode, rev, model, "TM", "", currency, "0", "False", vendor, oemasset, remarks, accountcode, costcentre, pcs, ismodify, setitemcode, vnonly, cnvnonly, owner, "No" });
                }

                if (number > 1)
                {
                    for (int i = 1; i < number; i++)
                    {
                        int    rowindex = dgvQuotationDetail.Rows.Count - 1;
                        string rowMould = dgvQuotationDetail.Rows[rowindex].Cells[0].Value.ToString();
                        int    mId      = Convert.ToInt32(rowMould.Substring(rowMould.Length - 2));
                        int    cMid     = mId + 1;
                        string result   = cMid.ToString("00");
                        mouldno = "K" + itemcode + result;

                        if (transferMode == "From Vendor")
                        {
                            dgvQuotationDetail.Rows.Add(new object[] { mouldno, itemcode, rev, model, "New", "", currency, "0", "False", vendor, oemasset, remarks, accountcode, costcentre, pcs, ismodify, setitemcode, vnonly, cnvnonly, owner, "No" });
                        }
                        else
                        {
                            dgvQuotationDetail.Rows.Add(new object[] { mouldno, itemcode, rev, model, "TM", "", currency, "0", "False", vendor, oemasset, remarks, accountcode, costcentre, pcs, ismodify, setitemcode, vnonly, cnvnonly, owner, "No" });
                        }
                    }
                }

                if (modifynumber != 0)
                {
                    if (!DataChecking.isItemCodeExists(txtPartno.Text))
                    {
                        MessageBox.Show("Item Code: " + txtPartno.Text + " does not exist");
                        return;
                    }
                    if (modifynumber == 1)
                    {
                        dgvQuotationDetail.Rows.Add(new object[] { "", itemcode, rev, model, "Modify", "", currency, "0", "False", vendor, oemasset, remarks, accountcode, costcentre, pcs, ismodify, setitemcode, vnonly, cnvnonly, owner, "No" });
                    }
                    else
                    {
                        for (int i = 0; i < modifynumber; i++)
                        {
                            dgvQuotationDetail.Rows.Add(new object[] { "", itemcode, rev, model, "Modify", "", currency, "0", "False", vendor, oemasset, remarks, accountcode, costcentre, pcs, ismodify, setitemcode, vnonly, cnvnonly, owner, "No" });
                        }
                    }
                }
                dgvQuotationDetail.CurrentCell = dgvQuotationDetail.Rows[0].Cells[5];
                dgvQuotationDetail.BeginEdit(true);

                lblMsg.Text = dgvQuotationDetail.Rows.Count.ToString();

                this.btnCheckTotal.Enabled = true;
                this.btnValidate.Enabled   = true;
            }
        }
Beispiel #12
0
        private void btnValidate_Click(object sender, EventArgs e)
        {
            bool validInput     = true;
            bool validAmount    = true;
            bool validMouldCode = true;

            bool isSetMould = false;

            List <int> indexList = new List <int>();
            List <int> setList   = new List <int>();

            Regex amountEx = new Regex(@"^[0-9]*(\.[0-9]{1,2})?$");

            foreach (DataGridViewRow row in dgvQuotationDetail.Rows)
            {
                row.DefaultCellStyle.BackColor = SystemColors.ControlLightLight;
                row.DefaultCellStyle.ForeColor = Color.Black;

                string mouldno   = row.Cells[0].Value.ToString();
                string itemcode  = row.Cells[1].Value.ToString();
                string rev       = row.Cells[2].Value.ToString();
                string currency  = row.Cells[6].Value.ToString();
                string amount    = row.Cells[7].Value.ToString();
                string mpa       = row.Cells[8].FormattedValue.ToString();
                string vendor    = row.Cells[9].Value.ToString();
                string mouldcode = "";

                //string setmould = row.Cells[11].FormattedValue.ToString();

                string accountcode = row.Cells[12].Value.ToString();
                string costcentre  = row.Cells[13].Value.ToString();

                if (!validPrice(amount))
                {
                    validAmount = false;
                    indexList.Add(row.Index);
                }
                if (row.Cells[5].Value == null)
                {
                    mouldcode = "";
                }
                else
                {
                    mouldcode = row.Cells[5].Value.ToString();
                }

                if (!DataChecking.isValidMouldCode(mouldcode))
                {
                    validMouldCode = false;
                    indexList.Add(row.Index);
                }

                /*if (setmould == "True")
                 * {
                 *  setList.Add(row.Index);
                 *  isSetMould = true;
                 * }*/
            }
            indexList = indexList.Distinct().ToList();

            if (!validAmount)
            {
                MessageBox.Show("Invalid Amount Format found. Please check.");
            }

            if (!validMouldCode)
            {
                MessageBox.Show("Invalid Mould Code found. Please check.");
            }

            for (int i = 0; i < indexList.Count; i++)
            {
                int rowIndex = indexList[i];

                dgvQuotationDetail.Rows[rowIndex].DefaultCellStyle.BackColor = Color.Red;
                dgvQuotationDetail.Rows[rowIndex].DefaultCellStyle.ForeColor = Color.White;
            }

            for (int k = 0; k < setList.Count; k++)
            {
                int rowIndex = setList[k];
                dgvQuotationDetail.Rows[rowIndex].Cells[0].Style.BackColor = Color.Yellow;
                dgvQuotationDetail.Rows[rowIndex].Cells[0].Style.ForeColor = Color.Black;
            }

            if (isSetMould)
            {
                MessageBox.Show("Please check and make sure the Set Mould No. is correct.");
            }

            if (validAmount && validMouldCode)
            {
                validInput = true;
            }
            else
            {
                validInput = false;
            }

            lblMsg.Visible = true;

            if (validInput)
            {
                lblMsg.Text      = "PASSED";
                lblMsg.ForeColor = Color.Green;
                btnSave.Enabled  = true;
            }
            else
            {
                lblMsg.Text      = "WARNING";
                lblMsg.ForeColor = Color.Red;
                btnSave.Enabled  = false;
            }

            canSave = validInput;
        }
Beispiel #13
0
        private void btnCheck_Click(object sender, EventArgs e)
        {
            decimal amount      = 0;
            decimal totalAmount = 0;
            decimal usdAmount   = 0;
            decimal usdTotal    = 0;
            decimal jpyAmount   = 0;
            decimal jpyTotal    = 0;
            decimal rmbAmount   = 0;
            decimal rmbTotal    = 0;

            string year  = DateTime.Today.ToString("yyyy");
            string month = DateTime.Today.ToString("MM");

            string jpyrate = DataChecking.getJpyRate(year, month);

            bool isAmountOver = false;

            List <OverCostData> overList = new List <OverCostData>();

            List <QuotationData> quoList = new List <QuotationData>();

            foreach (DataGridViewRow row in dgvQuotationDetail.Rows)
            {
                string partno   = row.Cells[1].Value.ToString();
                string rev      = row.Cells[2].Value.ToString();
                string currency = row.Cells[6].Value.ToString();
                string camount  = row.Cells[7].Value.ToString();

                if (currency == "USD")
                {
                    usdAmount = Convert.ToDecimal(row.Cells[7].Value);
                    usdTotal  = usdTotal + usdAmount;

                    amount      = DataChecking.amountWithRate(row.Cells[6].Value.ToString(), row.Cells[7].Value.ToString());
                    totalAmount = totalAmount + amount;
                }
                else if (currency == "JPY")
                {
                    jpyAmount = Convert.ToDecimal(row.Cells[7].Value);
                    jpyTotal  = jpyTotal + jpyAmount;

                    amount      = Convert.ToDecimal(row.Cells[7].Value) * Convert.ToDecimal(jpyrate);
                    totalAmount = totalAmount + amount;
                }
                else if (currency == "HKD")
                {
                    amount      = DataChecking.amountWithRate(row.Cells[6].Value.ToString(), row.Cells[7].Value.ToString());
                    totalAmount = totalAmount + amount;
                }

                else if (currency == "RMB")
                {
                    rmbAmount = Convert.ToDecimal(row.Cells[7].Value);
                    rmbTotal  = rmbTotal + rmbAmount;
                }

                string mouldcode = row.Cells[5].Value.ToString();

                string oem = row.Cells[10].Value.ToString();

                string pcs = row.Cells[14].Value.ToString();

                amount = amount / Convert.ToInt32(pcs);


                if (oem != "")
                {
                    row.Cells[12].Value = DataChecking.getAccountCode(oem);
                    row.Cells[13].Value = DataChecking.getCostCentre(oem);
                }
                else
                {
                    if (currency != "RMB")
                    {
                        if (amount < 10000 || mouldcode.StartsWith("8") && mouldcode != "8")
                        {
                            row.Cells[12].Value = "5005020002";
                            row.Cells[13].Value = "1404000029";
                        }
                    }
                }

                quoList.Add(new QuotationData {
                    PartNo = partno, Rev = rev, Currency = currency, Amount = Convert.ToDouble(camount)
                });
            }

            var sumList = from l in quoList
                          group l by new
            {
                l.PartNo,
                l.Rev,
                l.Currency,
            } into g
                select new QuotationData()
            {
                PartNo   = g.Key.PartNo,
                Rev      = g.Key.Rev,
                Currency = g.Key.Currency,
                Amount   = g.Sum(x => Convert.ToDouble(x.Amount))
            };

            foreach (var item in sumList)
            {
                if (IsPriceOverCost(item.PartNo, item.Rev, item.Currency, item.Amount.ToString()))
                {
                    overList.Add(new OverCostData {
                        PartNo = item.PartNo, Amount = item.Amount.ToString()
                    });
                    isAmountOver = true;
                }
            }

            if (isAmountOver)
            {
                string items = "";

                foreach (OverCostData item in overList)
                {
                    items = items + item.PartNo + "  Amount: " + item.Amount + "\n";
                    foreach (DataGridViewRow row in dgvQuotationDetail.Rows)
                    {
                        if (row.Cells[1].Value.ToString() == item.PartNo)
                        {
                            row.DefaultCellStyle.BackColor = Color.Red;
                            row.DefaultCellStyle.ForeColor = Color.White;
                        }
                    }
                }

                MessageBox.Show("Below items over cost.\n\n" + items);
            }

            lblJpy.Text = jpyTotal.ToString("#.##");
            lblHkd.Text = totalAmount.ToString("#.##");
            lblUsd.Text = usdTotal.ToString("#.##");
            lblRmb.Text = rmbTotal.ToString("#.##") + " (" + ((double)rmbTotal * 0.17).ToString("#.##") + ")";
        }
        private void loadData(int id)
        {
            try
            {
                string currentStatus = "";
                string mouldcurr     = "";
                string calFa         = "";

                string query = string.Format("select tm_chaseno, tm_mouldno, tm_itemcode, tm_rev, tm_status, tm_amount, tm_itemtext, tm_mpa" +
                                             ", tm_oemasset, tm_rm, tm_fixedassetcode, tm_ringi_code, tm_vendor_code, tm_mouldcode_code, tm_st_code, tm_pcs, tm_model, tm_ismodify, tm_currency, tm_category, tm_vnonly, tm_cnvnonly from tb_betamould where tm_id = '{0}'", id);

                GlobalService.reader = DataService.GetInstance().ExecuteReader(query);

                while (GlobalService.reader.Read())
                {
                    lblChaseno.Text = GlobalService.reader.GetString(0);
                    txtMouldno.Text = GlobalService.reader.GetString(1);
                    oMouldno        = txtMouldno.Text;

                    txtItemcode.Text = GlobalService.reader.GetString(2);
                    oItemCode        = txtItemcode.Text;

                    txtRev.Text = GlobalService.reader.GetString(3);
                    oRev        = txtRev.Text;

                    cbDiv.SelectedItem = GlobalService.reader.GetString(4);
                    oStatus            = cbDiv.SelectedItem.ToString();

                    txtAmount.Text = GlobalService.reader.GetString(5);
                    oAmount        = txtAmount.Text;

                    txtItemText.Text = GlobalService.reader.GetString(6);
                    oItemText        = txtItemText.Text;

                    string mpa = GlobalService.reader.GetString(7);
                    if (mpa == "True")
                    {
                        ckbMpa.Checked = true;
                    }
                    else
                    {
                        ckbMpa.Checked = false;
                    }
                    oMpa = mpa;

                    txtOemasset.Text = GlobalService.reader.GetString(8);
                    oOemAsset        = txtOemasset.Text;

                    txtRemarks.Text = GlobalService.reader.GetString(9);
                    oRemarks        = txtRemarks.Text;

                    string fa = GlobalService.reader.GetString(10);
                    calFa = fa;

                    if (fa == "")
                    {
                        lblFa.Text = "N/A";
                    }
                    else
                    {
                        lblFa.Text = fa;
                    }

                    string rin = GlobalService.reader.GetString(11);
                    if (rin == "")
                    {
                        lblRingi.Text = "N/A";
                    }
                    else
                    {
                        lblRingi.Text = rin;
                    }

                    txtVendor.Text = GlobalService.reader.GetString(12);
                    oVendor        = txtVendor.Text;

                    txtMouldCode.Text = GlobalService.reader.GetString(13);
                    oMouldCode        = txtMouldCode.Text;

                    currentStatus = GlobalService.reader.GetString(14);

                    txtPcs.Text = GlobalService.reader.GetString(15);

                    txtModel.Text = GlobalService.reader.GetString(16);

                    string ismodify = GlobalService.reader.GetString(17);

                    mouldcurr = GlobalService.reader.GetString(18);

                    globalCategory = GlobalService.reader.GetString(19);

                    string vnonly = GlobalService.reader.GetString(20);

                    string cnvnonly = GlobalService.reader.GetString(21);

                    if (vnonly == "True")
                    {
                        cbProductionBase.SelectedIndex = 2;
                    }
                    else if (cnvnonly == "True")
                    {
                        cbProductionBase.SelectedIndex = 1;
                    }
                    else
                    {
                        cbProductionBase.SelectedIndex = 0;
                    }

                    if (ismodify == "True")
                    {
                        ckbModify.Checked = true;
                    }
                    else
                    {
                        ckbModify.Checked = false;
                    }
                }
                GlobalService.reader.Close();
                GlobalService.reader.Dispose();

                Debug.WriteLine(currentStatus);

                modifyInStock = false;

                globalStatus = currentStatus;

                if (currentStatus == "Q" || currentStatus == "U" || currentStatus == "F" || currentStatus == "T")
                {
                    this.btnSave.Enabled = true;
                    pbEdit.Image         = Properties.Resources.tick_icon;
                }
                else if (currentStatus == "P" || currentStatus == "D")
                {
                    if (calFa == "")
                    {
                        this.btnSave.Enabled = true;
                        pbEdit.Image         = Properties.Resources.tick_icon;
                    }
                    else
                    {
                        this.btnSave.Enabled = false;
                        pbEdit.Image         = Properties.Resources.cross_icon;
                    }
                }
                else if (currentStatus == "K")
                {
                    foreach (Control control in groupBox1.Controls)
                    {
                        control.Enabled = false;
                    }

                    modifyInStock = true;

                    txtRemarks.Enabled = true;
                    txtModel.Enabled   = true;
                    ckbModify.Enabled  = true;
                    cbGroup.Enabled    = true;

                    lblOem.Enabled      = true;
                    txtOemasset.Enabled = true;

                    lblIsModify.Enabled    = true;
                    lblModel.Enabled       = true;
                    lblVendorGroup.Enabled = true;
                    lblRemarks.Enabled     = true;

                    lblVnOnly.Enabled        = true;
                    ckbVn.Enabled            = true;
                    cbProductionBase.Enabled = true;

                    this.btnSave.Enabled = true;
                    pbEdit.Image         = Properties.Resources.tick_icon;
                }
                else if (currentStatus == "S")
                {
                    foreach (Control control in groupBox1.Controls)
                    {
                        control.Enabled = false;
                    }

                    modifyInStock = true;

                    txtRemarks.Enabled = true;
                    ckbModify.Enabled  = true;
                    txtModel.Enabled   = true;
                    cbGroup.Enabled    = true;

                    lblOem.Enabled      = true;
                    txtOemasset.Enabled = true;

                    lblIsModify.Enabled    = true;
                    lblModel.Enabled       = true;
                    lblVendorGroup.Enabled = true;
                    lblRemarks.Enabled     = true;

                    lblVnOnly.Enabled        = true;
                    ckbVn.Enabled            = true;
                    cbProductionBase.Enabled = true;

                    this.btnSave.Enabled = true;
                    pbEdit.Image         = Properties.Resources.tick_icon;
                }
                else
                {
                    this.btnSave.Enabled = false;
                    pbEdit.Image         = Properties.Resources.cross_icon;
                }

                lblStatus.Text = DataChecking.getCurrentStatus(currentStatus);

                lblVendorname.Text = DataChecking.getVendorName(txtVendor.Text);
                lblGroup.Text      = DataChecking.getVendorGroup(txtVendor.Text);
                lblPurchaser.Text  = DataChecking.getVendorPerson(txtVendor.Text);
                lblCurrency.Text   = DataChecking.getCurrency(txtVendor.Text);

                if (mouldcurr == "JPY")
                {
                    lblCurrency.Text = lblCurrency.Text + "(Transfer Curr: JPY)";
                }

                this.loadMouldCode(txtMouldCode.Text);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message + ex.StackTrace);
            }

            try
            {
                cbGroup.Items.Clear();
                string singleGroup = DataChecking.getVendorGroup(txtVendor.Text);
                string text        = string.Format("select v_remarks from tb_vendor where v_code = '{0}'", txtVendor.Text);

                GlobalService.reader = DataService.GetInstance().ExecuteReader(text);

                string remarks = "";

                if (GlobalService.reader.HasRows)
                {
                    while (GlobalService.reader.Read())
                    {
                        remarks = GlobalService.reader.GetString(0);
                    }
                }

                GlobalService.reader.Close();
                GlobalService.reader.Dispose();

                if (remarks != "")
                {
                    string[] remark = Split(remarks);
                    foreach (string item in remark)
                    {
                        cbGroup.Items.Add(item);
                    }
                }
                else
                {
                    cbGroup.Items.Add(singleGroup);
                }
                cbGroup.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message + ex.StackTrace);
            }
        }
        private void RollBack2()
        {
            string po = txtPO.Text;

            if (!IsPOExist(po))
            {
                MessageBox.Show("PO does not exist.");
                return;
            }

            if (!IsPOInStock(po))
            {
                MessageBox.Show("PO : " + po + " does not in In-Stock status.");
                return;
            }

            string query = "";

            if (rbtnK.Checked)
            {
                query = string.Format("update tb_betamould set tm_st_code = 'K', tm_instockdate = '#N/A', tm_instockdate50 = case when tm_mpa = 'True' then 'Yes' else '#N/A' end where tm_po = '{0}'", po);
                DataService.GetInstance().ExecuteNonQuery(query);

                string chaseno = DataChecking.GetChaseNoByPO(po);

                string logText = string.Format("insert into tb_log (log_module, log_fromvalue, log_tovalue, log_user, log_datetime, log_chaseno, log_message)" +
                                               " values ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}')", "In Stock", "-", "-", AdUtil.getUsername("kmhk.local"), DateTime.Now.ToString("yyyy/MM/dd"), chaseno, "Roll Back");

                DataService.GetInstance().ExecuteNonQuery(logText);

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

            else if (rbtnPRpass.Checked)
            {
                query = string.Format("update tb_betamould set tm_st_code = 'PR', tm_instockdate = 'Received', tm_instockdate50 = N'一回合格入庫' where tm_po = '{0}'", po);
                DataService.GetInstance().ExecuteNonQuery(query);

                string chaseno = DataChecking.GetChaseNoByPO(po);

                string logText = string.Format("insert into tb_log (log_module, log_fromvalue, log_tovalue, log_user, log_datetime, log_chaseno, log_message)" +
                                               " values ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}')", "In Stock", "-", "-", AdUtil.getUsername("kmhk.local"), DateTime.Now.ToString("yyyy/MM/dd"), chaseno, "Roll Back");

                DataService.GetInstance().ExecuteNonQuery(logText);

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

            else if (rbtnPRfail.Checked)
            {
                query = string.Format("update tb_betamould set tm_st_code = 'PR', tm_instockdate = '#N/A', tm_instockdate50 = 'Received' where tm_po = '{0}'", po);
                DataService.GetInstance().ExecuteNonQuery(query);

                string chaseno = DataChecking.GetChaseNoByPO(po);

                string logText = string.Format("insert into tb_log (log_module, log_fromvalue, log_tovalue, log_user, log_datetime, log_chaseno, log_message)" +
                                               " values ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}')", "In Stock", "-", "-", AdUtil.getUsername("kmhk.local"), DateTime.Now.ToString("yyyy/MM/dd"), chaseno, "Roll Back");

                DataService.GetInstance().ExecuteNonQuery(logText);

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

            else if (rbtnHS.Checked)
            {
                query = string.Format("update tb_betamould set tm_st_code = 'HS', tm_instockdate = '#N/A' where tm_po = '{0}'", po);
                DataService.GetInstance().ExecuteNonQuery(query);

                string chaseno = DataChecking.GetChaseNoByPO(po);

                string logText = string.Format("insert into tb_log (log_module, log_fromvalue, log_tovalue, log_user, log_datetime, log_chaseno, log_message)" +
                                               " values ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}')", "In Stock", "-", "-", AdUtil.getUsername("kmhk.local"), DateTime.Now.ToString("yyyy/MM/dd"), chaseno, "Roll Back");

                DataService.GetInstance().ExecuteNonQuery(logText);

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

            else
            {
                MessageBox.Show("Please select one of the option");
                return;
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            string _chaseno = lblChaseno.Text.Trim();

            if (_chaseno.StartsWith("CM"))
            {
                string mouldno   = txtMouldno.Text.Trim();
                string partno    = txtItemcode.Text.Trim();
                string rev       = txtRev.Text.Trim();
                string div       = cbDiv.SelectedItem.ToString();
                string model     = txtModel.Text.Trim();
                string amount    = txtAmount.Text.Trim();
                string itemtext  = txtItemText.Text.Trim();
                string mpa       = ckbMpa.Checked ? "True" : "False";
                string remarks   = txtRemarks.Text.Trim();
                string pcs       = txtPcs.Text.Trim();
                string vendor    = txtVendor.Text.Trim();
                string group     = cbGroup.SelectedItem.ToString();
                string mouldcode = txtMouldCode.Text.Trim();
                string quantity  = mpa == "True"?"2":"1";
                double camount   = Convert.ToDouble(amount);
                string category  = camount >= 5000 ? "A" : "K";

                string query = string.Format("update tb_betamould set tm_mouldno = '{0}', tm_itemcode = '{1}', tm_rev = '{2}', tm_status = '{3}', tm_model = '{4}', tm_amount = '{5}'" +
                                             ", tm_itemtext = '{6}', tm_mpa = '{7}', tm_rm = N'{8}', tm_pcs = '{9}', tm_vendor_code = '{10}', tm_group = '{11}', tm_mouldcode_code = '{12}', tm_qty = '{13}', tm_category = '{14}'" +
                                             " where tm_chaseno = '{15}'", mouldno, partno, rev, div, model, amount, itemtext, mpa, remarks, pcs, vendor, group, mouldcode, quantity, category, _chaseno);
                DataService.GetInstance().ExecuteNonQuery(query);
            }
            else
            {
                if (!modifyInStock)
                {
                    string currentStatus = "";

                    string chaseno  = lblChaseno.Text;
                    string mouldno  = txtMouldno.Text;
                    string itemcode = txtItemcode.Text;
                    string rev      = txtRev.Text;
                    string status   = cbDiv.SelectedItem.ToString();
                    string amount   = txtAmount.Text;
                    string mpa      = "False";
                    if (ckbMpa.Checked)
                    {
                        mpa = "True";
                    }

                    string itemtext = "";

                    string projecttext = itemcode + "-" + rev;
                    string request     = itemcode + rev;
                    string vendor      = txtVendor.Text;
                    string mouldcode   = txtMouldCode.Text;

                    string category = "";
                    string quantity = "1";

                    string currency = "";

                    string pcs = txtPcs.Text;

                    string oemasset = txtOemasset.Text;
                    string remarks  = txtRemarks.Text;

                    string group = cbGroup.SelectedItem.ToString();

                    string instockdate50 = "";

                    string ismodify = "";

                    if (ckbModify.Checked)
                    {
                        ismodify = "True";
                    }
                    else
                    {
                        ismodify = "False";
                    }

                    string vnonly = cbProductionBase.SelectedIndex == 2 ? "True" : "False";

                    string cnvnonly = cbProductionBase.SelectedIndex == 1 ? "True" : "False";

                    string model = txtModel.Text;

                    bool validMouldCode = true;

                    if (mouldcode != "")
                    {
                        if (!DataChecking.isValidMouldCode(mouldcode))
                        {
                            validMouldCode = false;
                        }
                        else
                        {
                            if (mpa == "False")
                            {
                                itemtext      = mouldno + "MP+" + mouldcode + "+" + status;
                                instockdate50 = "#N/A";
                            }
                            else
                            {
                                itemtext      = mouldno + "MP+" + mouldcode + "+" + status + "*";
                                instockdate50 = "Yes";
                            }
                        }
                    }

                    bool validVendor = true;

                    if (vendor != "")
                    {
                        if (!DataChecking.isValidVendor(vendor))
                        {
                            validVendor = false;
                        }
                        else
                        {
                            if (lblCurrency.Text.Contains("JPY"))
                            {
                                currency = "JPY";
                            }
                            else
                            {
                                currency = DataChecking.getCurrency(vendor);
                            }
                        }
                    }

                    string accountcode = currency == "RMB" ? "" : "5005020002";
                    string costcentre  = currency == "RMB" ? "" : "1404000029";

                    decimal calAmount = 0;

                    string year    = DateTime.Today.ToString("yyyy");
                    string month   = DateTime.Today.ToString("MM");
                    string jpyrate = DataChecking.getJpyRate(year, month);

                    if (lblCurrency.Text.Contains("JPY"))
                    {
                        calAmount = Convert.ToDecimal(amount) * Convert.ToDecimal(jpyrate);
                    }
                    else
                    {
                        calAmount = DataChecking.amountWithRate(currency, amount);
                    }

                    string amounthkd = currency == "RMB" ? "-" : calAmount.ToString("#.##");

                    if (calAmount >= 10000 & mpa == "True")
                    {
                        quantity = "2";
                    }
                    else
                    {
                        quantity = "1";
                    }

                    int piece = Convert.ToInt32(pcs);

                    calAmount = calAmount / piece;

                    if (!validMouldCode)
                    {
                        MessageBox.Show("Invalid Mould Code Found. Please check your data");
                        return;
                    }

                    if (!validVendor)
                    {
                        MessageBox.Show("Invalid Vendor Code Found. Please check your data");
                        return;
                    }

                    if (globalStatus != "T")
                    {
                        if (calAmount < 10000)
                        {
                            if (globalStatus == "K")
                            {
                                currentStatus = "K";
                            }
                            else if (globalStatus == "S")
                            {
                                currentStatus = "S";
                            }
                            else
                            {
                                if (calAmount == 0)
                                {
                                    currentStatus = "K";
                                }
                                else
                                {
                                    currentStatus = "U";
                                }
                            }

                            category = "K";
                        }
                        else
                        {
                            if (globalStatus == "K")
                            {
                                currentStatus = "K";
                                category      = globalCategory;
                            }
                            else if (globalStatus == "S")
                            {
                                currentStatus = "S";
                                category      = globalCategory;
                            }
                            else
                            {
                                if (mouldcode.StartsWith("8") && mouldcode != "8")
                                {
                                    currentStatus = "U";
                                    category      = "K";
                                }
                                else if (oemasset != "")
                                {
                                    currentStatus = "U";
                                    category      = "K";
                                }
                                else
                                {
                                    currentStatus = "F";
                                    accountcode   = "";
                                    costcentre    = "";
                                    category      = "A";
                                }
                            }
                        }
                    }
                    else
                    {
                        currentStatus = "T";
                        category      = "K";
                    }

                    if (oemasset != "")
                    {
                        //Debug.WriteLine("OEM: " + oemasset);

                        if (oemasset.Length == 1)
                        {
                            oemasset = "0" + oemasset;
                        }

                        if (!DataChecking.validOem(oemasset))
                        {
                            MessageBox.Show("Invalid OEM");
                            return;
                        }

                        accountcode = DataChecking.getAccountCode(oemasset);

                        costcentre = DataChecking.getCostCentre(oemasset);
                    }

                    //string amounthkd = DataChecking.amountWithRate(currency, amount).ToString();

                    string updateText = string.Format("update tb_betamould set tm_mouldno = '{0}', tm_itemcode = '{1}', tm_rev = '{2}'" +
                                                      ", tm_status = '{3}', tm_currency = '{4}', tm_amount = '{5}', tm_mpa = '{6}', tm_mouldcode_code = '{7}'" +
                                                      ", tm_vendor_code = '{8}', tm_qty = '{9}', tm_itemtext = '{10}', tm_projecttext = '{11}', tm_request = '{12}'" +
                                                      ", tm_st_code = '{13}', tm_oemasset = '{14}', tm_rm = N'{15}', tm_modify = 'Yes', tm_amounthkd = '{16}', tm_group = '{17}', tm_accountcode = '{18}', tm_costcentre = '{19}', tm_category = '{20}', tm_ismodify = '{21}', tm_model = '{22}', tm_instockdate50 = '{23}', tm_vnonly = '{24}', tm_cnvnonly = '{25}' where tm_chaseno = '{26}'", mouldno, itemcode, rev, status, currency, amount, mpa, mouldcode,
                                                      vendor, quantity, itemtext, projecttext, request, currentStatus, oemasset, remarks, amounthkd, group, accountcode, costcentre, category, ismodify, model, instockdate50, vnonly, cnvnonly, chaseno);

                    DataService.GetInstance().ExecuteNonQuery(updateText);

                    this.saveLogRecord();
                }
                else
                {
                    string ismodify = "";

                    if (ckbModify.Checked)
                    {
                        ismodify = "True";
                    }
                    else
                    {
                        ismodify = "False";
                    }

                    string vnonly = cbProductionBase.SelectedIndex == 2 ? "True" : "False";

                    string cnvnonly = cbProductionBase.SelectedIndex == 1 ? "True" : "False";

                    string model = txtModel.Text;

                    string remarks = txtRemarks.Text;

                    string chaseno = lblChaseno.Text;

                    string oemasset = txtOemasset.Text;

                    string accountcode = "";

                    string costcentre = "";

                    if (oemasset != "")
                    {
                        //Debug.WriteLine("OEM: " + oemasset);

                        if (oemasset.Length == 1)
                        {
                            oemasset = "0" + oemasset;
                        }

                        if (!DataChecking.validOem(oemasset))
                        {
                            MessageBox.Show("Invalid OEM");
                            return;
                        }

                        accountcode = DataChecking.getAccountCode(oemasset);

                        costcentre = DataChecking.getCostCentre(oemasset);
                    }

                    string text = string.Format("update tb_betamould set tm_model = '{0}', tm_ismodify = '{1}', tm_rm = '{2}', tm_group = '{3}'" +
                                                ", tm_moulditemviewer = 'Yes', tm_vnonly = '{4}', tm_cnvnonly = '{5}', tm_oemasset = '{6}', tm_accountcode = '{7}'" +
                                                ", tm_costcentre = '{8}' where tm_chaseno = '{9}'", model, ismodify, remarks, cbGroup.SelectedItem.ToString(), vnonly, cnvnonly, oemasset, accountcode, costcentre, chaseno);

                    DataService.GetInstance().ExecuteNonQuery(text);
                }
                MessageBox.Show("Record has been saved");

                if (formClose != null)
                {
                    formClose(this, new EventArgs());
                }
            }
        }
Beispiel #17
0
        private void addToListToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (dgvDisposal.SelectedRows == null)
            {
                return;
            }

            bool isValid = true;

            List <string> mouldlist = new List <string>();
            List <string> errlist   = new List <string>();

            foreach (DataGridViewRow row in dgvDisposal.SelectedRows)
            {
                string mouldno = row.Cells[1].Value.ToString();

                if (DataChecking.isMouldInStock(mouldno))
                {
                    mouldlist.Add(mouldno);
                }
                else
                {
                    errlist.Add(mouldno);
                    isValid = false;
                }
            }

            /*if (!isValid)
             * {
             *  MessageBox.Show("Some data are not in IN-STOCK status yet. Please check the data before doing the disposal operation");
             *  return;
             * }*/

            for (int i = 0; i < mouldlist.Count; i++)
            {
                string mould = mouldlist[i];

                Debug.WriteLine("SEARCH MOULD: " + mould);

                string query = string.Format("select t.tm_chaseno from tb_betamould as t, tb_setcommon as sc where t.tm_mouldno = sc.sc_oldmouldno" +
                                             " and sc.sc_mouldno = '{0}'", mould);

                GlobalService.reader = DataService.GetInstance().ExecuteReader(query);

                if (GlobalService.reader.HasRows)
                {
                    while (GlobalService.reader.Read())
                    {
                        string strChaseno = GlobalService.reader.GetString(0);

                        GlobalService.ChaseNoList.Add(strChaseno);
                    }
                }
                GlobalService.reader.Close();
                GlobalService.reader.Dispose();

                string query1 = string.Format("select tm_chaseno from tb_betamould where tm_mouldno = '{0}'", mould);

                GlobalService.reader = DataService.GetInstance().ExecuteReader(query1);

                while (GlobalService.reader.Read())
                {
                    string chase = GlobalService.reader.GetString(0);
                    GlobalService.ChaseNoList.Add(chase);
                }
                GlobalService.reader.Close();
                GlobalService.reader.Dispose();
            }

            GlobalService.ChaseNoList = GlobalService.ChaseNoList.Distinct().ToList();

            MessageBox.Show("Data added to list");
        }
Beispiel #18
0
        private void btnCheck_Click(object sender, EventArgs e)
        {
            try
            {
                updateList = new List <CdReportList>();

                this.Cursor = Cursors.WaitCursor;

                foreach (DataGridViewRow row in dgvCdReport.Rows)
                {
                    List <string> instockList = new List <string>();

                    string reportno = row.Cells[1].Value.ToString();

                    string vendor   = row.Cells[3].Value.ToString();
                    string itemcode = row.Cells[6].Value.ToString();
                    string rev      = row.Cells[7].Value.ToString();

                    decimal tmpAmountAfter = Convert.ToDecimal(row.Cells[10].Value);

                    decimal tmpCdTotal = Convert.ToDecimal(row.Cells[12].Value);

                    decimal total = Convert.ToDecimal(DataChecking.getAmountHkdByItemcodeRev(itemcode, rev));

                    row.Cells[11].Value = total;

                    decimal originalTotal = Convert.ToDecimal(DataChecking.getAmountByItemcodeRev(itemcode, rev));

                    string instockdate = "";

                    string query = string.Format("select tm_instockdate from tb_betamould where tm_itemcode = '{0}' and tm_rev = '{1}'" +
                                                 " and tm_vendor_code = '{2}' and tm_st_code = 'S' group by tm_instockdate", itemcode, rev, vendor);

                    GlobalService.reader = DataService.GetInstance().ExecuteReader(query);

                    //DataGridViewComboBoxColumn col = (DataGridViewComboBoxColumn)dgvCdReport.Columns[12];
                    DataGridViewComboBoxCell comCell = new DataGridViewComboBoxCell();
                    //comCell = this.dgvCdReport[12, row.Index] as DataGridViewComboBoxCell;
                    dgvCdReport[13, row.Index] = comCell;

                    if (GlobalService.reader.HasRows)
                    {
                        while (GlobalService.reader.Read())
                        {
                            instockdate = GlobalService.reader.GetString(0);

                            instockList.Add(instockdate);
                        }
                    }
                    else
                    {
                        instockList.Add("沒有入庫紀錄");
                    }
                    GlobalService.reader.Close();
                    GlobalService.reader.Dispose();

                    comCell.DataSource = instockList;

                    comCell.Value = comCell.Items[0];

                    /*if (col.Items.Count > 0)
                     *  row.Cells[12].Value = instockdate;
                     * else
                     *  row.Cells[12].Value = "未有入庫紀錄";*/

                    string cdmonth = "";

                    if (instockdate != "" && instockdate != "沒有入庫紀錄")
                    {
                        cdmonth = Convert.ToDateTime(row.Cells[13].Value).ToString("yyyy.MM");
                    }
                    else
                    {
                        cdmonth = "#N/A";
                    }

                    if (cdmonth != "#N/A")
                    {
                        row.Cells[16].ReadOnly = false;
                    }

                    row.Cells[14].Value = cdmonth;

                    //row.Cells[0].Value = total;

                    row.Cells[12].Value = Convert.ToDecimal(row.Cells[9].Value) - Convert.ToDecimal(total);

                    Debug.WriteLine("Total: " + total + "  Temp Amount: " + tmpAmountAfter);

                    if (total != tmpAmountAfter)
                    {
                        row.DefaultCellStyle.BackColor = Color.LightYellow;

                        row.Cells[15].Value = tmpAmountAfter + "  \u2192  " + total;
                    }
                    else
                    {
                        row.DefaultCellStyle.BackColor = SystemColors.ControlLightLight;
                    }

                    string amountsystem = row.Cells[0].Value.ToString();

                    updateList.Add(new CdReportList {
                        ReportNo = reportno, AmountAfter = originalTotal.ToString(), AmountHkdAfter = total.ToString(), Remarks = row.Cells[15].Value.ToString(), InStockDate = instockdate, CdMonth = cdmonth, AmountSystem = amountsystem
                    });
                }
                this.Cursor = Cursors.Default;

                MessageBox.Show("Checking completed");
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message + ex.StackTrace);
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            string mainMouldNo = lblMouldNo.Text;

            string mainItemCode = lblItemcode.Text;

            string mainText = string.Format("if not exists (select * from tb_relationcommon where rc_itemcode = '{1}') begin" +
                                            " insert into tb_relationcommon (rc_oldmouldno, rc_itemcode, rc_newmouldno) values" +
                                            " ('{0}', '{1}', '{2}') end", mainMouldNo, mainItemCode, mainMouldNo);

            DataService.GetInstance().ExecuteNonQuery(mainText);

            foreach (DataGridViewRow row in dgvResult.Rows)
            {
                string mouldnocommon = row.Cells[1].Value.ToString();
                string itemcode      = row.Cells[2].Value.ToString();
                string vendor        = row.Cells[3].Value.ToString();
                string mouldcode     = row.Cells[4].Value.ToString();
                string newOld        = row.Cells[6].Value.ToString();
                string oemasset      = row.Cells[7].Value.ToString();
                string remarks       = row.Cells[8].Value.ToString();
                string mouldnoold    = row.Cells[9].Value.ToString();

                string query = string.Format("insert into tb_relationcommon (rc_oldmouldno, rc_itemcode, rc_newmouldno) values " +
                                             " ('{0}', '{1}', '{2}')", mouldnoold, itemcode, mouldnocommon);
                DataService.GetInstance().ExecuteNonQuery(query);

                string commandText = string.Format("update tb_betamould set tm_common = 'Common', tm_type = 'Common', tm_modify = 'Yes', tm_moulditemviewer = 'Yes' where tm_mouldno = '{0}'", lblMouldNo.Text);
                DataService.GetInstance().ExecuteNonQuery(commandText);

                if (newOld == "New")
                {
                    string projectText = itemcode + "-01";
                    string request     = itemcode + "01";
                    string itemText    = mouldnoold + "MP+" + mouldcode + "+New";

                    string currency = DataChecking.getCurrency(vendor);

                    string group = DataChecking.getVendorGroup(vendor);

                    string chaseno = DataChecking.getLastChaseNo();

                    string inserttext = string.Format("insert into tb_betamould (tm_chaseno, tm_mouldno, tm_itemcode, tm_rev, tm_status, tm_currency, tm_amount, tm_amounthkd" +
                                                      ", tm_mpa, tm_mouldcode_code, tm_vendor_code, tm_st_code, tm_qty, tm_itemtext, tm_projecttext, tm_request, tm_owner, tm_category, tm_indate, tm_common, tm_oemasset, tm_rm, tm_createdby, tm_group) 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}')", chaseno, mouldnocommon, itemcode, "01", "New",
                                                      currency, "0", "0", "False", mouldcode, vendor, "S", "1", itemText, projectText, request, "KDTHK", "K", DateTime.Today.ToString("yyyy/MM/dd"), "Common", oemasset, remarks, AdUtil.getUsername("kmhk.local"), group);

                    DataService.GetInstance().ExecuteNonQuery(inserttext);
                }
                else
                {
                    string updateText = string.Format("update tb_betamould set tm_common = 'Common', tm_modify = 'Yes', tm_moulditemviewer = 'Yes' where tm_mouldno = '{0}' and tm_itemcode = '{1}'", mouldnoold, itemcode);
                    DataService.GetInstance().ExecuteNonQuery(updateText);
                }
            }

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

            if (formClose != null)
            {
                formClose(this, new EventArgs());
            }
        }
        private void modify()
        {
            //table.Rows.Add();

            int lastId = 0;

            string text = "select top 1 tm_id from tb_betamould order by tm_id desc";

            GlobalService.reader = DataService.GetInstance().ExecuteReader(text);

            while (GlobalService.reader.Read())
            {
                lastId = GlobalService.reader.GetInt32(0);
            }

            GlobalService.reader.Close();
            GlobalService.reader.Dispose();

            lastId = lastId + 1;

            string strChaseNo = DataChecking.getLastChaseNo();

            string itemcode = dgvQuotation.SelectedRows[0].Cells[6].Value.ToString();

            string rev = (Convert.ToInt32(DataChecking.getLastRev(itemcode)) + 1).ToString();

            if (Convert.ToInt32(rev) < 10)
            {
                rev = "0" + rev;
            }

            string mouldno    = dgvQuotation.SelectedRows[0].Cells[8].Value.ToString();
            string status     = "Modify";
            string type       = dgvQuotation.SelectedRows[0].Cells[10].Value.ToString();
            string currency   = DataChecking.getCurrency(dgvQuotation.SelectedRows[0].Cells[3].Value.ToString());
            string amount     = dgvQuotation.SelectedRows[0].Cells[13].Value.ToString();
            string mpa        = dgvQuotation.SelectedRows[0].Cells[15].FormattedValue.ToString();
            string vendor     = dgvQuotation.SelectedRows[0].Cells[3].Value.ToString();
            string vendorname = dgvQuotation.SelectedRows[0].Cells[4].Value.ToString();
            string mouldcode  = dgvQuotation.SelectedRows[0].Cells[11].Value.ToString();
            string qstatus    = "";
            //string owner = dgvQuotation.SelectedRows[0].Cells[13].Value.ToString();

            string oemasset      = dgvQuotation.SelectedRows[0].Cells[18].Value.ToString();
            string remarks       = dgvQuotation.SelectedRows[0].Cells[19].Value.ToString();
            string category      = "";
            string commonstatus  = dgvQuotation.SelectedRows[0].Cells[20].Value.ToString();
            string purchasegroup = dgvQuotation.SelectedRows[0].Cells[5].Value.ToString();

            if (DataChecking.amountWithRate(currency, amount) < 10000)
            {
                category = "K";

                if (vendor != "" && mouldcode != "" && mouldno != "" && itemcode != "" && rev != "" && amount != "")
                {
                    qstatus = "U";
                }

                else
                {
                    qstatus = "Q";
                }
            }
            else
            {
                category = "A";

                if (vendor != "" && mouldcode != "" && mouldno != "" && itemcode != "" && rev != "" && amount != "" && oemasset == "")
                {
                    qstatus = "F";
                }

                else if (vendor != "" && mouldcode != "" && mouldno != "" && itemcode != "" && rev != "" && amount != "" && oemasset != "")
                {
                    qstatus  = "U";
                    category = "K";
                }
                else
                {
                    qstatus = "Q";
                }
            }

            string amounthkd     = DataChecking.amountWithRate(currency, amount).ToString("#.##");
            string kdcstatus     = DataChecking.getKdcStatus(qstatus);
            string currentstatus = DataChecking.getCurrentStatus(qstatus);

            string createdperson   = AdUtil.getUsername("kmhk.local");
            string createddatetime = DateTime.Today.ToString("yyyy/MM/dd");

            string accountcode = "";
            string costcentre  = "";

            if (oemasset != "")
            {
                accountcode = DataChecking.getAccountCode(oemasset);
                costcentre  = DataChecking.getCostCentre(oemasset);
            }
            else
            {
            }
            table.Rows.Add(new object[] { lastId, currentstatus, strChaseNo, vendor, vendorname, purchasegroup, itemcode, rev, mouldno,
                                          status, type, mouldcode, currency, amount, amounthkd, mpa, qstatus, kdcstatus, oemasset, remarks, commonstatus, createdperson, createddatetime });

            string itemtext    = mouldno + "MP+" + mouldcode + "+" + status;
            string projecttext = itemcode + "-" + rev;
            string request     = itemcode + rev;

            string quantity = "";

            if (mpa == "True")
            {
                quantity = "2";
            }
            else
            {
                quantity = "1";
            }

            string model  = itemcode.Substring(2, 3);
            string common = DataChecking.getCommon(mouldno, itemcode);

            string insertText = string.Format("insert into tb_betamould (tm_chaseno, tm_mouldno, tm_itemcode, tm_rev, tm_status, tm_type, tm_currency, tm_amount, tm_amounthkd" +
                                              ", tm_mpa, tm_mouldcode_code, tm_vendor_code, tm_st_code, tm_qty, tm_itemtext, tm_projecttext, tm_request, tm_owner, tm_category, tm_indate, tm_common, tm_oemasset, tm_rm, tm_createdby, tm_model) 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}')", strChaseNo, mouldno, itemcode, rev, status, type,
                                              currency, amount, amounthkd, mpa, mouldcode, vendor, qstatus, quantity, itemtext, projecttext, request, "KDTHK", category, DateTime.Today.ToString("yyyy/MM/dd"), common, oemasset, remarks, AdUtil.getUsername("kmhk.local"), model);

            DataService.GetInstance().ExecuteNonQuery(insertText);

            lblTotal.Text = "ROWS COUNT: " + dgvQuotation.Rows.Count;
        }
Beispiel #21
0
        private void transferWithoutFee(List <TransferNoFeeList> list)
        {
            if (list.Count != 0)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    string listChaseno  = list[i].ChaseNo;
                    string listMouldno  = list[i].MouldNo;
                    string listItemcode = list[i].ItemCode;

                    string query = string.Format("select tm_mouldno, tm_itemcode, tm_rev, tm_status, tm_type, tm_mpa, tm_fixedassetcode, tm_tmpfixedassetcode" +
                                                 ", tm_qty, tm_common, tm_request, tm_projecttext, tm_category, tm_mouldcode_code, tm_owner, tm_vendor_code, tm_pcs" +
                                                 " from tb_betamould where tm_chaseno = '{0}'", listChaseno);

                    string mouldno = "", itemcode = "", rev = "", status = "", type = "", currency = "", mpa = "";
                    string fac = "", tmpfac = "", qty = "", common = "", request = "", indate = DateTime.Today.ToString("yyyy/MM/dd");
                    string projecttext = "", category = "", vendor = "", mouldcode = "", owner = "", fromVendor = "", pcs = "";

                    GlobalService.reader = DataService.GetInstance().ExecuteReader(query);
                    while (GlobalService.reader.Read())
                    {
                        mouldno     = GlobalService.reader.GetString(0);
                        itemcode    = GlobalService.reader.GetString(1);
                        rev         = GlobalService.reader.GetString(2);
                        status      = GlobalService.reader.GetString(3);
                        type        = GlobalService.reader.GetString(4);
                        mpa         = GlobalService.reader.GetString(5);
                        fac         = GlobalService.reader.GetString(6);
                        tmpfac      = GlobalService.reader.GetString(7);
                        qty         = GlobalService.reader.GetString(8);
                        common      = GlobalService.reader.GetString(9);
                        request     = GlobalService.reader.GetString(10);
                        projecttext = GlobalService.reader.GetString(11);
                        category    = GlobalService.reader.GetString(12);
                        mouldcode   = GlobalService.reader.GetString(13);
                        owner       = GlobalService.reader.GetString(14);
                        fromVendor  = GlobalService.reader.GetString(15);
                        pcs         = GlobalService.reader.GetString(16);
                    }
                    GlobalService.reader.Close();
                    GlobalService.reader.Dispose();

                    string tStatus = "";

                    if (status == "New")
                    {
                        tStatus = "TM";
                    }
                    else
                    {
                        tStatus = "TM+Modify";
                    }

                    string itemtext = mouldno + "MP+" + mouldcode + "+" + tStatus;
                    string chaseno  = DataChecking.getLastChaseNo();
                    string tmpPo    = chaseno.Replace("MS", "TM");

                    string transferChaseNo = DataChecking.getLastTransferNo();
                    vendor   = txtVendorAfter.Text;
                    currency = DataChecking.getCurrency(vendor);

                    string text = string.Format("insert into tb_betamould (tm_chaseno, tm_mouldno, tm_itemcode, tm_rev, tm_status, tm_type, tm_currency" +
                                                ", tm_amount, tm_amounthkd, tm_mpa, tm_fixedassetcode, tm_tmpfixedassetcode, tm_common, tm_itemtext, tm_request, tm_indate" +
                                                ", tm_projecttext, tm_po, tm_category, tm_vendor_code, tm_mouldcode_code, tm_st_code, tm_transfer, tm_owner, tm_qty" +
                                                ", tm_createdby) 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}'",
                                                chaseno, mouldno, itemcode, rev, tStatus, type, currency, "0", "0", mpa, fac, tmpfac, common, itemtext, request, indate, projecttext, tmpPo,
                                                category, vendor, mouldcode, "P", transferChaseNo, owner, qty, AdUtil.getUsername("kmhk.local"));

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