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 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; }
private void btnReject_Click(object sender, EventArgs e) { string now = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); string text = _status == "科責承認中" ? string.Format("update TB_ACC_OUTSTANDING set o_divapproval = 'No', o_divapprovaldate = '{0}', o_status = N'科責已拒絕' where o_invoice = '{1}'", now, _invoice) : _status == "會計處理中" ? string.Format("update TB_ACC_OUTSTANDING set o_staffapproval = 'No', o_staffapprovaldate = '{0}', o_status = N'會計已拒絕' where o_invoice = '{1}'", now, _invoice) : string.Format("update TB_ACC_OUTSTANDING set o_accapproval = 'No', o_accapprovaldate = '{0}', o_status = N'會計已拒絕' where o_invoice = '{1}'", now, _invoice); DataServiceCM.GetInstance().ExecuteNonQuery(text); string applicant = AccUtil.GetApplicant(_invoice); EformUtil.SendRejectEmail(_invoice, GlobalService.User, AdUtil.GetEmailByUsername(GlobalService.User, "kmhk.local"), AdUtil.GetEmailByUsername(applicant, "kmhk.local"), "Outstanding Slip Rejected - " + _invoice, "Your Outstanding Slip has been rejected by " + GlobalService.User); DialogResult = DialogResult.OK; }
private void btnSave_Click(object sender, EventArgs e) { string createdby = txtUser.Text.Trim(); string created = DateTime.Today.ToString("yyyy/MM/dd"); string department = txtDepartment.Text.Trim(); string remarks = txtRemarks.Text.Trim(); string sectHead = UserUtil.GetSectionHead(UserUtil.GetSect(GlobalService.User)); string divHead = UserUtil.GetDivisionHead(UserUtil.GetDivision(GlobalService.User)); string adm1st = "Sammy Chow Chi To (周志滔)"; string adm2nd = "Sammy Chow Chi To (周志滔)"; if (remarks.Contains("'")) { remarks = remarks.Replace("'", "''"); } string query = string.Format("insert into TB_ADM_FORM_PURCHASE (ap_created, ap_createdby, ap_department, ap_remarks, ap_sect, ap_div, ap_adm1st, ap_adm2nd)" + " values ('{0}', N'{1}', N'{2}', N'{3}', N'{4}', N'{5}', N'{6}', N'{7}')", created, createdby, department, remarks, sectHead, divHead, adm1st, adm2nd); DataServiceCM.GetInstance().ExecuteNonQuery(query); string text = "select top 1 ap_id from TB_ADM_FORM_PURCHASE order by ap_id desc"; int id = (int)DataServiceCM.GetInstance().ExecuteScalar(text); foreach (DataGridViewRow row in dgvItems.Rows) { if (row.IsNewRow) { continue; } string item = row.Cells[0].Value.ToString().Trim(); string qty = row.Cells[1].Value.ToString().Trim(); string amount = row.Cells[2].Value.ToString().Trim(); if (item.Contains("'")) { item = item.Replace("'", "''"); } string detailText = string.Format("insert into TB_ADM_FORM_PURCHASE_DETAIL (apd_ap_id, apd_item, apd_qty, apd_amount)" + " values ('{0}', N'{1}', '{2}', '{3}')", id, item, qty, amount); DataServiceCM.GetInstance().ExecuteNonQuery(detailText); } string from = AdUtil.GetEmailByUserId(AdUtil.GetUserIdByUsername(GlobalService.User, "kmhk.local"), "kmhk.local"); string to = AdUtil.GetEmailByUserId(AdUtil.GetUserIdByUsername(sectHead, "kmhk.local"), "kmhk.local"); string emailText = "Application Approval required. Please click <a href=\"\\\\kdthk-dm1\\project\\it system\\MyCloud Beta\\KDTHK-DM-SP.application\">HERE</a> to approval process."; string body = "<p><span style=\"font-family: Calibri;\">" + emailText + "</span></p>"; EformUtil.SendApprovalEmail("", GlobalService.User, from, to, body, "Approval Required - 月度購買依賴"); MessageBox.Show("Record has been saved."); DialogResult = DialogResult.OK; }
private void btnReject_Click(object sender, EventArgs e) { string query = string.Format("update TB_CM_DEBIT set d_status = N'拒絕承認' where d_docno = '{0}'", _docno); DataServiceCM.GetInstance().ExecuteNonQuery(query); string sect = ""; string div = ""; string dept = ""; string createdby = ""; string text = string.Format("select d_sect, d_div, d_dept, d_createdby from TB_CM_DEBIT where d_docno = '{0}'", _docno); using (IDataReader reader = DataServiceCM.GetInstance().ExecuteReader(text)) { while (reader.Read()) { sect = reader.GetString(0).Trim(); div = reader.GetString(1).Trim(); dept = reader.GetString(2).Trim(); createdby = reader.GetString(3).Trim(); } } string subject = "Debit/Credit Note Application has been Rejected"; string content = "Dear Sir/Madam,\n\nYour Debit/Credit Note Application has been Rejected. Please go to MyCloud to revise or apply a new application.\n\nThis is system message, please do not reply."; EformUtil.SendRejectEmail(_docno, GlobalService.User, AdUtil.GetEmailByUsername(GlobalService.User, "kmhk.local"), AdUtil.GetEmailByUsername(createdby, "kmhk.local"), subject, content);//cc? }
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); } }
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(); }
private void btnSave_Click(object sender, EventArgs e) { if (dgvPermission.Rows.Count == 0) { MessageBox.Show("No record found."); return; } dgvPermission.EndEdit(); if (!IsDataValid(dgvPermission)) { MessageBox.Show("Invalid input found."); return; } string applicant = DataUtil.GetApplicant(GlobalService.ChaseNo); string head = DataUtil.GetHead(applicant); string approval = DataUtil.IsItemApproved(GlobalService.ChaseNo) ? "Yes" : "No"; string strApprovalDate = DataUtil.GetApprovalDate(GlobalService.ChaseNo); string st = approval == "Yes" ? "I.T處理中" : "上司承認中"; string chaseno = DataUtil.GetPermissionChaseNo(); foreach (DataGridViewRow row in dgvPermission.Rows) { if (row.IsNewRow) { continue; } string item = row.Cells[0].Value.ToString(); string user = row.Cells[1].Value.ToString(); string start = row.Cells[2].Value.ToString(); string status = row.Cells[3].Value.ToString(); string remarks = row.Cells[4].Value == null? "": row.Cells[4].Value.ToString(); string assigned = row.Cells[5].Value.ToString().Trim(); //string query = string.Format("insert into TB_FORM_PERMISSION (p_type, p_user, p_item, p_created, p_createdby, p_start, p_remarks, p_chaseno, p_approver, p_approval, p_refno, p_applicant, p_status, p_handledby)" + // " values ('{0}', N'{1}', N'{2}', '{3}', N'{4}', '{5}', N'{6}', '{7}', N'{8}', '{9}', '{10}', N'{11}', N'{12}', N'{13}')", status, user, item, DateTime.Today.ToString("yyyy/MM/dd"), GlobalService.Creator, start, remarks, chaseno, head, approval, GlobalService.ChaseNo, GlobalService.Creator, st, assigned); string query = string.Format("insert into TB_FORM_PERMISSION (p_type, p_user, p_item, p_created, p_createdby, p_start, p_remarks, p_chaseno, p_approver, p_approval, p_refno, p_applicant, p_status, p_handledby, p_itapproval, p_approvaldate)" + " values ('{0}', N'{1}', N'{2}', '{3}', N'{4}', '{5}', N'{6}', '{7}', N'{8}', '{9}', '{10}', N'{11}', N'{12}', N'{13}', N'{14}', N'{15}')", status, user, item, DateTime.Today.ToString("yyyy/MM/dd"), GlobalService.Creator, start, remarks, chaseno, head, approval, GlobalService.ChaseNo, GlobalService.Creator, st, assigned, UserUtil.ItManagerName(), strApprovalDate); DataService.GetInstance().ExecuteNonQuery(query); } GlobalService.SavedForm = "permission"; /*if (st == "上司承認中") * { * string from = AdUtil.GetEmailByUserId(AdUtil.GetUserIdByUsername(GlobalService.User, "kmhk.local"), "kmhk.local"); * * string to = AdUtil.GetEmailByUserId(AdUtil.GetUserIdByUsername(head, "kmhk.local"), "kmhk.local"); * * string text = "IT Application Approval required. Please click <a href=\"\\\\kdthk-dm1\\project\\it system\\MyCloud Beta\\KDTHK-DM-SP.application\">HERE</a> to approval process."; * string body = "<p><span style=\"font-family: Calibri;\">" + text + "</span></p>"; * //EformUtil.SendApprovalEmail(chaseno, from, to, body); * }*/ if (approval == "No") { string from = AdUtil.GetEmailByUsername(applicant, "kmhk.local"); string to = AdUtil.GetEmailByUsername(head, "kmhk.local"); EformUtil.SendApprovalEmail(GlobalService.ChaseNo, from, to, "Approval Required for 權限及軟件安裝", "權限及軟件安裝", applicant); } if (SavedEvent != null) { SavedEvent(this, new EventArgs()); } }
public static void DeleteData(DataTable table, string path) { string sPath = path.Contains("'") ? path.Replace("'", "''") : path; //DataRow[] rows = table.Select(string.Format("filepath = '{0}'", sPath)); DataRow[] rows = (from row in table.AsEnumerable() where row.RowState != DataRowState.Deleted && row.RowState != DataRowState.Deleted && row.Field <string>("filepath") == path select row).ToArray(); List <string> queryList = new List <string>(); foreach (DataRow row in rows) { string owner = row["fileowner"].ToString().Trim(); if (owner == GlobalService.User) { List <string> sharedList = GetSharedList(GlobalService.DbTable, sPath); foreach (string shared in sharedList) { if (shared == "-") { continue; } if (!UserUtil.IsCnMember(shared.Trim()) && !UserUtil.IsVnMember(shared.Trim()) && !UserUtil.IsJpMember(shared.Trim())) { string tableName = "TB_" + AdUtil.GetUserIdByUsername(shared, "kmhk.local"); string sharedText = string.Format("delete from " + tableName + " where r_path = N'{0}'", sPath); queryList.Add(sharedText); } else { string sharedText = string.Format("delete from TB_OUTSIDE_SHARE where o_path = N'{0}'", sPath); queryList.Add(sharedText); } } string ownerText = string.Format("delete from " + GlobalService.DbTable + " where r_path = N'{0}'", sPath); queryList.Add(ownerText); if (File.Exists(path)) { if (GlobalService.User == UserUtil.HrUserName1()) //if (GlobalService.User == "Ling Wai Man(凌慧敏,Velma)") { string directory = @"\\kdthk-dm1\project\IT System\MyCloud Record\" + DateTime.Today.ToString("yyyyMMdd"); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } string filename = Path.GetFileName(path); File.Copy(path, directory + @"\" + filename); } File.Delete(path); } string delQuery = string.Format("delete from S_OUT_SHARE where o_path = N'{0}'", sPath); DataServiceMes.GetInstance().ExecuteNonQuery(delQuery); } else { string tableName = "TB_" + AdUtil.GetUserIdByUsername(owner, "kmhk.local"); List <string> sharedList = GetSharedList(tableName, sPath); sharedList.Remove(GlobalService.User); string shared = string.Join(";", sharedList.ToArray()); if (shared == "") { shared = "-"; } string ownerText = string.Format("update " + tableName + " set r_shared = N'{0}' where r_path = N'{1}'", shared, sPath); queryList.Add(ownerText); string sharedText = string.Format("delete from " + GlobalService.DbTable + " where r_path = N'{0}'", sPath); queryList.Add(sharedText); } if (row.RowState != DataRowState.Deleted) { row.Delete(); } } string now = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); string query = string.Format("insert into TB_LOG (log_datetime, log_category, log_path, log_by) values ('{0}', '{1}', N'{2}', N'{3}')", now, "Delete", sPath, GlobalService.User); queryList.Add(query); foreach (string text in queryList) { DataService.GetInstance().ExecuteNonQuery(text); } //QueryUtil.InsertDataToLocalDb(text); }
private void btnOK_Click(object sender, EventArgs e) { string now = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); if (!rbtnApprove.Checked && !rbtnReject.Checked) { DialogResult = DialogResult.Cancel; } else if (rbtnApprove.Checked) { string query = _status == "上司承認中" ? string.Format("update TB_FORM_R3 set r_approval = 'Yes', r_status = N'申請已發送' where r_chaseno = '{0}'", _chaseno) : string.Format("update TB_FORM_R3 set r_cmapproval = 'Yes', r_cmappdate = '{0}', r_status = N'申請處理完成' where r_chaseno = '{1}'", now, _chaseno); DataService.GetInstance().ExecuteNonQuery(query); if (_status == "上司承認中") { string mail = AdUtil.GetEmailByUsername(_applicant, "kmhk.local"); EformUtil.SendR3NotificationEmail(_chaseno, "R3申請", _applicant, mail, _title, EformUtil.GetR3Id(_chaseno), EformUtil.GetR3Request(_chaseno), EformUtil.GetR3Reason(_chaseno)); } else { EformUtil.SendNotificationEmail(_chaseno, "R3申請", GlobalService.User, AdUtil.GetEmailByUsername(GlobalService.User, "kmhk.local"), "經管承認完了", "", 0, 0, null); } DialogResult = DialogResult.OK; } else { string query = _status == "上司承認中" ? string.Format("update TB_FORM_R3 set r_approval = 'Reject', r_status = N'上司已拒絕' where r_chaseno = '{0}'", _chaseno) : string.Format("update TB_FORM_R3 set r_cmapproval = 'Reject', r_status = N'經管已拒絕' where r_chaseno = '{0}'", _chaseno); DataService.GetInstance().ExecuteNonQuery(query); EformUtil.SendNotificationEmail(_chaseno, "R3申請", GlobalService.User, AdUtil.GetEmailByUsername(GlobalService.User, "kmhk.local"), "經管已拒絕", "", 0, 0, null); DialogResult = DialogResult.OK; } }
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); } }
private void SaveData() { SharedUtil.UpdateEmptyShared(); SharedUtil.UpdateShared(); string sPath = _filePath.Contains("'") ? _filePath.Replace("'", "''") : _filePath; DataRow[] rows = GlobalService.RootTable.Select(string.Format("filepath = '{0}'", sPath)); List <string> hklist = new List <string>(); List <string> cnlist = new List <string>(); List <string> vnlist = new List <string>(); List <string> jplist = new List <string>(); foreach (DataGridViewRow row in dgvUser.Rows) { string loc = row.Cells[1].Value.ToString().Trim(); if (loc == "HK") { hklist.Add(row.Cells[0].Value.ToString().Trim()); } else if (loc == "CN") { cnlist.Add(row.Cells[0].Value.ToString().Trim()); } else if (loc == "VN") { vnlist.Add(row.Cells[0].Value.ToString().Trim()); } else { jplist.Add(row.Cells[0].Value.ToString().Trim()); } } //FileInfo info = new FileInfo(_filePath); //FileSecurity fs = info.GetAccessControl(); //AuthorizationRuleCollection rules = fs.GetAccessRules(true, true, typeof(NTAccount)); if (deleteList.Count > 0) { PermissionUtil.RemovePermission(deleteList, _filePath); } if (deleteCnList.Count > 0) { PermissionUtil.RemoveGlobalPermission(deleteCnList, _filePath, "kmcn.local"); } if (deleteVnList.Count > 0) { PermissionUtil.RemoveGlobalPermission(deleteVnList, _filePath, "kdtvn.local"); } if (deleteJpList.Count > 0) { PermissionUtil.RemoveGlobalPermission(deleteJpList, _filePath, "km.local"); } if (hklist.Count > 0) { PermissionUtil.SetPermission(hklist, _filePath); } if (cnlist.Count > 0) { PermissionUtil.SetGlobalPermission(cnlist, _filePath, "kmcn.local"); } if (vnlist.Count > 0) { PermissionUtil.SetGlobalPermission(vnlist, _filePath, "kdtvn.local"); } if (jplist.Count > 0) { PermissionUtil.SetGlobalPermission(jplist, _filePath, "km.local"); } List <string> totalList = hklist.Concat(cnlist).Concat(vnlist).Concat(jplist).ToList(); string shared = totalList.Count == 0 ? "-" : string.Join(";", totalList.ToArray()); foreach (DataRow row in rows) { if (shared == "") { shared = "-"; } row["shared"] = shared; string text = string.Format("update " + GlobalService.DbTable + " set r_shared = N'{0}' where r_path = N'{1}'", shared, sPath); DataService.GetInstance().ExecuteNonQuery(text); } string disc = DiscUtil.IsDisc(GlobalService.RootTable, _filePath) ? "True" : "False"; string extension = Path.GetExtension(_filePath); if (_fileName.Contains("'")) { _fileName = _fileName.Replace("'", "''"); } if (_keyword.Contains("'")) { _keyword = _keyword.Replace("'", "''"); } foreach (string sharedPerson in hklist) { string tableName = "TB_" + AdUtil.GetUserIdByUsername(sharedPerson.Trim(), "kmhk.local"); string sharedDivision = SystemUtil.GetDivision(sharedPerson.Trim()); string sharedDepartment = SystemUtil.GetDepartment(sharedPerson.Trim()); string sharedVpath = sharedDivision != GlobalService.Division && _vpath.StartsWith(@"\" + GlobalService.Division) ? @"\Documents" + _vpath : sharedDepartment != GlobalService.DepartmentFolder && _vpath.StartsWith(@"\Common") ? @"\Documents" + _vpath : _vpath; string sharedText = string.Format("if not exists (select * from " + tableName + " where r_path = N'{7}') insert into " + tableName + " (r_filename, r_extension, r_keyword, r_lastaccess, r_lastmodified, r_owner, r_shared, r_path, r_vpath, r_deletedate, r_disc)" + " values (N'{0}', '{1}', N'{2}', '{3}', '{4}', N'{5}', N'{6}', N'{7}', N'{8}', '{9}', '{10}')", _fileName, extension, _keyword, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), _lastModified, GlobalService.User, sharedPerson.Trim(), sPath, sharedVpath, "2099/12/31", disc); DataService.GetInstance().ExecuteNonQuery(sharedText); } SharedUtil.SharedCN(cnlist, sPath, _fileName, _keyword); SharedUtil.SharedVN(vnlist, sPath, _fileName, _keyword); SharedUtil.SharedJp(jplist, sPath, _fileName, _keyword); try { List <string> receiverlist = cnlist.Concat(vnlist).Concat(jplist).ToList(); if (receiverlist.Count > 0) { EmailUtil.SendNotificationEmail(receiverlist); } } catch (Exception ex) { Debug.WriteLine(ex.Message + ex.StackTrace); } DialogResult = DialogResult.OK; }
private void LoadSharedNotOwner(string filePath, string owner) { string tableName = "TB_" + AdUtil.GetUserIdByUsername(owner, "kmhk.local"); filePath = filePath.Contains("'") ? filePath.Replace("'", "''") : filePath; string query = string.Format("select r_shared from " + tableName + " where r_path = N'{0}'", filePath); List <string> tmplist = new List <string>(); using (GlobalService.Reader = DataService.GetInstance().ExecuteReader(query)) { while (GlobalService.Reader.Read()) { string shared = GlobalService.Reader.GetString(0); List <string> sharedlist = shared.Split(';').ToList(); foreach (string item in sharedlist) { if (item != GlobalService.User && !lbShare.Items.Contains(item) && item != "-") { lbShare.Items.Add(item); } } foreach (string item in sharedlist) { if (item != "-" && item != GlobalService.User) { if (!tmplist.Contains(item)) { tmplist.Add(item); dgvUser.Rows.Add(item, "HK"); } } } } } foreach (string gShared in LoadGlobalSharedList(filePath)) { if (!tmplist.Contains(gShared)) { tmplist.Add(gShared); if (UserUtil.IsCnMember(gShared)) { dgvUser.Rows.Add(gShared, "CN"); } else if (UserUtil.IsVnMember(gShared)) { dgvUser.Rows.Add(gShared, "VN"); } else { dgvUser.Rows.Add(gShared, "JP"); } } } dgvUser.Rows.Add(owner, "HK"); //lbShare.Items.Add(owner); }
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) { string title = cbCategory.Text + " " + cbR3Category.Text; string startdate = dtpStart.Value.ToString("yyyy/MM/dd"); string comment = txtComment.Text.Trim(); string attachment = txtAttachment.Text.Trim(); string category = cbCategory.Text.Trim(); string r3Category = cbR3Category.Text.Trim(); string status = cbStatus.Text == "Completed" ? "經管承認中" : "IT處理中"; string applicant = DataUtil.GetApplicant(GlobalService.ChaseNo); string head = DataUtil.GetHead(applicant); string chaseno = DataUtil.GetR3Chaseno(); string cmApprover = txtCmApprover.Text.Trim(); //string itApprover = "Chan Fai Lung(陳輝龍,Onyx)"; string itApprover = UserUtil.ItUserName2(); if (cbStatus.Text == "Cancel") { string query = string.Format("delete from TB_FORM where f_chaseno = '{0}'", GlobalService.ChaseNo); DataService.GetInstance().ExecuteNonQuery(query); } else { string filePath = ""; if (attachment != "") { string filename = Path.GetFileName(attachment); string directory = @"\\kdthk-dm1\project\kdthk-dm\Forms\R3 Application\IT Attachments\"; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } File.Copy(attachment, directory + filename, true); filePath = directory + filename; } string query = string.Format("insert into TB_FORM_R3 (r_chaseno, r_status, r_applicant, r_created, r_title, r_category, r_type, r_content, r_start" + ", r_approver, r_approval, r_cmapprover, r_cmapproval, r_itapprover, r_itapproval, r_itattachment, r_itcomment, r_refno) values ('{0}', N'{1}', N'{2}'" + ", '{3}', N'{4}', N'{5}', '{6}', N'{7}', '{8}', N'{9}', '{10}', N'{11}', '{12}', N'{13}', N'{14}', N'{15}', N'{16}', '{17}')", chaseno, status, applicant, DateTime.Today.ToString("yyyy/MM/dd"), title, category, r3Category, "", startdate, head, "Yes", cmApprover, "No", itApprover, "Yes", filePath, comment, GlobalService.ChaseNo); DataService.GetInstance().ExecuteNonQuery(query); string from = AdUtil.GetEmailByUserId(AdUtil.GetUserIdByUsername(GlobalService.User)); string to = AdUtil.GetEmailByUserId(AdUtil.GetUserIdByUsername(cmApprover)); EformUtil.SendR3ApprovalEmail(title, comment, filePath, "", from, to, GlobalService.User); } if (SavedEvent != null) { SavedEvent(this, new EventArgs()); } }
private void SaveData() { dgvOutstanding.EndEdit(); string vendor = txtVendorCode.Text.Trim(); string vendorname = txtVendorName.Text.Trim(); string invoice = txtInvoice.Text.Trim(); string currency = cbCurr.Text; string indate = dtpInput.Value.ToString("yyyy/MM/dd"); string paydate = dtpPaymentDate.Value.ToString("yyyy/MM/dd"); string total = txtAmount.Text.Trim(); if (!AccUtil.IsVendorExists(vendor)) { MessageBox.Show("Vendor: " + vendor + " does not exist. Please check your data."); return; } if (AccUtil.IsInvoiceExists(invoice, vendor)) { MessageBox.Show("Invoice: " + invoice + " has been used."); return; } string signal = dtpInput.Value.Month == DateTime.Today.Month ? "True" : "False"; string sectHead = UserUtil.GetSectionHead(UserUtil.GetSect(GlobalService.User)); string divHead = UserUtil.GetDivisionHead(UserUtil.GetDivision(GlobalService.User)); string dept = UserUtil.GetDept(GlobalService.User); string deptHead = dept.Contains("RPS") ? UserUtil.GetDepartmentHead(dept) : ""; string cm1st = "Lee Suk Ha(李淑霞,Zoe)"; string cm2nd = "Li Yuen Yan(李婉茵,Sharon)"; bool isValid = true; List <Outstanding> list = new List <Outstanding>(); foreach (DataGridViewRow row in dgvOutstanding.Rows) { if (row.IsNewRow) { continue; } if (row.Cells[0].Value == null && row.Cells[2].Value == null && row.Cells[4].Value == null && row.Cells[5].Value == null && row.Cells[6].Value == null && row.Cells[7].Value == null && row.Cells[8].Value == null && row.Cells[9].Value == null) { continue; } if (row.Cells[0].Value == null || row.Cells[2].Value == null || row.Cells[4].Value == null || row.Cells[5].Value == null) { isValid = false; } string desc1 = "", desc2 = "", desc3 = "", desc4 = "", desc5 = ""; try { desc1 = row.Cells[5].Value.ToString().Trim(); desc2 = row.Cells[6].Value == null ? "" : row.Cells[6].Value.ToString().Trim(); desc3 = row.Cells[7].Value == null ? "" : row.Cells[7].Value.ToString().Trim(); desc4 = row.Cells[8].Value == null ? "" : row.Cells[8].Value.ToString().Trim(); desc5 = row.Cells[9].Value == null ? "" : row.Cells[9].Value.ToString().Trim(); } catch { isValid = false; } string acc = row.Cells[0].Value.ToString().Trim(); string accountcode = acc.Substring(0, 10); string accname = acc.Substring(12); accname = accname.Substring(0, accname.Length - 1); string cc = row.Cells[2].Value.ToString().Trim(); string costcentre = cc.Substring(0, 10); string costcentrename = cc.Substring(12); costcentrename = costcentrename.Substring(0, costcentrename.Length - 1); string inputAmount = row.Cells[4].Value.ToString().Trim(); list.Add(new Outstanding { VendorCode = vendor, Invoice = invoice, AccountCode = accountcode, CostCentre = costcentre, Amount = inputAmount, Desc1 = desc1, Desc2 = desc2, Desc3 = desc3, Desc4 = desc4, Desc5 = desc5 }); } if (!isValid) { MessageBox.Show("Please check the following:\n1. Select AccountCode & CostCentre.\n2. Input Amount.\n3. Remarks 1 must be input.", "Error found", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { string invoiceText = string.Format("insert into TB_ACC_MASTER_INVOICE (i_invoice, i_vendor) values ('{0}', '{1}')", invoice, vendor); DataServiceCM.GetInstance().ExecuteNonQuery(invoiceText); string name = AccUtil.GetVendorName(vendor); string curr = AccUtil.GetVendorCurrency(vendor); string payterm = AccUtil.GetVendorPayTerm(vendor); string query = string.Format("insert into TB_ACC_OUTSTANDING (o_invoice, o_vendor, o_vendorname, o_inputdate, o_paymentdate, o_currency, o_amount, o_createdby" + ", o_created, o_div, o_staff, o_acc, o_sect, o_dept) values ('{0}', '{1}', N'{2}', '{3}', '{4}', '{5}', '{6}', N'{7}', '{8}', N'{9}', N'{10}', N'{11}', N'{12}', N'{13}')", invoice, vendor, name, indate, paydate, currency, total, GlobalService.User, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), divHead, cm1st, cm2nd, sectHead, deptHead); DataServiceCM.GetInstance().ExecuteNonQuery(query); foreach (Outstanding item in list) { int id = AccUtil.GetOutstandingIdByInvoice(item.Invoice); string accname = AccUtil.GetAccountName(item.AccountCode); string costcentrename = AccUtil.GetCostCentreName(item.CostCentre); string desc = (item.Desc1 + item.Desc2 + item.Desc3 + item.Desc4 + item.Desc5); desc = desc.Substring(0, Math.Min(desc.Length, 50)); string text = string.Format("insert into TB_ACC_OUTSTANDING_DETAIL (od_o_id, od_accountcode, od_accountname, od_costcentre, od_costcentrename, od_amount" + ", od_desc1, od_desc2, od_desc3, od_desc4, od_desc5, od_display) values ('{0}', '{1}', N'{2}', '{3}', N'{4}', '{5}', N'{6}', N'{7}', N'{8}', N'{9}', N'{10}', N'{11}')", id, item.AccountCode, accname, item.CostCentre, costcentrename, DoFormat(item.Amount), item.Desc1, item.Desc2, item.Desc3, item.Desc4, item.Desc5, desc); DataServiceCM.GetInstance().ExecuteNonQuery(text); } string content = "Application Approval required. Please click <a href=\"\\\\kdthk-dm1\\project\\it system\\MyCloud Beta\\KDTHK-DM-SP.application\">HERE</a> to approval process."; string body = "<p><span style=\"font-family: Calibri;\">" + content + "</span></p>"; KDTHK_DM_SP.utils.EformUtil.SendApprovalEmail(invoice, GlobalService.User, AdUtil.GetEmailByUsername(GlobalService.User, "kmhk.local"), AdUtil.GetEmailByUsername(sectHead, "kmhk.local"), body, "Outstanding Slip"); MessageBox.Show("Record has been saved."); DialogResult = DialogResult.OK; } }
private void btnConfirm_Click(object sender, EventArgs e) { string sectHead = UserUtil.GetSectionHead(UserUtil.GetSect(GlobalService.User)); string divHead = UserUtil.GetDivisionHead(UserUtil.GetDivision(GlobalService.User)); string dept = UserUtil.GetDept(GlobalService.User); string deptHead = dept.Contains("RPS") ? UserUtil.GetDepartmentHead(dept) : ""; string cm1st = "Lee Suk Ha(李淑霞,Zoe)"; string cm2nd = "Li Yuen Yan(李婉茵,Sharon)"; foreach (DataGridViewRow row in dgvPreview.Rows) { string invoice = row.Cells[2].Value.ToString().Trim(); string code = row.Cells[0].Value.ToString().Trim(); string name = row.Cells[1].Value.ToString().Trim(); string currency = AccUtil.GetVendorCurrency(code); string payterm = AccUtil.GetVendorPayTerm(code); string paydate = AccUtil.PayDate(Convert.ToDateTime(DateTime.Today.ToString("yyyy/MM/dd")), payterm); string total = row.Cells[3].Value.ToString().Trim(); string invoiceText = string.Format("insert into TB_ACC_MASTER_INVOICE (i_invoice, i_vendor) values ('{0}', '{1}')", invoice, code); DataServiceCM.GetInstance().ExecuteNonQuery(invoiceText); string query = string.Format("insert into TB_ACC_OUTSTANDING (o_invoice, o_vendor, o_vendorname, o_inputdate, o_paymentdate, o_currency, o_amount, o_createdby" + ", o_created, o_div, o_staff, o_acc, o_sect, o_dept) values ('{0}', '{1}', N'{2}', '{3}', '{4}', '{5}', '{6}', N'{7}', '{8}', N'{9}', N'{10}', N'{11}', N'{12}', N'{13}')", invoice, code, name, DateTime.Today.ToString("yyyy/MM/dd"), paydate, currency, total, GlobalService.User, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), divHead, cm1st, cm2nd, sectHead, deptHead); DataServiceCM.GetInstance().ExecuteNonQuery(query); //KDTHK_DM_SP.utils.EformUtil.SendApprovalEmail(invoice, GlobalService.User, AdUtil.GetEmailByUsername(GlobalService.User, "kmhk.local"), AdUtil.GetEmailByUsername(sectHead, "kmhk.local"), "", "Outstanding Slip"); } foreach (Outstanding item in dataList) { int id = AccUtil.GetOutstandingIdByInvoice(item.Invoice); string acName = AccUtil.GetAccountName(item.AccountCode); string ccName = AccUtil.GetCostCentreName(item.CostCentre); string desc = (item.Desc1 + item.Desc2 + item.Desc3 + item.Desc4 + item.Desc5); desc = desc.Substring(0, Math.Min(desc.Length, 50)); string text = string.Format("insert into TB_ACC_OUTSTANDING_DETAIL (od_o_id, od_accountcode, od_accountname, od_costcentre, od_costcentrename, od_amount" + ", od_desc1, od_desc2, od_desc3, od_desc4, od_desc5, od_display) values ('{0}', '{1}', N'{2}', '{3}', N'{4}', '{5}', N'{6}', N'{7}', N'{8}', N'{9}', N'{10}', N'{11}')", id, item.AccountCode, acName, item.CostCentre, ccName, item.Amount, item.Desc1, item.Desc2, item.Desc3, item.Desc4, item.Desc5, desc); DataServiceCM.GetInstance().ExecuteNonQuery(text); } string content = "Application Approval required. Please click <a href=\"\\\\kdthk-dm1\\project\\it system\\MyCloud Beta\\KDTHK-DM-SP.application\">HERE</a> to approval process."; string body = "<p><span style=\"font-family: Calibri;\">" + content + "</span></p>"; bool isSent = false; if (!isSent) { isSent = true; KDTHK_DM_SP.utils.EformUtil.SendApprovalEmail("", GlobalService.User, AdUtil.GetEmailByUsername(GlobalService.User, "kmhk.local"), AdUtil.GetEmailByUsername(sectHead, "kmhk.local"), body, "Outstanding Slip"); } MessageBox.Show("Record has been saved."); DialogResult = DialogResult.OK; }
private void btnSave_Click(object sender, EventArgs e) { string appType = cbAppType.SelectedItem.ToString().Trim(); string reason = txtReason.Text.Trim(); string vendorType = cbVendorType.SelectedItem.ToString().Trim(); string vendorCode = txtVendorCode.Text.Trim(); string vendorName = txtVendorName.Text.Trim(); string addr1 = txtAddr1.Text.Trim(); string addr2 = txtAddr2.Text.Trim(); string addr3 = txtAddr3.Text.Trim(); string person = txtPerson.Text.Trim(); string phone = txtPhone.Text.Trim(); string email = txtEmail.Text.Trim(); string currency = cbCurrency.SelectedItem.ToString().Trim(); string payterm = txtPayterm.Text.Trim(); string fob = cbFob.SelectedItem.ToString().Trim(); if (reason.Contains("'")) { reason = reason.Replace("'", "''"); } if (vendorName.Contains("'")) { vendorName = vendorName.Replace("'", "''"); } if (addr1.Contains("'")) { addr1 = addr1.Replace("'", "''"); } if (addr2.Contains("'")) { addr2 = addr2.Replace("'", "''"); } if (addr3.Contains("'")) { addr3 = addr3.Replace("'", "''"); } string divHead = "Ho Kin Hang(何健恒,Ken)"; //UserUtil.GetDiv(GlobalService.User); string cm1st = "Ho Kin Hang(何健恒,Ken)"; //"Ng Wai Kwan(吳蕙君,Wendy)"; string cm2nd = "Ho Kin Hang(何健恒,Ken)"; //"Li Yuen Yan(李婉茵,Sharon)"; string cm3rd = "Ho Kin Hang(何健恒,Ken)"; //"Leung Wai Yip(梁偉業,Philip)"; string cm4th = "Ho Kin Hang(何健恒,Ken)"; //"Hara Masatoshi(原雅俊)"; string attachment = ""; string query = string.Format("insert into TB_ACC_VENDOR (v_type, v_reason, v_vendortype, v_code, v_name, v_addr1, v_addr2, v_addr3, v_person, v_phone, v_email" + ", v_currency, v_payterm, v_fob, v_attachment, v_created, v_createdby, v_div, v_cm1st, v_cm2nd, v_cm3rd, v_cm4th) values ('{0}', N'{1}', N'{2}', '{3}', N'{4}', N'{5}', N'{6}'" + ", N'{7}', N'{8}', '{9}', '{10}', '{11}', '{12}', '{13}', N'{14}', '{15}', N'{16}', N'{17}', N'{18}', N'{19}', N'{20}', N'{21}')", appType, reason, vendorType, vendorCode, vendorName, addr1, addr2, addr3, person, phone, email, currency, payterm, fob, "", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), GlobalService.User, divHead, cm1st, cm2nd, cm3rd, cm4th); DataServiceCM.GetInstance().ExecuteNonQuery(query); EformUtil.SendApprovalEmail("", GlobalService.User, AdUtil.GetEmailByUsername(GlobalService.User, "kmhk.local"), AdUtil.GetEmailByUsername(divHead, "kmhk.local"), "", "Vendor Master Application - " + appType); DialogResult = DialogResult.OK; }
private void btnSave_Click(object sender, EventArgs e) { List <string> queryList = new List <string>(); foreach (DataGridViewRow row in dgvShareSetup.Rows) { string name = row.Cells[0].Value.ToString(); string path = row.Cells[1].Value.ToString(); string folder = row.Cells[2].Value.ToString(); string shared = row.Cells[3].Value.ToString(); string keyword = row.Cells[4].Value.ToString(); string modified = row.Cells[5].Value.ToString(); string disc = row.Cells[6].Value.ToString(); string oShared = row.Cells[7].Value.ToString(); string extension = Path.GetExtension(path); string now = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); if (keyword == "") { keyword = name; } //if (shared == oShared) // continue; FileInfo info = new FileInfo(path); FileSecurity fs = info.GetAccessControl(); AuthorizationRuleCollection rules = fs.GetAccessRules(true, true, typeof(NTAccount)); foreach (FileSystemAccessRule rule in rules) { fs.RemoveAccessRuleSpecific(rule); } fs.SetAccessRuleProtection(true, false); fs.AddAccessRule(new FileSystemAccessRule(@"kmhk\itadmin", FileSystemRights.FullControl, AccessControlType.Allow)); fs.AddAccessRule(new FileSystemAccessRule(AdUtil.GetUserIdByUsername(GlobalService.User, "kmhk.local"), FileSystemRights.FullControl, AccessControlType.Allow)); string sPath = path.Contains("'") ? path.Replace("'", "''") : path; if (DataUtil.IsRecordExists(path)) { List <string> list = DataUtil.GetSharedList(GlobalService.DbTable, path); if (list.Count > 0) { foreach (string item in list) { if (!UserUtil.IsCnMember(item.Trim()) && !UserUtil.IsVnMember(item.Trim()) && !UserUtil.IsJpMember(item.Trim())) { string tbName = "TB_" + AdUtil.GetUserIdByUsername(item.Trim(), "kmhk.local"); string delText = string.Format("delete from " + tbName + " where r_path = N'{0}' and r_owner = N'{1}'", sPath, GlobalService.User); DataService.GetInstance().ExecuteNonQuery(delText); } else { string delText = string.Format("delete from S_OUT_SHARE where o_path = N'{0}' and o_to = N'{1}'", sPath, item.Trim()); DataServiceMes.GetInstance().ExecuteNonQuery(delText); } } } } List <string> sharedList = shared.Split(';').ToList(); List <string> hklist = new List <string>(); List <string> cnlist = new List <string>(); List <string> vnlist = new List <string>(); List <string> jplist = new List <string>(); foreach (string item in sharedList) { if (UserUtil.IsCnMember(item.Trim())) { cnlist.Add(item.Trim()); } else if (UserUtil.IsVnMember(item.Trim())) { vnlist.Add(item.Trim()); } else if (UserUtil.IsJpMember(item.Trim())) { jplist.Add(item.Trim()); } else { hklist.Add(item.Trim()); } } if (name.Contains("'")) { name = name.Replace("'", "''"); } if (keyword.Contains("'")) { keyword = keyword.Replace("'", "''"); } if (shared != "-") { foreach (string item in hklist) { string sharedId = AdUtil.GetUserIdByUsername(item.Trim(), "kmhk.local"); string tableName = "TB_" + sharedId; string sharedDivision = SystemUtil.GetDivision(item.Trim()); string sharedDepartment = SystemUtil.GetDepartment(item.Trim()); fs.AddAccessRule(new FileSystemAccessRule(sharedId, FileSystemRights.Modify, AccessControlType.Allow)); if (UserUtil.IsSpecialUser(item)) //if (item == "Chow Chi To(周志滔,Sammy)" || item == "Ling Wai Man(凌慧敏,Velma)" || item == "Chan Fai Lung(陳輝龍,Onyx)" || item == "Ng Lau Yu, Lilith (吳柳如)" || // item == "Lee Miu Wah(李苗華)" || item == "Lee Ming Fung(李銘峯)" || item == "Ho Kin Hang(何健恒,Ken)" || item == "Yeung Wai, Gabriel (楊偉)") { string asText = string.Format("select as_userid from TB_USER_AS where as_user = N'{0}'", item.Trim()); string asId = DataService.GetInstance().ExecuteScalar(asText).ToString().Trim(); fs.AddAccessRule(new FileSystemAccessRule(asId, FileSystemRights.Modify, AccessControlType.Allow)); } string sharedVpath = sharedDivision != GlobalService.Division && folder.StartsWith(@"\" + GlobalService.Division) ? @"\Documents" + folder : sharedDepartment != GlobalService.Department && folder.StartsWith(@"\Common") ? @"\Documents" + folder : folder; if (sharedVpath.Contains("'")) { sharedVpath.Replace("'", "''"); } string sharedText = string.Format("insert into " + tableName + " (r_filename, r_extension, r_keyword, r_lastaccess, r_lastmodified, r_owner, r_shared, r_path, r_vpath, r_deletedate)" + " values (N'{0}', '{1}', N'{2}', '{3}', '{4}', N'{5}', N'{6}', N'{7}', N'{8}', '{9}')", name, extension, keyword, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), modified, GlobalService.User, item.Trim(), sPath, sharedVpath, "2099/12/31"); queryList.Add(sharedText); try { File.SetAccessControl(path, fs); } catch (Exception ex) { Debug.WriteLine(ex.Message + ex.StackTrace); continue; } } if (cnlist.Count > 0) { PermissionUtil.SetGlobalPermission(cnlist, path, "kmcn.local"); SharedUtil.SharedCN(cnlist, sPath, name, keyword); } if (vnlist.Count > 0) { PermissionUtil.SetGlobalPermission(vnlist, path, "kdtvn.local"); SharedUtil.SharedVN(vnlist, sPath, name, keyword); } if (jplist.Count > 0) { PermissionUtil.SetGlobalPermission(jplist, path, "km.local"); SharedUtil.SharedJp(jplist, sPath, name, keyword); } } try { List <string> receiverlist = cnlist.Concat(vnlist).Concat(jplist).ToList(); if (receiverlist.Count > 0) { EmailUtil.SendNotificationEmail(receiverlist); } } catch (Exception ex) { Debug.WriteLine(ex.Message + ex.StackTrace); } if (shared == "") { shared = "-"; } string ownerText = string.Format("update " + GlobalService.DbTable + " set r_shared = N'{0}' where r_path = N'{1}'", shared, sPath); queryList.Add(ownerText); } foreach (string text in queryList) { DataService.GetInstance().ExecuteNonQuery(text); } GlobalService.RootTable = RootUtil.RootDataTable(); this.DialogResult = DialogResult.OK; }
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) { List <FaApplicationList> list = new List <FaApplicationList>(); foreach (DataGridViewRow row in dgvMain.Rows) { string isChecked = row.Cells[15].FormattedValue.ToString(); if (isChecked != "True") { continue; } string chaseno = row.Cells[0].Value.ToString().Trim(); string vendor = row.Cells[1].Value.ToString().Trim(); string vendorname = row.Cells[2].Value.ToString().Trim(); string partno = row.Cells[3].Value.ToString().Trim(); string itemtext = row.Cells[11].Value.ToString().Trim(); string ringi = row.Cells[13].Value.ToString().Trim(); string mouldJig = row.Cells[14].Value.ToString().Trim(); list.Add(new FaApplicationList { Chaseno = chaseno, Itemcode = partno, Itemtext = itemtext, Ringi = ringi, Vendor = vendor + " " + vendorname, AppType = mouldJig }); } if (list.Count > 0) { switch (MessageBox.Show("Are you sure to apply " + list.Count + " item for Fixed Asset?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { case DialogResult.Yes: DataTable pdfTable = new DataTable(); string[] headers = { "ChaseNo", "Item Text", "Item Code", "Ringi", "Vendor" }; foreach (string header in headers) { pdfTable.Columns.Add(header); } string pdfFile = DataUtil.GetLatestPdfId(); string today = DateTime.Today.ToString("yyyy/MM/dd"); int mouldCount = 0; int jigCount = 0; foreach (FaApplicationList item in list) { string query = string.Format("update tb_betamould set tm_st_code = 'A', tm_ringi_code = '{0}', tm_pdfid = '{1}' where tm_chaseno = '{2}'", item.Ringi, pdfFile, item.Chaseno); DataService.GetInstance().ExecuteNonQuery(query); pdfTable.Rows.Add(item.Chaseno, item.Itemtext, item.Itemcode, item.Ringi, item.Vendor); string mpa = DataUtil.GetMpa(item.Chaseno) == "True" ? "Yes" : "No"; string vendor = DataUtil.GetVendor(item.Chaseno); string path = @"\\kdthk-dm1\moss$\cm\FixedAssets\" + pdfFile + ".pdf"; string model = DataUtil.GetModel(item.Chaseno); string currency = DataUtil.GetCurrency(item.Chaseno); string amount = DataUtil.GetAmount(item.Chaseno); string approvalText = string.Format("insert into TB_FA_APPROVAL (f_request, f_applicant, f_type, f_chaseno, f_pdfid, f_status, f_desc, f_mpa, f_vendor, f_attachment" + ", f_mould, f_ringi, f_model, f_currency, f_amount, f_assetdesc, f_ipo1st, f_ipo2nd, f_partno, f_apptype) values ('{0}', N'{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}', '{13}', '{14}', '{15}', N'{16}', N'{17}', '{18}', '{19}')" , today, GlobalService.Owner, "Acquisition", item.Chaseno, pdfFile, "IPO 1st Approval", item.Itemtext, mpa, vendor, path, item.Chaseno, item.Ringi, model, currency, amount , item.Vendor, GlobalService.IPO1st, GlobalService.IPO2nd, item.Itemcode, item.AppType); DataServiceNew.GetInstance().ExecuteNonQuery(approvalText); if (item.AppType == "Mould") { mouldCount += 1; } if (item.AppType == "Jigs") { jigCount += 1; } } pdfTable.DefaultView.Sort = "ChaseNo ASC"; PdfUtil.ApplyFixedAssetPdf(pdfTable, pdfFile, mouldCount, jigCount); string from = AdUtil.GetEmailByUserId(AdUtil.GetUserIdByUsername(GlobalService.Owner, "kmhk.local"), "kmhk.local"); string to = AdUtil.GetEmailByUserId(AdUtil.GetUserIdByUsername(GlobalService.IPO1st, "kmhk.local"), "kmhk.local"); EmailUtil.SendEmail(from, to, "SpApp_Fixed Asset Application Approval Required"); DialogResult = DialogResult.OK; break; case DialogResult.No: break; } } }
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; } }
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(); } }
private void btnSave_Click(object sender, EventArgs e) { dgvApproval.EndEdit(); foreach (DataGridViewRow row in dgvApproval.Rows) { string approval = row.Cells[0].Value.ToString().Trim(); if (approval == "---") { continue; } string pdfid = row.Cells[3].Value.ToString().Trim(); string now = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); string query = ""; string applicant = row.Cells[2].Value.ToString().Trim(); string email = AdUtil.GetEmailByUserId(AdUtil.GetUserIdByUsername(applicant, "kmhk.local"), "kmhk.local"); if (GlobalService.Owner == GlobalService.IPO1st) { if (approval == "Approve") { query = string.Format("update TB_FA_APPROVAL set f_status = '{0}', f_ipo1stapp = '{1}', f_ipo1stdate = '{2}'" + " where f_pdfid = '{3}'", "IPO 2nd Approval", "Approve", now, pdfid); EmailUtil.SendEmail(email, "*****@*****.**", "SpApp_Fixed Asset Application Approval Required"); } else { query = string.Format("delete from TB_FA_APPROVAL where f_pdfid = '{0}'", pdfid); RejectStatus(pdfid); } } else { if (approval == "Approve") { query = string.Format("update TB_FA_APPROVAL set f_status = '{0}', f_ipo2ndapp = '{1}', f_ipo2nddate = '{2}', f_ringi1st = N'{3}', f_cm1st = N'{4}', f_cm2nd = N'{5}', f_cm3rd = N'{6}'" + " where f_pdfid = '{7}'", "Ringi Approval", "Approve", now, "Lai King Ho(黎景豪,Ken)", "Lee Suk Ha(李淑霞,Zoe)", "Li Yuen Yan(李婉茵,Sharon)", "Leung Wai Yip(梁偉業,Philip)", pdfid); try { EmailUtil.NotificationEmail(email, "*****@*****.**", "Fixed Asset Application Approval Required"); } catch { Debug.WriteLine("aaa"); } } else { query = string.Format("delete from TB_FA_APPROVAL where f_pdfid = '{0}'", pdfid); RejectStatus(pdfid); } } DataServiceNew.GetInstance().ExecuteNonQuery(query); } LoadData(); }
private void btnOK_Click(object sender, EventArgs e) { Login(@"kmhk.local\" + AdUtil.GetUserIdByUsername(txtUser.Text.Trim(), "kmhk.local"), txtPassword.Text.Trim()); }
private void SaveDataFile(DataTable table, string path) { if (string.IsNullOrEmpty(txtTarget.Text)) { MessageBox.Show("Please input file name."); return; } string sPath = path.Contains("'") ? path.Replace("'", "''") : path; DataRow[] rows = table.Select(string.Format("filepath = '{0}'", sPath)); string newPath = path.Replace(txtSource.Text, txtTarget.Text); //bool confirmed = true; //Debug.WriteLine(newPath); /*if (File.Exists(newPath)) * { * Debug.WriteLine("exists"); * switch (MessageBox.Show("Filename " + txtTarget.Text + " already exists. Do you want to overwrite it?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) * { * case DialogResult.Yes: * File.Delete(newPath); * break; * * case DialogResult.No: * confirmed = false; * break; * } * }*/ //if (confirmed) //{ File.Move(path, newPath); string fileName = txtTarget.Text; if (fileName.Contains("'")) { fileName = fileName.Replace("'", "''"); } string newPathSave = newPath.Contains("'") ? newPath.Replace("'", "''") : newPath; string tableName = "TB_" + AdUtil.GetUserIdByUsername(GlobalService.User, "kmhk.local"); List <string> sharedList = DataUtil.GetLocalSharedList(GlobalService.RootTable, path); List <string> queryList = new List <string>(); foreach (DataRow row in table.Rows) { row["filepath"] = newPath; row["filename"] = txtTarget.Text; } if (sharedList.Count > 0) { foreach (string shared in sharedList) { if (!UserUtil.IsCnMember(shared.Trim()) && !UserUtil.IsVnMember(shared.Trim()) && !UserUtil.IsJpMember(shared.Trim())) { string sharedTable = "TB_" + AdUtil.GetUserIdByUsername(shared.Trim(), "kmhk.local"); string sharedText = string.Format("update " + sharedTable + " set r_path = N'{0}', r_filename = N'{1}' where r_path = N'{2}'", newPathSave, fileName, sPath); DataService.GetInstance().ExecuteNonQuery(sharedText); } else { string sharedText = string.Format("update TB_OUTSIDE_SHARE set o_path = N'{0}', o_filename = N'{1}' where o_path = N'{2}'", newPathSave, fileName, sPath); DataService.GetInstance().ExecuteNonQuery(sharedText); } } } string ownerText = string.Format("update " + GlobalService.DbTable + " set r_path = N'{0}', r_filename = N'{1}' where r_path = N'{2}'", newPathSave, fileName, sPath); DataService.GetInstance().ExecuteNonQuery(ownerText); //} }
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 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 btnUpload_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); if (ofd.ShowDialog() == DialogResult.OK) { DataTable table = ImportExcel2007.TranslateToTable(ofd.FileName); List <int> invoiceIdList = new List <int>(); foreach (DataRow row in table.Rows) { string invoice = row.ItemArray[0].ToString().Trim(); string vendor = row.ItemArray[1].ToString().Trim(); string acccode = row.ItemArray[3].ToString().Trim(); string costcentre = row.ItemArray[4].ToString().Trim(); string amount = row.ItemArray[10].ToString().Trim(); string approval = row.ItemArray[11].ToString().Trim(); if (approval == "Yes") { int id = GetInvoiceId(invoice); string status = GetInvoiceStatus(invoice); string query = status == "會計處理中" ? string.Format("update TB_ACC_OUTSTANDING_DETAIL set od_staffapproval = 'Yes' where od_o_id = '{0}' and od_accountcode = '{1}'" + " and od_costcentre = '{2}' and od_amount = '{3}'", id, acccode, costcentre, amount) : string.Format("update TB_ACC_OUTSTANDING_DETAIL set od_divapproval = 'Yes'" + " where od_o_id = '{0}' and od_accountcode = '{1}' and od_costcentre = '{2}' and od_amount = '{3}'", id, acccode, costcentre, amount); DataServiceCM.GetInstance().ExecuteNonQuery(query); invoiceIdList.Add(id); } } invoiceIdList = invoiceIdList.Distinct().ToList(); string now = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); foreach (int item in invoiceIdList) { string status = GetInvoiceStatusById(item); string invoice = GetInvoiceById(item); string applicant = AccUtil.GetApplicant(invoice); string div = AccUtil.GetDivisionApprover(invoice); string staff = AccUtil.GetAccStaff(invoice); string acc = AccUtil.GetAccApprover(invoice); if (status == "會計處理中") { if (IsAllItemApprovedByStaff(item)) { string query = string.Format("update TB_ACC_OUTSTANDING set o_status = N'會計承認中', o_staffapproval = 'Yes', o_staffapprovaldate = '{0}' where o_id = '{1}'", now, item); DataServiceCM.GetInstance().ExecuteNonQuery(query); EformUtil.SendApprovalEmail(_invoice, applicant, AdUtil.GetEmailByUsername(applicant, "kmhk.local"), AdUtil.GetEmailByUsername(acc, "kmhk.local"), "", "Outstanding Slip - " + invoice); } } if (status == "會計承認中") { if (IsAllItemApprovedByAcc(item)) { string query = string.Format("update TB_ACC_OUTSTANDING set o_status = N'申請處理完成', o_accapproval = 'Yes', o_accapprovaldate = '{0}' where o_id = '{1}'", now, item); DataServiceCM.GetInstance().ExecuteNonQuery(query); EformUtil.SendFinishedEmail(_invoice, acc, AdUtil.GetEmailByUsername(acc, "kmhk.local"), AdUtil.GetEmailByUsername(applicant, "kmhk.local"), "Outstanding Slip Application Finished - " + invoice, "You Outstanding Slip Application has been finished."); } } } MessageBox.Show("Record has been uploaded."); } }
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; } }