public DataView loadEmpData(ListInfo info, DBManager db, Repeater repeater) { WebDatePicker PayPeriodAsOFDate = (WebDatePicker)EmployeeSearchControl1.AdditionElementControl.FindControl("PayPeriodAsOFDate"); DBFilter filter = binding.createFilter(); //if (info != null && info.orderby != null && !info.orderby.Equals("")) // filter.add(info.orderby, info.order); string select = "e.*, ep.*, pp.PayPeriodFr, pp.PayperiodTo, pp.PayPeriodConfirmDate"; string from = "from [" + db.dbclass.tableName + "] e, EmpPayroll ep, PayrollPeriod pp "; filter.add(new MatchField("e.EmpID", "ep.EmpID")); filter.add(new MatchField("ep.PayperiodID", "pp.PayperiodID")); filter.add(new Match("ep.EmpPayStatus", "C")); filter.add(WebUtils.AddRankFilter(Session, "e.EmpID", true)); DateTime dtPayPeriodAsOFDate; if (DateTime.TryParse(PayPeriodAsOFDate.Value, out dtPayPeriodAsOFDate)) { filter.add(new Match("pp.PayPeriodFr", "<=", dtPayPeriodAsOFDate)); filter.add(new Match("pp.PayPeriodTo", ">=", dtPayPeriodAsOFDate)); } if (dtPayPeriodAsOFDate.Ticks.Equals(0)) { dtPayPeriodAsOFDate = AppUtils.ServerDateTime().Date; } filter.add(new IN("e.EmpID", "Select EmpID from " + EEmpPersonalInfo.db.dbclass.tableName + " ee", EmployeeSearchControl1.GetEmpInfoFilter(dtPayPeriodAsOFDate, dtPayPeriodAsOFDate))); //if (filter.getOrderClause().IndexOf("PayPeriodFr")<0) // filter.add("EmpNo", true); DataTable table = filter.loadData(dbConn, null, select, from); table = EmployeeSearchControl1.FilterEncryptedEmpInfoField(table, info); view = new DataView(table); ListFooter.Refresh(); if (repeater != null) { repeater.DataSource = table; repeater.DataBind(); } return(view); }
protected void EmpExtraField_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType.Equals(ListItemType.Item) || e.Item.ItemType.Equals(ListItemType.AlternatingItem)) { TextBox textBox = (TextBox)e.Item.FindControl("EmpExtraFieldValue"); WebDatePicker datePicker = (WebDatePicker)e.Item.FindControl("EmpExtraFieldValueDateControl"); EEmpExtraField empExtraField = (EEmpExtraField)e.Item.DataItem; EEmpExtraFieldValue h = (EEmpExtraFieldValue)CurElements[empExtraField.EmpExtraFieldID]; string value = string.Empty; if (h != null) { value = h.EmpExtraFieldValue; } if (string.IsNullOrEmpty(empExtraField.EmpExtraFieldControlType)) { empExtraField.EmpExtraFieldControlType = EEmpExtraField.FIELD_CONTROL_TYPE_TEXTBOX; } if (empExtraField.EmpExtraFieldControlType.Equals(EEmpExtraField.FIELD_CONTROL_TYPE_TEXTAREA, StringComparison.CurrentCultureIgnoreCase)) { textBox.TextMode = TextBoxMode.MultiLine; textBox.Rows = 5; textBox.Text = value; textBox.Visible = true; datePicker.Visible = false; } else if (empExtraField.EmpExtraFieldControlType.Equals(EEmpExtraField.FIELD_CONTROL_TYPE_DATE, StringComparison.CurrentCultureIgnoreCase)) { datePicker.TextBox.Text = value; datePicker.Visible = true; textBox.Visible = false; } else { textBox.Text = value; textBox.Visible = true; datePicker.Visible = false; } textBox.Attributes.Add("EmpExtraFieldID", empExtraField.EmpExtraFieldID.ToString()); } }
// process gridview commands for detail lines protected void gvInvoiceLines_RowCommand(object sender, GridViewCommandEventArgs e) { int invoiceID = 0; int invoiceLineID = 0; Invoice invoice = null; InvoiceDetail invoiceLine = null; TextBox txtLineAmount; switch (e.CommandName) { case "DoSave": Page.Validate("invoice"); if (!Page.IsValid) { return; } Page.Validate("invoiceLine"); if (!Page.IsValid) { return; } saveInvoice(); break; case "DoEdit": invoiceLineID = Convert.ToInt32(e.CommandArgument); invoiceLine = InvoiceDetailManager.Get(invoiceLineID); if (invoiceLine != null) { ViewState["InvoiceLineID"] = invoiceLineID.ToString(); // date WebDatePicker txtDate = gvInvoiceLines.FooterRow.FindControl("txtDate") as WebDatePicker; if (txtDate != null && invoiceLine.LineDate != null) { txtDate.Text = string.Format("{0:MM/dd/yyyy}", invoiceLine.LineDate); } // service description DropDownList cbx = gvInvoiceLines.FooterRow.FindControl("cbxServiceDescription") as DropDownList; if (cbx != null && invoiceLine.ServiceTypeID != null) { ListItem item = cbx.Items.FindByText(invoiceLine.LineDescription.Trim()); if (item != null) { cbx.SelectedIndex = cbx.Items.IndexOf(item); } } else { ListItem item = new ListItem(invoiceLine.LineDescription, invoiceLine.LineDescription); cbx.Items.Add(item); cbx.Text = invoiceLine.LineDescription; } // quantity WebNumericEditor txtQty = gvInvoiceLines.FooterRow.FindControl("txtQty") as WebNumericEditor; if (txtQty != null && invoiceLine.Qty != null) { txtQty.Text = invoiceLine.Qty.ToString(); } // rate WebNumericEditor txtRate = gvInvoiceLines.FooterRow.FindControl("txtRate") as WebNumericEditor; if (txtRate != null) { txtRate.Value = invoiceLine.Rate; } //// service unit //Label lblUnitDescription = gvInvoiceLines.FooterRow.FindControl("lblUnitDescription") as Label; //if (lblUnitDescription != null && invoiceLine.InvoiceServiceType != null && invoiceLine.InvoiceServiceType.InvoiceServiceUnit != null) // lblUnitDescription.Text = invoiceLine.InvoiceServiceType.InvoiceServiceUnit.UnitDescription; // total amount txtLineAmount = gvInvoiceLines.FooterRow.FindControl("txtLineAmount") as TextBox; if (txtLineAmount != null) { txtLineAmount.Text = string.Format("{0:N2}", invoiceLine.LineAmount ?? 0); } //billable CheckBox cbxBillable = gvInvoiceLines.FooterRow.FindControl("cbxBillable") as CheckBox; if (cbxBillable != null && invoiceLine.isBillable != null) { cbxBillable.Checked = invoiceLine.isBillable ?? false; } // comments WebTextEditor txtComments = gvInvoiceLines.FooterRow.FindControl("txtComments") as WebTextEditor; if (txtComments != null && invoiceLine.Comments != null) { txtComments.Text = invoiceLine.Comments; } // show cancel icon ImageButton ibtnCancel = gvInvoiceLines.FooterRow.FindControl("ibtnCancel") as ImageButton; ibtnCancel.Visible = true; } break; case "DoDelete": invoiceLineID = Convert.ToInt32(e.CommandArgument); invoiceID = ViewState["InvoiceID"] != null?Convert.ToInt32(ViewState["InvoiceID"]) : 0; if (invoiceLineID > 0 && invoiceID > 0) { try { using (TransactionScope scope = new TransactionScope()) { deleteInvoiceComment(invoiceLineID); InvoiceDetailManager.Delete(invoiceLineID); // update invoice total after deleting detail line invoice = InvoiceManager.Get(invoiceID); if (invoice != null && invoice.InvoiceDetail != null) { invoice.TotalAmount = invoice.InvoiceDetail.Where(x => x.isBillable == true).Sum(x => x.LineAmount); InvoiceManager.Save(invoice); } // complete transaction scope.Complete(); refreshParentWindow(); } bindInvoiceDetails(invoiceID); } catch (Exception ex) { lblMessage.Text = "Error while deleting invoice detail line."; lblMessage.CssClass = "error"; Core.EmailHelper.emailError(ex); } } break; } }
/// <summary> /// Gathers information from gridview footer /// </summary> /// <returns></returns> protected InvoiceDetail getInvoiceDetailLine() { decimal qty = 0; decimal rate = 0; decimal totalAmount = 0; string[] values = null; int serviceTypeID = 0; DateTime date = DateTime.MaxValue; InvoiceDetail invoiceDetailLine = new InvoiceDetail(); // service date WebDatePicker txtDate = gvInvoiceLines.FooterRow.FindControl("txtDate") as WebDatePicker; if (txtDate != null && !string.IsNullOrEmpty(txtDate.Text)) { invoiceDetailLine.LineDate = Convert.ToDateTime(txtDate.Text); } // service description DropDownList cbx = gvInvoiceLines.FooterRow.FindControl("cbxServiceDescription") as DropDownList; if (cbx != null) { values = cbx.SelectedValue.Split(new char[] { '|' }); if (values.Length >= 3) { int.TryParse(values[0], out serviceTypeID); invoiceDetailLine.ServiceTypeID = serviceTypeID; invoiceDetailLine.LineDescription = cbx.SelectedItem.Text.Trim(); } } // quantity WebNumericEditor txtQty = gvInvoiceLines.FooterRow.FindControl("txtQty") as WebNumericEditor; if (txtQty != null) { qty = txtQty.Value == null ? 0 : Convert.ToDecimal(txtQty.Value); invoiceDetailLine.Qty = qty; } // unit description //Label lblUnitDescription = gvInvoiceLines.FooterRow.FindControl("lblUnitDescription") as Label; //if (lblUnitDescription != null) // invoiceDetailLine.UnitDescription = lblUnitDescription.Text; // rate WebNumericEditor txtRate = gvInvoiceLines.FooterRow.FindControl("txtRate") as WebNumericEditor; if (txtRate != null) { rate = txtRate.Value == null ? 0 : Convert.ToDecimal(txtRate.Value); invoiceDetailLine.Rate = rate; } // total amount // quantity TextBox txtLineAmount = gvInvoiceLines.FooterRow.FindControl("txtLineAmount") as TextBox; decimal.TryParse(txtLineAmount.Text.Trim().Replace(",", ""), out totalAmount); invoiceDetailLine.LineAmount = totalAmount; invoiceDetailLine.Total = totalAmount; //if (invoiceDetailLine.UnitDescription != null && invoiceDetailLine.UnitDescription.ToLower() == "percentage") // totalAmount = (rate / 100 ) * qty; //else // totalAmount = rate * qty; // comments WebTextEditor txtComments = gvInvoiceLines.FooterRow.FindControl("txtComments") as WebTextEditor; if (txtComments != null) { invoiceDetailLine.Comments = txtComments.Text.Trim(); } // is billable CheckBox cbxBillable = gvInvoiceLines.FooterRow.FindControl("cbxBillable") as CheckBox; if (cbxBillable != null) { invoiceDetailLine.isBillable = cbxBillable.Checked; } return(invoiceDetailLine); }
public bool Save() { if (!FullResAddrPanel.Visible) { EmpResAddr.Text = EmpResAddr1.Text + "\r\n" + EmpResAddr2.Text + "\r\n" + EmpResAddr3.Text; } EEmpPersonalInfo c = new EEmpPersonalInfo(); Hashtable values = new Hashtable(); binding.toValues(values); PageErrors errors = PageErrors.getErrors(db, Page.Master); errors.clear(); db.validate(errors, values); if (!errors.isEmpty()) { return(false); } db.parse(values, c); if (this.IsResetESSPassword.Checked) { c.EmpPW = string.Empty; } if (PrevEmpID > 0) { if (IsCreateNewRoleEmployee) { c.EmpNo = NewRoleEmpNo.Text.Trim(); c.MasterEmpID = PrevEmpID; if (string.IsNullOrEmpty(c.EmpNo)) { errors.addError(lblNewRoleEmpNo.Text, "validate.required.prompt"); return(false); } } } c.EmpNo = c.EmpNo.ToUpper(); // Start 0000044, Miranda, 2014-05-09 string oldEmpNo = ""; if (!AppUtils.checkDuplicate(dbConn, db, c, errors, "EmpNo")) { if (isAutoGenerateEmpNo && empNoFormat != null && EmpID < 0) { // Check if EmpNo format is same as EmpNoFormat setting of System Parameter bool alignToFormat = isAlignToDefinedFormat(c.EmpNo, empNoFormat); if (alignToFormat) { errors.clear(); oldEmpNo = c.EmpNo; c.EmpNo = getNextEmpNo(empNoFormat).ToUpper(); EmpNo.Text = c.EmpNo; if (!AppUtils.checkDuplicate(dbConn, db, c, errors, "EmpNo")) { return(false); } else { errors.addError(string.Format(HROne.Translation.PageErrorMessage.ALERT_NEW_STAFF_NO_BEEN_USED, new string[] { oldEmpNo, c.EmpNo })); } } else { return(false); } } else { return(false); } } // End 0000044, Miranda, 2014-05-09 // Start 0000066, Miranda, 2014-08-08 if (SuppressHKIDWarning.Text == "false" && !AppUtils.checkDuplicate(dbConn, db, c, errors, "EmpHKID")) { SuppressHKIDWarning.Text = "true"; errors.clear(); errors.addError("HKID is already input in system, click SAVE button again to bypass this warning and save to database."); } // End 0000066, Miranda, 2014-08-08 if (c.EmpDateOfBirth > AppUtils.ServerDateTime().Date) { errors.addError("EmpDateOfBirth", HROne.Translation.PageErrorMessage.ERROR_INVALID_DOB); } if (c.EmpEngSurname.Contains(" ")) { errors.addError("EmpEngSurname", HROne.Translation.PageErrorMessage.ERROR_SURNAME_CONTAIN_SPACE); } if (!errors.isEmpty()) { return(false); } //if (c.EmpProbaLastDate.Ticks.Equals(0)) //{ // if (c.EmpProbaPeriod > 0) // { // c.EmpProbaLastDate = c.EmpDateOfJoin; // if (c.EmpProbaUnit.Equals("D")) // c.EmpProbaLastDate = c.EmpProbaLastDate.AddDays(c.EmpProbaPeriod); // else if (c.EmpProbaUnit.Equals("M")) // c.EmpProbaLastDate = c.EmpProbaLastDate.AddMonths(c.EmpProbaPeriod); // c.EmpProbaLastDate = c.EmpProbaLastDate.AddDays(-1); // } //} if (string.IsNullOrEmpty(c.EmpStatus) || c.EmpStatus.Equals("A")) { if (WebUtils.TotalActiveEmployee(dbConn, c.EmpID) >= WebUtils.productLicense(Session).NumOfEmployees) { errors.addError(string.Format(PageErrorMessage.ERROR_MAX_LICENSE_LIMITCH_REACH, new string[] { WebUtils.productLicense(Session).NumOfEmployees + " " + HROne.Common.WebUtility.GetLocalizedString("Employee") })); return(false); } } // Start 0000092, Ricky So, 2014-09-09 if (c.EmpNationalityID > 0) { ENationality m_nationality = new ENationality(); m_nationality.NationalityID = c.EmpNationalityID; if (ENationality.db.select(dbConn, m_nationality)) { c.EmpNationality = m_nationality.NationalityDesc; } } if (c.EmpPlaceOfBirthID > 0) { EPlaceOfBirth m_placeOfBirth = new EPlaceOfBirth(); m_placeOfBirth.PlaceOfBirthID = c.EmpPlaceOfBirthID; if (EPlaceOfBirth.db.select(dbConn, m_placeOfBirth)) { c.EmpPlaceOfBirth = m_placeOfBirth.PlaceOfBirthDesc; } } if (c.EmpPassportIssuedCountryID > 0) { EIssueCountry m_issueCountry = new EIssueCountry(); m_issueCountry.CountryID = c.EmpPassportIssuedCountryID; if (EIssueCountry.db.select(dbConn, m_issueCountry)) { c.EmpPassportIssuedCountry = m_issueCountry.CountryDesc; } } // End 0000092, Ricky So, 2014-09-09 WebUtils.StartFunction(Session, FUNCTION_CODE, c.EmpID); if (EmpID < 0) { // Utils.MarkCreate(Session, c); c.EmpStatus = "A"; db.insert(dbConn, c); EmpID = c.EmpID; if (PrevEmpID > 0) { if (!IsCreateNewRoleEmployee) { EmpUtils.CopyEmpDetail(dbConn, PrevEmpID, EmpID); } } // url = Utils.BuildURL(-1, CurID); } else { // Utils.Mark(Session, c); db.update(dbConn, c); } //DBFilter empUniformFilter = new DBFilter(); //empUniformFilter.add(new Match("EmpID", c.EmpID)); //ArrayList empUniformList = EEmpUniform.db.select(dbConn, empUniformFilter); //EEmpUniform empUniform = null; //if (empUniformList.Count > 0) // empUniform = (EEmpUniform)empUniformList[0]; //else //{ // empUniform = new EEmpUniform(); // empUniform.EmpID = c.EmpID; //} //empUniform.EmpUniformB = EmpUniformB.Text; //empUniform.EmpUniformW = EmpUniformW.Text; //empUniform.EmpUniformH = EmpUniformH.Text; //if (empUniform.EmpUniformID > 0) // EEmpUniform.db.update(dbConn, empUniform); //else // EEmpUniform.db.insert(dbConn, empUniform); ArrayList list = new ArrayList(); foreach (RepeaterItem groupItem in EmpExtraFieldGroupRepeater.Items) { Repeater EmpExtraField = (Repeater)groupItem.FindControl("EmpExtraField"); foreach (RepeaterItem item in EmpExtraField.Items) { TextBox textBox = (TextBox)item.FindControl("EmpExtraFieldValue"); WebDatePicker datePicker = (WebDatePicker)item.FindControl("EmpExtraFieldValueDateControl"); int EmpExtraFieldID = Int32.Parse(textBox.Attributes["EmpExtraFieldID"]); DBFilter filter = new DBFilter(); filter.add(new Match("EmpID", c.EmpID)); filter.add(new Match("EmpExtraFieldID", EmpExtraFieldID)); ArrayList existingExtraFieldValueList = EEmpExtraFieldValue.db.select(dbConn, filter); EEmpExtraFieldValue h = null; if (existingExtraFieldValueList.Count > 0) { h = (EEmpExtraFieldValue)existingExtraFieldValueList[0]; } else { h = new EEmpExtraFieldValue(); h.EmpID = c.EmpID; h.EmpExtraFieldID = EmpExtraFieldID; } if (textBox.Visible) { h.EmpExtraFieldValue = textBox.Text.Trim(); } else if (datePicker.Visible) { h.EmpExtraFieldValue = datePicker.Value.Trim(); } list.Add(h); } } //filter = new DBFilter(); //filter.add(new Match("EmpID", CurEmpID)); //filter.add(new Match("EmpPosID", CurID)); //EEmpHierarchy.db.delete(dbConn, filter); foreach (EEmpExtraFieldValue h in list) { if (h.EmpExtraFieldValueID == 0) { EEmpExtraFieldValue.db.insert(dbConn, h); } else { EEmpExtraFieldValue.db.update(dbConn, h); } } WebUtils.EndFunction(dbConn); return(true); }