Пример #1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //GlobalService.User = AdUtil.getUsername("kmhk.local");
            if (Environment.UserName.Substring(0, 2).ToLower() == "hk")
            {
                GlobalService.User = AdUtil.getUsername("kmhk.local");
            }
            else
            {
                GlobalService.User = AdUtil.getUsername("kmas.local");
            }
            GlobalService.HardwareList = DataUtil.GetHardwareList();
            GlobalService.SoftwareList = DataUtil.GetSoftwareList();
            GlobalService.QaList       = DataUtil.GetQaList();

            GlobalService.ITList = new List <string>();
            GlobalService.ITList.AddRange(new string[] { UserUtil.ItUserName1(), UserUtil.ItUserName3(), UserUtil.ItUserName2(), UserUtil.ItUserName4() });
            //GlobalService.ITList.AddRange(new string[] { "Yeung Wai, Gabriel (楊偉)", "Lee Ming Fung(李銘峯)", "Ho Kin Hang(何健恒,Ken)", "Chan Fai Lung(陳輝龍,Onyx)" });

            //Application.Run(new Form2());
            //Application.Run(new Main());

            Application.Run(new Main2());
        }
        public FaApprovalView()
        {
            InitializeComponent();

            user = AdUtil.getUsername("kmhk.local");

            this.LoadData();

            Application.Idle += new EventHandler(Application_Idle);
        }
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            /*OpenFileDialog ofd = new OpenFileDialog();
             *
             * if (ofd.ShowDialog() == DialogResult.OK)
             * {
             *  DataTable table = ImportExcel2007.TranslateToTable(ofd.FileName);
             *
             *  foreach (DataRow row in table.Rows)
             *  {
             *      string id = row.ItemArray[0].ToString().Trim();
             *      string group = row.ItemArray[1].ToString().Trim();
             *
             *      string query = string.Format("update tb_vendor set v_group = '{0}' where v_id = '{1}'", group, id);
             *      DataService.GetInstance().ExecuteNonQuery(query);
             *  }
             * }*/

            GlobalService.Owner = AdUtil.getUsername("kmhk.local");
            //GlobalService.Owner = "Cato Yeung Pui Kwan (楊沛昆)";

            //GlobalService.IPO1st = "Ho Kin Hang(何健恒,Ken)";
            //GlobalService.IPO2nd = "Ho Kin Hang(何健恒,Ken)";
            GlobalService.IPO1st = "Poon Nga Wai(潘雅慧,Anna)";
            GlobalService.IPO2nd = "Cheng Chong Wah(鄭創華)";


            //Application.Run(new testform());
            if (GlobalService.Owner == "Cheng Chong Wah(鄭創華)")
            {
                Application.Run(new MainSimple());
            }
            else
            {
                Application.Run(new frmMain());
            }
        }
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            DataTable vendorTable = new DataTable();

            vendorTable = ImportXlsUtil.TranslateToTable(filename);

            foreach (DataRow row in vendorTable.Rows)
            {
                string vendorcode = row.ItemArray[0].ToString();
                string vendorname = row.ItemArray[1].ToString();
                string pgroup     = row.ItemArray[2].ToString();
                string detail     = row.ItemArray[3].ToString();
                string paycurr    = row.ItemArray[4].ToString();
                string payterm    = row.ItemArray[5].ToString();
                string request    = row.ItemArray[6].ToString();
                string edi        = row.ItemArray[7].ToString();
                string remarks    = row.ItemArray[8].ToString();

                if (vendorcode.Length == 9)
                {
                    vendorcode = "0" + vendorcode;
                }

                vendorname = vendorname.Replace("'", "");

                string query = string.Format("if exists (select * from tb_vendor where v_code = '{0}') update tb_vendor set v_name = '{1}', v_group = '{2}'" +
                                             ", v_detail = '{3}', v_paycurr = '{4}', v_payterm = '{5}', v_request = '{6}', v_edi = '{7}', v_remarks = '{8}' where v_code = '{0}'" +
                                             " else insert into tb_vendor (v_code, v_name, v_group, v_detail, v_paycurr, v_payterm, v_request, v_edi, v_remarks) values" +
                                             " ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}')", vendorcode, vendorname, pgroup, detail, paycurr, payterm, request, edi, remarks);

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

            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}')", "Vendor", "-", "-", AdUtil.getUsername("kmhk.local"), DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), "-", "Master Uploaded");

            DataService.GetInstance().ExecuteNonQuery(logText);

            MessageBox.Show("Data uploaded");
        }
        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;
        }
