private void lnkExpenses_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { this.Hide(); Expenses.ExpensesList go = new Expenses.ExpensesList(); go.MdiParent = this.ParentForm; go.Show(); }
private void btnaddexpense_Click(object sender, EventArgs e) { try { if (txtAmount.Text == string.Empty) { MessageBox.Show("Please Insert Expense Amount"); txtAmount.Focus(); } else if (cmboCategory.Text == string.Empty) { MessageBox.Show("Please Select category"); cmboCategory.Focus(); } else { string Filename; if (txtAttachmentFileName.Text != string.Empty) { Filename = DateTime.Now.ToString("yyyyMMddhhmmss") + lblFileExtension.Text; } else { Filename = ""; } string sql1 = " insert into tbl_expense (Date , ReferenceNo , Category , Amount , Attachment , fileextension, Note , Createdby) "+ " values ('" + dtStartDate.Text + "', '" + txtReferNo.Text + "','" + cmboCategory.Text + "', '" + txtAmount.Text + "', " + " '" + Filename + "', '" + lblFileExtension.Text + "', '" + txtNote.Text + "' , '" + UserInfo.UserName + "')"; DataAccess.ExecuteSQL(sql1); if (txtAttachmentFileName.Text != string.Empty) { //Attachment upload ///////////////// string path = Application.StartupPath + @"\ExpenseAttachment\"; if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(Application.StartupPath + @"\ExpenseAttachment\"); } string copyfile = lblcopyfile.Text; //Source file string pastefile = path + @"\" + Filename; //destination file System.IO.File.Copy(copyfile, pastefile); } MessageBox.Show("Saved Successfully", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult result = MessageBox.Show("Do you want to add a new Expense?", "Yes or No", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result == DialogResult.Yes) { txtAmount.Text = string.Empty; txtNote.Text = string.Empty; txtReferNo.Text = string.Empty; } else { this.Hide(); Expenses.ExpensesList go = new Expenses.ExpensesList(); go.MdiParent = this.ParentForm; go.Show(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }