Пример #1
0
        protected void dgBankPaymentDetail_ItemCommand(object source, DataGridCommandEventArgs e)
        {
            if (e.CommandName == "AddNew")
            {
                try
                {
                    BankPaymentRequestDetail cprd = new BankPaymentRequestDetail();
                    cprd.BankPaymentRequest = _presenter.CurrentBankPaymentRequest;
                    TextBox txtBankCode = e.Item.FindControl("txtBankCode") as TextBox;
                    cprd.BankCode = Convert.ToInt32(txtBankCode.Text);
                    TextBox txtName = e.Item.FindControl("txtName") as TextBox;
                    cprd.Name = txtName.Text;
                    TextBox txtAmount = e.Item.FindControl("txtAmount") as TextBox;
                    cprd.Amount = Convert.ToDecimal(txtAmount.Text);
                    TextBox txtCurrency = e.Item.FindControl("txtCurrency") as TextBox;
                    cprd.Currency = txtCurrency.Text;
                    DropDownList ddlAccount = e.Item.FindControl("ddlAccount") as DropDownList;
                    cprd.Account = _presenter.GetAccount(Convert.ToInt32(ddlAccount.SelectedValue));
                    //Added Fields
                    cprd.Reference   = txtVoucherNo.Text;
                    cprd.ProcessDate = Convert.ToDateTime(txtRequestDate.Text);

                    _presenter.CurrentBankPaymentRequest.BankPaymentRequestDetails.Add(cprd);

                    dgBankPaymentDetail.EditItemIndex = -1;
                    BindBankPaymentDetails();
                    Master.ShowMessage(new AppMessage("Bank Payment Detail Successfully Added!", Chai.WorkflowManagment.Enums.RMessageType.Info));
                }
                catch (Exception ex)
                {
                    Master.ShowMessage(new AppMessage("Error: Unable to Save Bank Payment Detail " + ex.Message, Chai.WorkflowManagment.Enums.RMessageType.Error));
                }
            }
        }
Пример #2
0
        public static void CreateCSV <T>(IList <T> list, string csvNameWithExt)
        {
            if (list == null || list.Count == 0)
            {
                return;
            }

            string pathDesktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            string filePath    = pathDesktop + "\\" + csvNameWithExt;

            if (!File.Exists(filePath))
            {
                File.Create(filePath).Close();
            }
            //get type from 0th member
            Type   t       = list[0].GetType();
            string newLine = Environment.NewLine;

            using (var sw = new StreamWriter(filePath))
            {
                //make a new instance of the class name we figured out to get its props
                object o = Activator.CreateInstance(t);
                //gets all properties
                PropertyInfo[] props = o.GetType().GetProperties();

                //foreach of the properties in class above, write out properties
                //this is the header row
                foreach (PropertyInfo pi in props)
                {
                    if (pi.Name != "Account" || pi.Name.ToUpper() != "BANKPAYMENTREQUEST")
                    {
                        sw.Write(pi.Name.ToUpper() + ",");
                    }
                }
                sw.Write(newLine);

                //this acts as datarow
                foreach (T item in list)
                {
                    //this acts as datacolumn
                    foreach (PropertyInfo pi in props)
                    {
                        if (pi.Name != "Account" || pi.Name.ToUpper() != "BANKPAYMENTREQUEST")
                        {
                            BankPaymentRequestDetail detail = (BankPaymentRequestDetail)item.GetType()
                                                              .GetProperty(pi.Name)
                                                              .GetValue(item, null);
                            //this is the row+col intersection (the value)
                            string whatToWrite =
                                Convert.ToString(item.GetType()
                                                 .GetProperty(pi.Name)
                                                 .GetValue(item, null))
                                .Replace(',', ' ') + ',';

                            sw.Write(whatToWrite);
                        }
                    }
                    sw.Write(newLine);
                }
            }
        }
 public void DeleteBankPaymentRequestDetail(BankPaymentRequestDetail BankPaymentRequestDetail)
 {
     _controller.DeleteEntity(BankPaymentRequestDetail);
 }