Пример #6
0
        public SplashForm()
        {
            InitializeComponent();

            string domain = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName;

            //GlobalService.User = domain == "kmhk.local" ? AdUtil.getUsername("kmhk.local") : "";

            string currentUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToUpper();

            //string currentUser = Environment.UserDomainName.ToUpper();

            if (currentUser.StartsWith("KMHK"))
            {
                GlobalService.User    = AdUtil.getUsername("kmhk.local");
                GlobalService.DbTable = "TB_" + AdUtil.GetUserIdByUsername(GlobalService.User, "kmhk.local");
            }
            else if (currentUser.StartsWith("KMAS"))
            {
                //GlobalService.User = AdUtil.getUsername("kmas.local");
                //GlobalService.DbTable = "TB_" + AdUtil.GetUserIdByUsername(GlobalService.User, "kmas.local");
                string tb = currentUser == @"KMAS\AS1600048" ? "hk070022"
                    : currentUser == @"KMAS\AS1600049" ? "hk110017"
                            //: currentUser == @"KMAS\AS1600050" ? "hk040015"
                    : currentUser == @"KMAS\AS1600051" ? "hk160002"
                    : currentUser == @"KMAS\AS1600053" ? "hk950330"
                    : currentUser == @"KMAS\AS1600054" ? "hk110023"
                            //: currentUser == @"KMAS\AS1600055" ? "hk120027"
                            //: currentUser == @"KMAS\AS1600056" ? "hk140005" : "";
                    : currentUser == @"KMAS\AS1600056" ? "hk140005"
                    : currentUser == @"KMAS\AS1700059" ? "hkit001"
                    : currentUser == @"KMAS\AS1700060" ? "hkit002"
                    : currentUser == @"KMAS\AS1700061" ? "hkit003"
                    : currentUser == @"KMAS\AS060701057" ? "hkit004"
                    : currentUser == @"KMAS\AS1700063" ? "AS1700063" : "";

                GlobalService.DbTable = "TB_" + tb;

                string name = currentUser == @"KMAS\AS1600048" ? "Chow Chi To(周志滔,Sammy)"
                    : currentUser == @"KMAS\AS1600049" ? "Ling Wai Man(凌慧敏,Velma)"
                              //: currentUser == @"KMAS\AS1600050" ? "Chan Fai Lung(陳輝龍,Onyx)"
                    : currentUser == @"KMAS\AS1600051" ? "Ng Lau Yu, Lilith (吳柳如)"
                    : currentUser == @"KMAS\AS1600053" ? "Lee Miu Wah(李苗華)"
                    : currentUser == @"KMAS\AS1600054" ? "Lee Ming Fung(李銘峯)"
                              //: currentUser == @"KMAS\AS1600055" ? "Ho Kin Hang(何健恒,Ken)"
                    : currentUser == @"KMAS\AS1600056" ? "Yeung Wai, Gabriel (楊偉)"
                    : currentUser == @"KMAS\AS1700059" ? "Darli Yeung Sheung Yu (楊尚儒)"
                    : currentUser == @"KMAS\AS1700060" ? "Donovan Chan Wing Shing (陳永成)"
                    : currentUser == @"KMAS\AS1700061" ? "Cash Tsang Yuk Kam (曾旭鑫)"
                    : currentUser == @"KMAS\AS1700063" ? "Cato Yeung Pui Kwan (楊沛昆)"
                    : currentUser == @"KMAS\AS060701057" ? "Nakata" : "";

                GlobalService.User = name;
            }
            else
            {
                throw new Exception("User does not belongs to KMHK or KMAS");
            }

            //GlobalService.User = "******";
            //GlobalService.User = "******";
            //GlobalService.DbTable = "TB_hk950193";

            if (!worker.IsBusy)
            {
                worker.RunWorkerAsync();
            }
        }
Пример #7
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();
        }
Пример #8
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);
                }
            }
        }
        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 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 RollBack()
        {
            string po = this.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;
            }

            switch (MessageBox.Show("You are trying to roll back PO : " + po + " from In-Stock status. Are you sure to do it?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
            {
            case System.Windows.Forms.DialogResult.Yes:
                string 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");

                this.DialogResult = DialogResult.OK;
                break;

            case System.Windows.Forms.DialogResult.No:
                break;
            }
        }
        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);
            }
        }
Пример #13
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());
            }
        }
Пример #14
0
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                foreach (DataRow datarow in potable.Rows)
                {
                    string chaseno         = datarow[0].ToString();
                    string vendor          = datarow[4].ToString();
                    string purchaserequest = datarow[6].ToString();
                    string po    = datarow[7].ToString();
                    string porev = datarow[8].ToString();

                    string paydate = "-----";

                    if (!po.StartsWith("TM"))
                    {
                        if (porev.Length == 2)
                        {
                            po = po + "000" + porev;
                        }
                        else
                        {
                            po = po + "00" + porev;
                        }
                    }

                    //string status = DataChecking.getStatusCodeByPo(po);
                    string status = DataChecking.getStatusByChaseno(chaseno);

                    string query = "";

                    if (status == "K")
                    {
                        query = string.Format("update tb_betamould set tm_po = '{0}', tm_porev = '{1}', tm_poissued = '{2}'" +
                                              ", tm_modify = 'Yes', tm_moulditemviewer = 'Yes', tm_purchaserequest = '{4}' where tm_chaseno = '{5}'", po, porev, DateTime.Today.ToString("yyyy/MM/dd")
                                              , purchaserequest, chaseno);
                    }
                    else
                    {
                        query = string.Format("update tb_betamould set tm_st_code = case when tm_status = 'New' then 'P' else 'K' end, tm_po = '{0}', tm_porev = '{1}', tm_poissued = '{2}'" +
                                              ", tm_modify = 'Yes', tm_moulditemviewer = 'Yes', tm_purchaserequest = '{3}' where tm_chaseno = '{4}'", po, porev, DateTime.Today.ToString("yyyy/MM/dd")
                                              , purchaserequest, chaseno);
                    }

                    DataService.GetInstance().ExecuteNonQuery(query);

                    string text = string.Format("update tb_expensetransfer set et_pono = '{0}', et_poissued = '{1}' where et_chaseno = '{2}'", po, DateTime.Today.ToString("yyyy/MM/dd"), chaseno);

                    DataService.GetInstance().ExecuteNonQuery(text);

                    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}')", "PO Issued", "-", po, AdUtil.getUsername("kmhk.local"), DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), chaseno, "PO Issued");

                    DataService.GetInstance().ExecuteNonQuery(logText);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message + ex.StackTrace);
            }
        }
        private void saveLogRecord()
        {
            string logText = "";

            if (oMouldno != txtMouldno.Text)
            {
                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", oMouldno, txtMouldno.Text, AdUtil.getUsername("kmhk.local"), DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"),
                                        lblChaseno.Text, "Edit Data");
                DataService.GetInstance().ExecuteNonQuery(logText);
            }

            if (oItemCode != txtItemcode.Text)
            {
                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", oItemCode, txtItemcode.Text, AdUtil.getUsername("kmhk.local"), DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"),
                                        lblChaseno.Text, "Edit Data");
                DataService.GetInstance().ExecuteNonQuery(logText);
            }

            if (oRev != txtRev.Text)
            {
                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", oRev, txtRev.Text, AdUtil.getUsername("kmhk.local"), DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"),
                                        lblChaseno.Text, "Edit Data");
                DataService.GetInstance().ExecuteNonQuery(logText);
            }

            if (oStatus != cbDiv.SelectedItem.ToString())
            {
                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", oStatus, cbDiv.SelectedItem.ToString(), AdUtil.getUsername("kmhk.local"), DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"),
                                        lblChaseno.Text, "Edit Data");
                DataService.GetInstance().ExecuteNonQuery(logText);
            }

            if (oAmount != txtAmount.Text)
            {
                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", oAmount, txtAmount.Text, AdUtil.getUsername("kmhk.local"), DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"),
                                        lblChaseno.Text, "Edit Data");
                DataService.GetInstance().ExecuteNonQuery(logText);
            }

            string mpa = "";

            if (ckbMpa.Checked)
            {
                mpa = "True";
            }
            else
            {
                mpa = "False";
            }

            if (oMpa != mpa)
            {
                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", oMpa, mpa, AdUtil.getUsername("kmhk.local"), DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"),
                                        lblChaseno.Text, "Edit Data");
                DataService.GetInstance().ExecuteNonQuery(logText);
            }

            if (oOemAsset != txtOemasset.Text)
            {
                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", oOemAsset, txtOemasset.Text, AdUtil.getUsername("kmhk.local"), DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"),
                                        lblChaseno.Text, "Edit Data");
                DataService.GetInstance().ExecuteNonQuery(logText);
            }

            if (oRemarks != txtRemarks.Text)
            {
                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", oRemarks, txtRemarks.Text, AdUtil.getUsername("kmhk.local"), DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"),
                                        lblChaseno.Text, "Edit Data");
                DataService.GetInstance().ExecuteNonQuery(logText);
            }

            if (oVendor != txtVendor.Text)
            {
                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", oVendor, txtVendor.Text, AdUtil.getUsername("kmhk.local"), DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"),
                                        lblChaseno.Text, "Edit Data");
                DataService.GetInstance().ExecuteNonQuery(logText);
            }

            if (oMouldCode != txtMouldCode.Text)
            {
                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", oMouldCode, txtMouldCode.Text, AdUtil.getUsername("kmhk.local"), DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"),
                                        lblChaseno.Text, "Edit Data");
                DataService.GetInstance().ExecuteNonQuery(logText);
            }
        }
