protected void Page_Load(object sender, EventArgs e) { Id = Convert.ToInt32(Request["id"]); Type = Request["type"]; if (!IsPostBack) { ResetForm(); // new if (Type == "0") { // } // modify else { var corporateCreditCardSchema = new CCorporateCreditCardSchema().Get(Id); if (corporateCreditCardSchema != null) { LinqDataSourceUser.WhereParameters.Clear(); LinqDataSourceUser.WhereParameters.Add("UserId", DbType.Int32, corporateCreditCardSchema.UserId.ToString()); LinqDataSourceUser.Where = "UserId == @UserId"; RadGridUser.MasterTableView.Rebind(); foreach (GridDataItem item in RadGridUser.Items) { item.Selected = true; break; } GetCorporateCreditCardSchema(); } } } }
private void GetCorporateCreditCardSchema() { if (RadGridUser.SelectedValue != null) { var cCorporateCreditCardSchema = new CCorporateCreditCardSchema().GetByUserId(Convert.ToInt32(RadGridUser.SelectedValue)); if (cCorporateCreditCardSchema != null) { RadTextBoxCreditCardNumber.Text = cCorporateCreditCardSchema.CreditCardNumber; RadNumericTextBoxCreditLimit.Value = (double)cCorporateCreditCardSchema.CreditLimit; } } }
protected void RadToolBar1_OnButtonClick(object sender, RadToolBarEventArgs e) { if (e.Item.Text == "Save") { if (IsValid) { if (RadGridUser.SelectedValue != null) { var cCorporateCreditCardSchema = new CCorporateCreditCardSchema(); var corporateCreditCardSchema = cCorporateCreditCardSchema.GetByUserId(Convert.ToInt32(RadGridUser.SelectedValue)); bool isNew = false; if (corporateCreditCardSchema == null) { corporateCreditCardSchema = new Erp2016.Lib.CorporateCreditCardSchema(); corporateCreditCardSchema.CreatedId = CurrentUserId; corporateCreditCardSchema.CreatedDate = DateTime.Now; isNew = true; } corporateCreditCardSchema.UserId = Convert.ToInt32(RadGridUser.SelectedValue); corporateCreditCardSchema.CreditCardNumber = RadTextBoxCreditCardNumber.Text; corporateCreditCardSchema.CreditLimit = (decimal)RadNumericTextBoxCreditLimit.Value; // new if (isNew) { cCorporateCreditCardSchema.Add(corporateCreditCardSchema); } // modify else { corporateCreditCardSchema.UpdatedId = CurrentUserId; corporateCreditCardSchema.UpdatedDate = DateTime.Now; cCorporateCreditCardSchema.Update(corporateCreditCardSchema); } RunClientScript("Close();"); } } } }
protected void RadToolBar1_ButtonClick(object sender, RadToolBarEventArgs e) { // Save if (e.Item.Text == "TempSave" || e.Item.Text == "Request") { if (IsValid) { var corporateCreditCardSchema = new CCorporateCreditCardSchema().GetByUserId(CurrentUserId); if (corporateCreditCardSchema != null) { var corporateCreditCard = new CCorporateCreditCard().GetByUserId(CurrentUserId); if (corporateCreditCard != null) { var startDay = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 4); var endDay = startDay.AddMonths(1); if (corporateCreditCard.PeriodStart >= startDay && corporateCreditCard.PeriodEnd < endDay) { ShowMessage("Credit on this month is already requested. Try it again when 4th beginning of month."); return; } } if (RadNumericTextBoxGrandTotal.Value > (double)corporateCreditCardSchema.CreditLimit) { ShowMessage("Your limited Credit Amount of is " + corporateCreditCardSchema.CreditLimit); return; } var cObj = new CCorporateCreditCard(); var obj = cObj.Get(Id); // new one if (obj == null) { obj = new Erp2016.Lib.CorporateCreditCard(); obj.CreatedId = Convert.ToInt32(CurrentUserId); obj.CreatedDate = DateTime.Now; obj.PeriodStart = (DateTime)RadDatePickerStart.SelectedDate; obj.PeriodEnd = (DateTime)RadDatePickerEnd.SelectedDate; int newIndex = Convert.ToInt32(cObj.Add(obj).ToString()); obj = cObj.Get(newIndex); ViewState["NewIndex"] = newIndex; } else { obj.PeriodStart = (DateTime)RadDatePickerStart.SelectedDate; obj.PeriodEnd = (DateTime)RadDatePickerEnd.SelectedDate; obj.UpdatedId = Convert.ToInt32(CurrentUserId); obj.UpdatedDate = DateTime.Now; ViewState["NewIndex"] = obj.CorporateCreditCardId.ToString(); } obj.ApprovalId = CurrentUserId; obj.ApprovalDate = DateTime.Now; if (e.Item.Text == "TempSave") { obj.ApprovalStatus = null; } else { var cApprovalHistory = new CApprovalHistory(); cApprovalHistory.DelApprovalHistory((int)CConstValue.Approval.CorporateCreditCard, Convert.ToInt32(ViewState["NewIndex"])); // approve request var approval = new CApproval(); var approvalResult = approval.ApproveRequstCreate((int)CConstValue.Approval.CorporateCreditCard, CurrentUserId, Convert.ToInt32(ViewState["NewIndex"])); if (approvalResult > 0) { obj.ApprovalStatus = approvalResult; } else { ShowMessage("Failed"); return; } new CMail().SendMail(CConstValue.Approval.CorporateCreditCard, CConstValue.MailStatus.ToApproveUser, Convert.ToInt32(ViewState["NewIndex"]), string.Empty, CurrentUserId); } cObj.Update(obj); // save uploading file FileDownloadList1.SaveFile(Convert.ToInt32(ViewState["NewIndex"])); // save other tables RunClientScript("SaveChanges();"); } else { ShowMessage("not found Limit credit amount. It needs to be registered."); } } else { ShowMessage("Failed"); } } // Revise else if (e.Item.Text == "Revise") { RunClientScript("ShowApprovalReviseWindow('" + Id + "');"); } // Approval else if (e.Item.Text == "Approve") { RunClientScript("ShowApprovalWindow('" + Id + "');"); } // Reject else if (e.Item.Text == "Reject") { RunClientScript("ShowApprovalRejectWindow('" + Id + "');"); } // Accept else if (e.Item.Text == "Accept") { RunClientScript("ShowApprovalAcceptWindow('" + Id + "');"); } // Complete else if (e.Item.Text == "Complete") { RunClientScript("ShowApprovalCompleteWindow('" + Id + "');"); } // Print else if (e.Item.Text == "Print") { RunClientScript("ShowPrint();"); } // Cancel else if (e.Item.Text == "Cancel") { RunClientScript("ShowApprovalCancelWindow('" + Id + "');"); } // close else if (e.Item.Text == "Close") { RunClientScript("Close();"); } }