private void btnAmend_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.lvMType.SelectedItems.Count == 0)
                {
                    throw new MessageException("请选择要修改的项目!");
                }

                checkText();

                MerchandiseInfoData mid = getMInfo();
                mid.ID = ((MerchandiseInfoData)this.lvMType.SelectedItems[0].Tag).ID;

                MInfoCortrol.updMInfo(mid);

                ListViewItem lvi = new ListViewItem(mid.Name);
                lvi.Tag = mid;
                ListViewItem.ListViewSubItem lvs = new ListViewItem.ListViewSubItem();

                MerchandiseTypeData ptd = MTypeCortrol.getMTypeOfID(mid.TypeID);
                lvs.Text = ptd.Name;
                lvs.Tag  = ptd;

                lvi.SubItems.Add(lvs);
                lvi.SubItems.Add(mid.Quantity.ToString());

                this.lvMType.Items[this.lvMType.SelectedIndices[0]] = lvi;
                clear();
            }
            catch (MessageException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void 修ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.lvMInfo.SelectedItems.Count == 0)
            {
                return;
            }
            ListViewItem lvi = this.lvMInfo.SelectedItems[0];

            try
            {
                frmInput            fi  = new frmInput("请输入库存数量!", lvi.SubItems[1].Text);
                string              str = fi.ShowInput();
                int                 i   = Convert.ToInt32(str);
                MerchandiseInfoData mid = (MerchandiseInfoData)lvi.Tag;
                mid.Storage = i;
                MInfoCortrol.updMInfo(mid);
                lvi.SubItems[1].Text = i.ToString();
            }
            catch (MessageException ex)
            {
                if (ex.Message != "")
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
 private void btnPInfoID_Click(object sender, EventArgs e)
 {
     try
     {
         frmSelectMInfo      fsm = new frmSelectMInfo();
         MerchandiseInfoData mid = (MerchandiseInfoData)fsm.ShowSelect(pid);
         this.txtM.Text = mid.Name;
         this.txtM.Tag  = mid;
         foreach (PurveyData pd in PurveyCortrol.ls)
         {
             if (pd.PInfoID == pid.ID && pd.MInfoID == mid.ID)
             {
                 this.txtPrice.Text          = pd.Price.ToString();
                 this.txtQuantity.ReadOnly   = false;
                 this.txtPrice.ReadOnly      = false;
                 this.btnNumQuantity.Enabled = true;
                 this.btnNumPrice.Enabled    = true;
                 break;
             }
         }
     }
     catch (MessageException ex)
     {
         if (ex.Message != "")
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
        /// <summary>
        /// 增加商品,且返回新增加记录的ID
        /// </summary>
        /// <param name="mid"></param>
        /// <returns>新增加的ID</returns>
        public static int addMnfo(MerchandiseInfoData mid)
        {
            int i = mi.insertMerchandiseType(mid);

            mid.ID = i;
            ls.Add(mid);
            return(i);
        }
        /// <summary>
        /// 根据用户的输入组成新类
        /// </summary>
        /// <returns></returns>
        private MerchandiseInfoData getMInfo()
        {
            MerchandiseInfoData mid = new MerchandiseInfoData();

            mid.Name     = this.txtName.Text;
            mid.TypeID   = ((MerchandiseTypeData)this.txtGenre.Tag).ID;
            mid.Quantity = Convert.ToInt32(this.txtQuantity.Text);
            return(mid);
        }
 private void lvMType_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (this.lvMType.SelectedItems.Count > 0)
     {
         ListViewItem        lvi = this.lvMType.SelectedItems[0];
         MerchandiseInfoData mid = (MerchandiseInfoData)lvi.Tag;
         this.txtName.Text     = mid.Name;
         this.txtGenre.Tag     = lvi.SubItems[1].Tag;
         this.txtGenre.Text    = lvi.SubItems[1].Text;
         this.txtQuantity.Text = mid.Quantity.ToString();
     }
 }
        /// <summary>
        /// 删除商品信息
        /// </summary>
        /// <param name="merType">商品信息类</param>
        /// <returns></returns>
        public int delMerchandiseType(MerchandiseInfoData merInfo)
        {
            SqlConnection conn = new SqlConnection(connStr);

            conn.Open();
            SqlCommand cmd = new SqlCommand("delete from MerchandiseInfo where id = @id", conn);

            cmd.Parameters.AddWithValue("@id", merInfo.ID);
            int i = cmd.ExecuteNonQuery();

            return(i);
        }
        /// <summary>
        /// 删除商品信息
        /// </summary>
        /// <param name="ptd">欲删除的类</param>
        public static void delMInfo(MerchandiseInfoData mid)
        {
            mi.delMerchandiseType(mid);
            int i;

            for (i = 0; i < ls.Count; i++)
            {
                if (mid.ID == ls[i].ID)
                {
                    ls.RemoveAt(i);
                    break;
                }
            }
        }
 /// <summary>
 /// 向PListView里插入一条记录
 /// </summary>
 /// <param name="pid"></param>
 /// <param name="id">对应记录ID存储在第三列Tag</param>
 private void addMInfo(MerchandiseInfoData mid)
 {
     try
     {
         ListViewItem lvi = new ListViewItem(mid.Name);
         lvi.Tag = mid;
         lvi.SubItems.Add(mid.Storage.ToString());
         this.lvMInfo.Items.Add(lvi);
     }
     catch (MessageException ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        /// <summary>
        /// 修改商品信息
        /// </summary>
        /// <param name="mtd">欲修改的类</param>
        /// <returns>返回所处集合的ID,对应ListView的项目位置</returns>
        public static int updMInfo(MerchandiseInfoData mid)
        {
            mi.updateMerchandiseType(mid);
            int i;

            for (i = 0; i < ls.Count; i++)
            {
                if (mid.ID == ls[i].ID)
                {
                    ls[i] = mid;
                    break;
                }
            }
            return(i);
        }
        /// <summary>
        /// 修改商品信息
        /// </summary>
        /// <param name="merType">商品信息类</param>
        /// <returns></returns>
        public int updateMerchandiseType(MerchandiseInfoData merInfo)
        {
            SqlConnection conn = new SqlConnection(connStr);

            conn.Open();
            SqlCommand cmd = new SqlCommand("update MerchandiseInfo set name = @name,TypeID = @typeID,Quantity=@Quantity,Storage=@Storage where id = @id", conn);

            cmd.Parameters.AddWithValue("@id", merInfo.ID);
            cmd.Parameters.AddWithValue("@name", merInfo.Name);
            cmd.Parameters.AddWithValue("@typeID", merInfo.TypeID);
            cmd.Parameters.AddWithValue("@Quantity", merInfo.Quantity);
            cmd.Parameters.AddWithValue("@Storage", merInfo.Storage);
            int i = Convert.ToInt32(cmd.ExecuteScalar());

            return(i);
        }
        //private int _iD;
        //private string _name;
        //private int _typeID;
        /// <summary>
        /// 插入商品信息
        /// </summary>
        /// <param name="merType">商品信息类</param>
        /// <returns></returns>
        public int insertMerchandiseType(MerchandiseInfoData merInfo)
        {
            SqlConnection conn = new SqlConnection(connStr);

            conn.Open();
            SqlCommand cmd = new SqlCommand("insert into MerchandiseInfo values(@name,@typeID,@Quantity,default)", conn);

            cmd.Parameters.AddWithValue("@name", merInfo.Name);
            cmd.Parameters.AddWithValue("@typeID", merInfo.TypeID);
            cmd.Parameters.AddWithValue("@Quantity", merInfo.Quantity);
            cmd.ExecuteNonQuery();
            cmd.CommandText = "select @@IDENTITY";
            int i = Convert.ToInt32(cmd.ExecuteScalar());

            conn.Close();
            return(i);
        }
Beispiel #13
0
 private void buttobtnAccessionn2_Click(object sender, EventArgs e)
 {
     try
     {
         checkText();
         MerchandiseInfoData mid = new MerchandiseInfoData();
         mid.Name     = this.txtName.Text;
         mid.TypeID   = ((MerchandiseTypeData)this.txtGenre.Tag).ID;
         mid.Quantity = Convert.ToInt32(this.txtQuantity.Text);
         mid.ID       = MInfoCortrol.addMnfo(mid);
         addMIinfo(mid);
         clear();
     }
     catch (MessageException ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Beispiel #14
0
        /// <summary>
        /// 增加或修改一条商品信息
        /// </summary>
        /// <param name="sid">商品</param>
        /// <param name="cortrol">1增加,2修改</param>
        private void addStoctInfo(StockInfoData sid, int cortrol)
        {
            MerchandiseInfoData mid = ((MerchandiseInfoData)MInfoCortrol.getMInfoOfID(sid.MID));
            ListViewItem        lvi = new ListViewItem(mid.Name);

            lvi.Tag = mid;
            lvi.SubItems.Add(sid.Quantity.ToString());
            lvi.SubItems.Add(sid.Price.ToString());
            lvi.SubItems.Add(Convert.ToString(sid.Quantity * (double)sid.Price));
            if (cortrol == 1)
            {
                this.lvSInfo.Items.Add(lvi);
            }
            else if (cortrol == 2)
            {
                this.lvSInfo.Items[this.lvSInfo.SelectedIndices[0]] = lvi;
            }
        }
        /// <summary>
        /// 查询商品信息
        /// </summary>
        /// <param name="merType">商品信息类</param>
        /// <returns>返回商品信息的集合</returns>
        public List <MerchandiseInfoData> selMerchandiseType()
        {
            List <MerchandiseInfoData> list = new List <MerchandiseInfoData>();
            SqlConnection  conn             = new SqlConnection(connStr);
            SqlDataAdapter sda = new SqlDataAdapter("select * from MerchandiseInfo", conn);
            DataSet        ds  = new DataSet();

            sda.Fill(ds);
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                MerchandiseInfoData mer = new MerchandiseInfoData();
                mer.ID       = (int)dr[0];
                mer.Name     = dr[1].ToString();
                mer.TypeID   = (int)dr[2];
                mer.Quantity = (int)dr[3];
                mer.Storage  = (int)dr[4];
                list.Add(mer);
            }
            return(list);
        }
        private void addMIinfo(MerchandiseInfoData mid)
        {
            try
            {
                ListViewItem lvi = new ListViewItem(mid.Name);
                lvi.Tag = mid;
                ListViewItem.ListViewSubItem lvs = new ListViewItem.ListViewSubItem();

                MerchandiseTypeData mtd = MTypeCortrol.getMTypeOfID(mid.TypeID);
                lvs.Text = mtd.Name;
                lvs.Tag  = mtd;

                lvi.SubItems.Add(lvs);
                lvi.SubItems.Add(mid.Quantity.ToString());
                this.lvMType.Items.Add(lvi);
            }
            catch (MessageException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void lvMInfo_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.lvPurvey.Items.Clear();
            if (this.lvMInfo.SelectedItems.Count == 0)
                return;
            MerchandiseInfoData mid = (MerchandiseInfoData)this.lvMInfo.SelectedItems[0].Tag;

            foreach (PurveyData pd in PurveyCortrol.ls)
            {
                if (pd.MInfoID == mid.ID)
                {
                    foreach (PurveyInfoData pid in PInfoCortrol.ls)
                    {
                        if (pid.ID == pd.PInfoID)
                        {
                            addPurevey(pid, pd);
                        }
                    }
                }
            }
        }
 public void refurbish()
 {
     this.lvHint.Items.Clear();
     foreach (PurveyData pd in PurveyCortrol.ls)
     {
         MerchandiseInfoData mid = MInfoCortrol.getMInfoOfID(pd.MInfoID);
         PurveyInfoData      pid = PInfoCortrol.getPInfoOfID(pd.PInfoID);
         if (mid.Quantity * pid.Days > mid.Storage)
         {
             ListViewItem lvi = new ListViewItem(mid.Name);
             lvi.Tag = pd;
             lvi.SubItems.Add(mid.Storage.ToString());
             lvi.SubItems.Add(mid.Quantity.ToString());
             lvi.SubItems.Add(pid.Name);
             lvi.SubItems.Add(pid.Days.ToString());
             int i = -((mid.Storage - (mid.Quantity * pid.Days)) / mid.Quantity);
             lvi.SubItems.Add(i.ToString());
             this.lvHint.Items.Add(lvi);
         }
     }
 }
        public StockInfoData showSelect(PurveyInfoData p, MerchandiseInfoData mid, string quantity, string price)
        {
            this.pid              = p;
            this.btnYes.Text      = "    修改";
            this.txtM.Text        = mid.Name;
            this.txtM.Tag         = mid;
            this.txtPrice.Text    = price;
            this.txtQuantity.Text = quantity;

            this.ShowDialog();
            if (ok == false)
            {
                throw new MessageException("");
            }

            StockInfoData sid = new StockInfoData();

            sid.MID      = ((MerchandiseInfoData)this.txtM.Tag).ID;
            sid.Quantity = Convert.ToInt32(this.txtQuantity.Text);
            sid.Price    = Convert.ToDouble(this.txtPrice.Text);
            return(sid);
        }
        private void lvHint_DoubleClick(object sender, EventArgs e)
        {
            if (this.lvHint.SelectedItems.Count == 0)
            {
                return;
            }
            ListViewItem        lvi = this.lvHint.SelectedItems[0];
            PurveyData          pd  = (PurveyData)lvi.Tag;
            MerchandiseInfoData mid = MInfoCortrol.getMInfoOfID(pd.MInfoID);

            foreach (TreeNode tn in this.mTypeTreeView.tvMType.Nodes)
            {
                selectNotes(tn, mid.TypeID);
            }
            foreach (ListViewItem lv in this.lvMInfo.Items)
            {
                if (lv.Tag == mid)
                {
                    lv.Selected = true;
                }
            }
        }