如何将以一种形式输入的数据转换为另一种形式 [英] How to get the data that was entered in one form in to another form
问题描述
大家好,
我有一个带有一些文本框和3个按钮(即保存取消"和添加条目")的form1.
单击保存"后,我将检查条件是否为假,否则将引发错误.现在,如果我单击AddEntry按钮,则Form1数据将保持不变,并且我将在该form2上为用户显示form2,我将有一些文本框和2个buittons.如果用户输入一些数据并单击保存,那么如果用户单击form1的保存,我现在将显示form1,我想将数据保存到我指定的所需路径中
Form1的示例代码为
Hi all,
I am having a form1 with some textboxes and 3 buttons namely Save cancel and AddEntry.
On clicking save i will check for a condition if it is false i will raise an error. Now if i click on AddEntry Button Form1 data will be as it is and i will show form2 for the user on that form2 i will have some textboxes and 2 buittons. If user enter some data and click on save i will show form1 now if the user clicks on save of form1 i would like to save the data in to the required path i specified
The sample code form Form1 is
public bool saveBatchHeader(string m_strPath)<br />
{<br />
StringBuilder sb = new StringBuilder();<br />
sb.AppendLine();<br />
sb.Append(m_strRecordTypeCode.PadLeft(1, ''0''));<br />
sb.Append(m_strServiceClassCode.PadLeft(3, ''0''));<br />
sb.Append(m_strCompanyName.PadRight(16, '' ''));<br />
sb.Append(m_strCompanyDiscretionaryData.PadRight(20, '' ''));<br />
sb.Append(m_strCompanyIdentification.PadRight(10, '' ''));<br />
sb.Append(m_strStandardEntryClassCode.PadRight(3, '' ''));<br />
sb.Append(m_strCompanyEntryDescription.PadRight(10, '' ''));<br />
string m_strCompanyDescripDate = m_strCompanyDescriptiveDate.Replace("/", "");<br />
sb.Append(m_strCompanyDescripDate.PadLeft(6, ''0''));<br />
string m_strEffDate = m_strEffectiveEntryDate.Replace("/", "");<br />
sb.Append(m_strEffDate.PadLeft(6, ''0''));<br />
sb.Append(m_strJulianDate.PadRight(3, '' ''));<br />
sb.Append(m_strOriginatorStatusCode.PadRight(1, '' ''));<br />
sb.Append(m_strOriginationDFIIdentification.PadLeft(8, ''0''));<br />
sb.Append(m_strBatchNumber.PadLeft(7, ''0''));<br />
sb.Replace("\r\n", String.Empty);<br />
int len = sb.Length;<br />
if (len < 95)<br />
{<br />
m_flag = false;<br />
}<br />
else<br />
{<br />
StreamWriter sw = File.AppendText(m_strPath);<br />
sw.Write(sb);<br />
sw.Close();<br />
}<br />
return m_flag;<br />
}
对于表格,类文件如下
For form the class file is as follows
public bool saveEntry(string strPath)
{
m_flag = true;
string FileName = strPath;
string m_strDate = DateTime.Now.ToString("MM/dd/yyyy");
m_strDate = m_strDate.Replace("/", "");
strPath += "/CCD_EntryDetailRecord_" + m_strDate + ".txt";
using (TextWriter tw = new StreamWriter(strPath))
{
tw.Write(m_strRecordTypeCode.PadLeft(1, '0'));
tw.Write(m_strTransactionCode.PadLeft(2, '0'));
tw.Write(m_strRecievingDFIIdentification.PadLeft(9, '0'));
tw.Write(m_strDFIAccountNumber.PadRight(17, ' '));
tw.Write(m_strAmount.PadLeft(10, '0'));
tw.Write(m_strIdentificationNumber.PadRight(15, ' '));
tw.Write(m_strRecievingcompanyName.PadRight(22, ' '));
tw.Write(m_strDiscretionaryData.PadRight(2, ' '));
tw.Write(m_strAddendaRecordIndicator.PadLeft(1, '0'));
tw.Write("TTTTBBBBZZZZZZZ");
tw.WriteLine();
tw.Flush();
tw.Close();
}
因此,任何人都可以说出如何在之后添加此数据吗?
sb.Append(m_strBatchNumber.PadLeft(7,``0''));
So can any one tell how to get this data appended after
sb.Append(m_strBatchNumber.PadLeft(7, ''0''));
in the first form code.
推荐答案
我已经发布了类似问题的答案.检查一下
http://www.codeproject.com/Answers/102018/desktop-application.aspx#answer1 [^ ]
希望对您有帮助
问候,
Suresh
Hi,
I have posted answer for similar kind of question. Check it out
http://www.codeproject.com/Answers/102018/desktop-application.aspx#answer1[^]
Hope this will help you
Regards,
Suresh
使用静态类并在其中声明静态变量..
静态变量可以使用
访问 classname.变量名称
use a static class and declare static variables in it..
the static variables can access using
classname.variable name
这篇关于如何将以一种形式输入的数据转换为另一种形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!