Пример #1
0
        private string pay_getid()
        {
            string xuhao = "", id = "", san = "", housan = "";
            int    hs = 0, h = 0;
            string xh3 = "";

            DBCL.DBEntities dbc   = new DBCL.DBEntities();
            var             model = dbc.pays.Select(m => m);

            try
            {
                foreach (var item in model)
                {
                    xuhao  = item.pay_id;
                    housan = xuhao.Substring(xuhao.Length - 3, 3);
                    hs     = Convert.ToInt32(housan);
                    if (hs > h)
                    {
                        h = hs;
                    }
                }
            }
            catch { }


            if (xuhao == "")
            {
                xh3 = "001";
            }
            else
            {
                xh3 = set_housan(h);
            }

            string data = DateTime.Today.ToString("yyyyMMdd");

            id = "FK" + data + san + xh3;
            return(id);
        }
Пример #2
0
        private void j_submit_Click(object sender, EventArgs e)
        {
            //变量*************************************************************
            int    length = j_d.Rows.Count;
            int    k = 0;
            string name = "", unit = "", price = "";

            //校验
            if (length == 1)
            {
                MessageBox.Show("请输入数据");
                return;
            }
            for (int i = 0; i < length - 1; i++)
            {
                k = i + 1;
                if (j_d.Rows[i].Cells[1].Value == null && j_d.Rows[i].Cells[3].Value == null)
                {
                    continue;
                }
                //判断名称不为空,数据库是否存在,如存在则继续,不存在
                if (j_d.Rows[i].Cells[1].Value == null)
                {
                    MessageBox.Show("第" + k + "行名称不能为空");
                    return;
                }
                name = Convert.ToString(j_d.Rows[i].Cells[1].Value);
                //判断数量是否为空,是否为正整数
                if (j_d.Rows[i].Cells[2].Value == null)
                {
                    MessageBox.Show("第" + k + "行数量不能为空");
                    return;
                }

                if (Validator.IsNumStr(Convert.ToString(j_d.Rows[i].Cells[2].Value)) == false)
                {
                    MessageBox.Show("第" + k + "行数量不是正整数或超出10位");
                    return;
                }
                try {
                    DBCL.DBEntities dbcd     = new DBCL.DBEntities();
                    var             wa_model = dbcd.warehouses.FirstOrDefault(m => m.warehouse_name.IndexOf(name) >= 0);
                    decimal         shuliang = Convert.ToDecimal(j_d.Rows[i].Cells[2].Value);
                    if (wa_model.warehouse_number - shuliang < 0)
                    {
                        MessageBox.Show("第" + k + "行库存不足");
                        return;
                    }
                }
                catch { MessageBox.Show("仓库不存在"); }

                //判断单位是否为空,是否与数据库该商品单位相同,不相同则返回报错
                if (j_d.Rows[i].Cells[3].Value == null)
                {
                    MessageBox.Show("第" + k + "行单位不能为空");
                    return;
                }
                name = Convert.ToString(j_d.Rows[i].Cells[1].Value);
                unit = Convert.ToString(j_d.Rows[i].Cells[3].Value);
                var w_model = db.warehouses.Select(m => m);
                w_model = w_model.Where(m => m.warehouse_name == name);
                string dunit = "";
                foreach (var item in w_model)
                {
                    dunit = item.warehouse_unit;
                }
                if (dunit != "")
                {
                    if (dunit != unit)
                    {
                        MessageBox.Show("第" + k + "行单位错误应为:" + dunit);
                        return;
                    }
                }


                //判断单价是否为空,是否为保留两位小数,或整数
                if (j_d.Rows[i].Cells[4].Value == null)
                {
                    MessageBox.Show("第" + k + "行单价不能为空");
                    return;
                }
                price = Convert.ToString(j_d.Rows[i].Cells[4].Value);
                if (Validator.IsNumber2(price) == false)
                {
                    MessageBox.Show("第" + k + "行单价必须是正整数或两位以内小数");
                    return;
                }
            }

            //判断供货商是否为空,提示并返回
            if (j_source.Text.Trim() == "")
            {
                MessageBox.Show("请输入供货商");
                return;
            }

            //*****************************************************************************
            try
            {
                if (j_delete() == false)
                {
                    return;
                }
                if (jh_tijiao() == false)
                {
                    return;
                }
                panxiu = false;
            }
            catch
            {
                MessageBox.Show("更新失败");
            }
            MessageBox.Show("更新成功");
            Action handler = CloseWindow;

            if (handler != null)
            {
                handler();
            }
            this.Close();
        }