Пример #16
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in dgvTransferPreview.Rows)
            {
                string selected  = row.Cells[0].FormattedValue.ToString();
                string mouldno   = row.Cells[1].Value.ToString();
                string mouldcode = row.Cells[2].Value.ToString();
                string itemcode  = row.Cells[3].Value.ToString();
                string latestrec = row.Cells[4].Value.ToString();
                string rev       = row.Cells[5].Value.ToString();
                string vendor    = row.Cells[8].Value.ToString();
                string remarks   = row.Cells[9].Value.ToString();

                if (selected == "True")
                {
                    string text = string.Format("select tm_fixedassetcode from tb_betamould where tm_mouldno = '{0}' and tm_fixedassetcode != '' and tm_fixedassetcode not like '%,%' and tm_fixedassetcode not like '%VC%'", mouldno);

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

                    List <string> falist = new List <string>();

                    while (GlobalService.reader.Read())
                    {
                        string fa = GlobalService.reader.GetString(0);

                        falist.Add(fa);
                    }
                    GlobalService.reader.Close();
                    GlobalService.reader.Dispose();

                    string faremarks = "";

                    string category = "K";

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

                    string chaseno = DataChecking.getLastChaseNo();

                    string transferChaseno = chaseno.Replace("MS", "TM");

                    string pgroup = DataChecking.getVendorGroup(vendor);

                    string latestStatus = DataChecking.getLastStatus(mouldno, itemcode);

                    string itemtext = mouldno + "MP+" + mouldcode + "+TM";

                    string type = "TM";

                    string ismodify = "False";

                    string projecttext = itemcode + "-" + rev;

                    string request = itemcode + rev;

                    string quantity = "1";

                    string amount = "0";

                    string currency = DataChecking.getCurrency(vendor);

                    string status = "T";

                    string owner = "KDTHK";

                    string common = "Non-Common";

                    string model = itemcode.Length == 10 ? itemcode.Substring(3, 3) : mouldno.Substring(1, 3);

                    string oldvendor = row.Cells[6].Value.ToString(); //DataChecking.getVendorByMouldItem(mouldno, itemcode);

                    string pcs = row.Cells[10].Value.ToString();      //DataChecking.getPcsByMouldItem(mouldno, itemcode);

                    string query = 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_createdby, tm_model, tm_group, tm_po, tm_faremarks, tm_pcs, tm_ismodify, tm_fixedassetcode, tm_rm) 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}', '{28}', '{29}')", chaseno, mouldno, itemcode, rev, type, "Single",
                                                 currency, amount, amount, "False", mouldcode, vendor, status, quantity, itemtext, projecttext, request, owner, category, DateTime.Today.ToString("yyyy/MM/dd"), common, AdUtil.getUsername("kmhk.local"), model, pgroup, transferChaseno, faremarks, pcs, ismodify, faremarks, remarks);

                    DataService.GetInstance().ExecuteNonQuery(query);

                    this.saveTransferHistory(transferChaseno, mouldno, itemcode, rev, type, owner, owner, oldvendor, vendor, DateTime.Today.ToString("yyyy/MM/dd"), chaseno, faremarks, remarks);
                }
                else
                {
                    continue;
                }
            }
            MessageBox.Show("Record has been saved");

            dgvTransferPreview.Rows.Clear();
        }
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                DataTable worktable = (DataTable)e.Argument;

                foreach (DataRow datarow in worktable.Rows)
                {
                    string mouldcode   = datarow[0].ToString().Trim();
                    string type        = datarow[1].ToString();
                    string contentjp   = datarow[2].ToString();
                    string contenteng  = datarow[3].ToString();
                    string contentchin = datarow[4].ToString();
                    string itemgroup   = datarow[5].ToString();

                    string commandText = string.Format("if exists (select * from tbm_mouldcode where mc_mouldcode = '{0}') update tbm_mouldcode set mc_type = '{1}'" +
                                                       ", mc_contentjp = N'{2}', mc_contenteng = N'{3}', mc_contentchin = N'{4}', mc_itemgroup = '{5}' where mc_mouldcode = '{0}' else insert into tbm_mouldcode" +
                                                       " (mc_mouldcode, mc_type, mc_contentjp, mc_contenteng, mc_contentchin, mc_itemgroup) values ('{0}', '{1}', N'{2}', N'{3}', N'{4}', '{5}')", mouldcode, type, contentjp,
                                                       contenteng, contentchin, itemgroup);

                    DataService.GetInstance().ExecuteNonQuery(commandText);
                    //string commandText = string.Format("insert into tbm_mouldcode (mc_mouldcode, mc_type, mc_contentjp, mc_contenteng, mc_contentchin, mc_itemgroup" +
                    // " values ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}')", mouldcode, type, contentjp, contenteng, contentchin, itemgroup);
                }

                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}')", "Mould Code", "-", "-", AdUtil.getUsername("kmhk.local"), DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), "-", "Master Uploaded");

                DataService.GetInstance().ExecuteNonQuery(logText);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message + ex.StackTrace);
                validData = false;
            }
        }