| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 504 人关注过本帖
标题:c#实现进出库数据更新问题
只看楼主 加入收藏
liuentao
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-3-11
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
c#实现进出库数据更新问题
我写了一个仓库入库和出库的管理软件的代码,但是每次运行的时候,都会显示同样的库存信息,不管出库了多少...即使删掉了库存.运行软件的时候还是会以前的库存信息。代码如下:
private void button2_Click(object sender, EventArgs e)//----------取出
        {
            StreamReader M = new StreamReader("news\\no.txt");//读取ID
            string a = M.ReadLine();
            M.Close();
            Time();
            if (outname.Text != "")
            {
                if (outnum.Text != "")
                {
                    string[] lines = File.ReadAllLines("news\\inname.txt");//读取总信息
                    for (int i = 0; i < lines.Length; i++)
                    {
                        string[] line = lines[i].ToString().Split('\t');//读取信息
                        if (line[0] == outname.Text)//找到那一项时
                        {
                            int q1 = int.Parse(line[1]);
                            int q2 = int.Parse(outnum.Text);
                            if ( q1>= q2)//判断库存是否足够取出
                            {
                                StreamWriter dd = new StreamWriter("news\\inname.txt");
                                dd.Write("");
                                dd.Close();
                                string D = int.Parse(line[1]) - int.Parse(outnum.Text) + "";
                                for (int j = 0; j < i; j++)//输入前面的值
                                {
                                    StreamWriter a1 = File.AppendText("news\\inname.txt");
                                    a1.WriteLine(lines[j]);
                                    a1.Close();
                                }
                                for (int x = i + 1; x < lines.Length; x++)//写入后面的值
                                {
                                    StreamWriter a2 = File.AppendText("news\\inname.txt");
                                    a2.WriteLine(lines[x]);
                                    a2.Close();
                                }
                                StreamWriter a3 = File.AppendText("news\\inname.txt");//写入更改的值
                                a3.WriteLine(line[0] + '\t' + D + '\t' + r);
                                a3.Close();
                                StreamWriter a4 = File.AppendText("news\\" + outname.Text + ".txt");//写入详细信息列表
                                a4.WriteLine(a+'\t'+outname.Text + '\t' + outunit.Text +'\t'+outnum.Text+ '\t' + outpri.Text + '\t' + "取" + '\t' + (int.Parse(outnum.Text) * int.Parse(outpri.Text)) +'\t'+r+ '\t' + outws.Text + '\t' + outman.Text + '\t' + outcap.Text);
                                a4.Close();
                                long S = long.Parse(a);
                                S += 1;
                                StreamWriter T = new StreamWriter("news\\no.txt");
                                T.Write(S + "");
                                T.Close();
                                MessageBox.Show("取出成功!");
                                clear();
                            }
                            else
                            {
                                MessageBox.Show("对不起,库存只有" + line[1] + "不足" + outnum.Text);
                            }
                        }
                    }

                }
                else
                {
                    MessageBox.Show("请输入出库的数量");
                }
            }
            else
            {
                MessageBox.Show("请选择出库名称");
            }
        }

        private void manform_Activated(object sender, EventArgs e)
        {
            Shows();
            showname();
        }
搜索更多相关主题的帖子: private 信息 
2013-03-11 20:29
yhlvht
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:36
帖 子:707
专家分:4405
注 册:2011-9-30
收藏
得分:20 
贴出来的程序应该没有什么问题。你先检查写入的两个文件内容正不正确,内容正确就是其它显示代码的问题,如果写入的内容都不正确,那你就调试下看吧。
2013-03-12 17:34
快速回复:c#实现进出库数据更新问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028743 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved