在C#windows应用程序中将数据保存到数据库后,如何在不使用其他表单的情况下打印银行支票 [英] How to print bank cheque without using another form after saving the data into database in C# windows application

查看:106
本文介绍了在C#windows应用程序中将数据保存到数据库后,如何在不使用其他表单的情况下打印银行支票的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,在bankname和accountno和帐户类型组合框和帐户收款人复选框,receivername文本框,金额文本框,rupeesinwords文本框和checkbbook no和checkno和一个保存按钮。我想要的是填写所有细节和将数据保存到数据库然后我想打印检查而不使用其他表单。数据进入数据库,然后我点击打印按钮文件将去打印。经过长时间的谷歌搜索我尝试了一些代码。它给文件不包含任何页面的消息如何做到这一点请帮助我。我更新鲜。提前谢谢。



我的尝试:



< pre lang =c#>< blockquote class = quote>< div class = op>引用:< / div >

private void btnsave_Click ( object sender,EventArgs e)
{
ChqMngrBsns.Masters.WriteChkInfo writeinfo = new
ChqMngrBsns.Masters.WriteChkInfo();
if (cmbBankname.SelectedIndex == 0
{
MessageBox.Show( Select Bank);
return ;
}
else if (cmbpayee.SelectedIndex == 0
{
MessageBox.Show( 输入ReceiverName);
return ;
}
else if (txtAmnt.Text == || txtAmnt.Text == string .Empty)
{
MessageBox.Show( Enter Amount);
return ;
}
if (bankid > 0
{
writeinfo.bankid = bankid;
if (chkAcntpyee.Checked == true
{
writeinfo.IsActpayee = true ;
}
else
{
writeinfo.IsActpayee = false ;
}
writeinfo.pay = cmbpayee.Text.ToString();
writeinfo.Amount = Convert.ToDecimal(txtAmnt.Text);
writeinfo.Chkbookno = Convert.ToInt32(cmbckbno.GetItemText(cmbckbno.SelectedItem));
writeinfo.Chkno = Convert.ToInt32(cmbChqno.GetItemText(cmbChqno.SelectedItem));
writeinfo.Isprint = true ;
writeinfo.SaveData( true );
btnprint.Enabled = true ;
}
ClearControls( this );
}
private void btnprint_Click( object sender,EventArgs e)
{
CaptureScreen();
printDocument1.Print();
printPreviewDialog1.ShowDialog();
ClearControls( this );
}
位图memoryImage;
private void CaptureScreen()
{
Graphics myGraphics = < span class =code-keyword> this
.CreateGraphics();
尺寸s = .Size;
memoryImage = new 位图(s.Width,s.Height,myGraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
memoryGraphics.CopyFromScreen( this .Location.X, this .Location.Y, 1060 360 ,s);
}
私有 void printDocument1_PrintPage_1( object sender,PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImage, 1060 360 );
}

}
}

< / blockquote >

解决方案

使用 PrintDocument Class(System.Drawing.Printing) [ ^ ] - 链接包含一个基本示例。


I have a form in that bankname and accountno and account type comboboxes and account payee check box,receivername textbox,amount textbox,rupeesinwords textbox and checkbbook no and checkno and one save button.What i want is after filling all the details and save data into database then i want print that cheque without using another form. the data into database and then i click the print button document will go to print.After long googling I tried some code.It is giving "Documents doesnot conatain any pages" message how to do it please help me on this.I'm fresher.Thanks in advance.

What I have tried:

<blockquote class="quote"><div class="op">Quote:</div> 
 
    private void btnsave_Click(object sender, EventArgs e)
        {
            ChqMngrBsns.Masters.WriteChkInfo writeinfo = new 
   ChqMngrBsns.Masters.WriteChkInfo();
            if (cmbBankname.SelectedIndex == 0)
            {
                MessageBox.Show("Select Bank");
                return;
            }
            else if (cmbpayee.SelectedIndex == 0)
            {
              MessageBox.Show("Enter ReceiverName");
                return;
            }
            else if (txtAmnt.Text =="" || txtAmnt.Text==string.Empty)
            {
                MessageBox.Show("Enter Amount");
                 return;
            }
            if (bankid > 0)
            {
                writeinfo.bankid = bankid;
                if (chkAcntpyee.Checked == true)
                {
                   writeinfo.IsActpayee = true;
                }
                else
                {
                   writeinfo.IsActpayee = false;
                }
                writeinfo.pay = cmbpayee.Text.ToString();
                writeinfo.Amount = Convert.ToDecimal(txtAmnt.Text);
                writeinfo.Chkbookno = Convert.ToInt32(cmbckbno.GetItemText(cmbckbno.SelectedItem));
                writeinfo.Chkno = Convert.ToInt32(cmbChqno.GetItemText(cmbChqno.SelectedItem));
                writeinfo.Isprint = true;
                writeinfo.SaveData(true);
                 btnprint.Enabled = true;
            }
            ClearControls(this);
        }
        private void btnprint_Click(object sender, EventArgs e)
        {   
            CaptureScreen();
            printDocument1.Print();
            printPreviewDialog1.ShowDialog();
            ClearControls(this);
        }
        Bitmap memoryImage;
        private void CaptureScreen()
        {
            Graphics myGraphics = this.CreateGraphics();
            Size s = this.Size;
            memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
            Graphics memoryGraphics = Graphics.FromImage(memoryImage);
            memoryGraphics.CopyFromScreen(this.Location.X, this.Location.Y, 1060,360, s);
        }
        private void printDocument1_PrintPage_1(object sender, PrintPageEventArgs e)
        {
            e.Graphics.DrawImage(memoryImage, 1060, 360);
        }
        
    }
}

</blockquote>

解决方案

Use the PrintDocument Class (System.Drawing.Printing)[^] - the link includes a basic example.


这篇关于在C#windows应用程序中将数据保存到数据库后,如何在不使用其他表单的情况下打印银行支票的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