private void btnAdd_Click(object sender, EventArgs e)
        {
            BindingCollection <View_S_GoodsEnteringBill> tempList = dataGridView1.DataSource as BindingCollection <View_S_GoodsEnteringBill>;
            View_S_GoodsEnteringBill tempLnq = new View_S_GoodsEnteringBill();

            if (txtName.Text.Trim().Length == 0)
            {
                MessageDialog.ShowPromptMessage("物品名称不能为空");
                return;
            }

            tempLnq.单据号 = txtSDBNo.Text;

            tempLnq.图号型号   = txtCode.Text.ToUpper().Trim();
            tempLnq.图号型号   = StapleFunction.DeleteSpace(tempLnq.图号型号);
            tempLnq.物品名称   = txtName.Text.Trim();
            tempLnq.物品名称   = tempLnq.物品名称.Replace('(', '(');
            tempLnq.物品名称   = tempLnq.物品名称.Replace(')', ')');
            tempLnq.规格     = txtSpec.Text.Trim();
            tempLnq.单位     = cmbUnit.Text;
            tempLnq.材料类别   = txtDepot.Text;
            tempLnq.材料类别编码 = txtDepot.Tag.ToString();
            tempLnq.备注     = txtRemark.Text.Trim();

            try
            {
                foreach (View_S_GoodsEnteringBill item in tempList)
                {
                    if (item.图号型号 == tempLnq.图号型号 && item.物品名称 == tempLnq.物品名称 && item.规格 == tempLnq.规格)
                    {
                        throw new Exception("已存在于当前列表中,无法重复添加");
                    }
                }

                CheckString(tempLnq.物品名称);
                m_serverGoodsEntering.CheckGoodsInfo(tempLnq);
            }
            catch (Exception ex)
            {
                MessageDialog.ShowPromptMessage(ex.Message);
                return;
            }

            tempList.Add(tempLnq);
            RefreshDataGridView(m_listGoodsEntering);
            ClearInfo();
        }
Пример #2
0
        /// <summary>
        /// 检测物品信息
        /// </summary>
        /// <param name="goodsInfo">物品信息</param>
        /// <returns>存在返回True,否则返回False</returns>
        public void CheckGoodsInfo(View_S_GoodsEnteringBill goodsInfo)
        {
            DepotManagementDataContext ctx = CommentParameter.DepotDataContext;

            var varData = from a in ctx.F_GoodsPlanCost
                          where a.GoodsCode == goodsInfo.图号型号 &&
                          a.GoodsName == goodsInfo.物品名称 &&
                          a.Spec == goodsInfo.规格
                          select a;

            if (varData.Count() > 0)
            {
                throw new Exception("存在相同物品,无法录入");
            }
            else
            {
                if (goodsInfo.图号型号.Length > 0)
                {
                    varData = from a in ctx.F_GoodsPlanCost
                              where a.GoodsCode == goodsInfo.图号型号 &&
                              a.IsDisable == false
                              select a;

                    if (varData.Count() > 0)
                    {
                        foreach (var item in varData)
                        {
                            if (item.GoodsName == goodsInfo.物品名称)
                            {
                                return;
                            }
                        }

                        throw new Exception("存在相同【图号型号】的物品必须【物品名称】相同,如需录入请用【规格】区分,否则无法录入");
                    }
                }
            }
        }
        private void btnModify_Click(object sender, EventArgs e)
        {
            if (dataGridView1.CurrentRow == null)
            {
                return;
            }

            View_S_GoodsEnteringBill tempLnq = new View_S_GoodsEnteringBill();

            if (txtName.Text.Trim().Length == 0)
            {
                MessageDialog.ShowPromptMessage("物品名称不能为空");
                return;
            }

            tempLnq.单据号 = txtSDBNo.Text;

            tempLnq.图号型号   = txtCode.Text.ToUpper().Trim();
            tempLnq.图号型号   = StapleFunction.DeleteSpace(tempLnq.图号型号);
            tempLnq.物品名称   = txtName.Text.Trim();
            tempLnq.物品名称   = tempLnq.物品名称.Replace('(', '(');
            tempLnq.物品名称   = tempLnq.物品名称.Replace(')', ')');
            tempLnq.规格     = txtSpec.Text.Trim();
            tempLnq.单位     = cmbUnit.Text;
            tempLnq.材料类别   = txtDepot.Text;
            tempLnq.材料类别编码 = txtDepot.Tag.ToString();
            tempLnq.备注     = txtRemark.Text.Trim();

            dataGridView1.CurrentRow.Cells["图号型号"].Value = txtCode.Text.Trim();

            #region 2016-11-22, 夏石友, 增加了去除全角、半角空格的功能
            dataGridView1.CurrentRow.Cells["物品名称"].Value = StapleFunction.DeleteSpace(txtName.Text.Trim());
            dataGridView1.CurrentRow.Cells["规格"].Value   = StapleFunction.DeleteSpace(txtSpec.Text.Trim());
            #endregion

            dataGridView1.CurrentRow.Cells["材料类别"].Value   = txtDepot.Text;
            dataGridView1.CurrentRow.Cells["材料类别编码"].Value = txtDepot.Tag;
            dataGridView1.CurrentRow.Cells["单位"].Value     = cmbUnit.Text;
            dataGridView1.CurrentRow.Cells["备注"].Value     = txtRemark.Text.Trim();


            try
            {
                CheckString(tempLnq.物品名称);
                m_serverGoodsEntering.CheckGoodsInfo(tempLnq);

                dataGridView1.CurrentRow.Cells["图号型号"].Value   = tempLnq.图号型号;
                dataGridView1.CurrentRow.Cells["物品名称"].Value   = tempLnq.物品名称;
                dataGridView1.CurrentRow.Cells["规格"].Value     = tempLnq.规格;
                dataGridView1.CurrentRow.Cells["材料类别"].Value   = tempLnq.材料类别;
                dataGridView1.CurrentRow.Cells["材料类别编码"].Value = tempLnq.材料类别编码;
                dataGridView1.CurrentRow.Cells["单位"].Value     = tempLnq.单位;
                dataGridView1.CurrentRow.Cells["备注"].Value     = tempLnq.备注;
            }
            catch (Exception ex)
            {
                MessageDialog.ShowPromptMessage(ex.Message);
                return;
            }

            ClearInfo();
        }