Esempio n. 1
0
        protected void btnRun_Click(object sender, EventArgs e)
        {
            btnRun.Attributes["onclick"] = this.GetPostBackEventReference(this.btnRun) + ";this.disabled=true;this.value='处理中...'";
            string id = CommadMethod.getNextId("GID" + DateTime.Now.ToString("yyyyMMdd"), "");

            txtMNo.BackColor = Color.White;
            SelectCommandBuilder s = new SelectCommandBuilder(constr, "");
            string sql             = "select count(*) from goods_tran where goods_no=(select DISTINCT  goods_name from goods_tmp where goods_id = '" + ViewState["id"].ToString() + "')";
            string sql1            = "select count(*) from goods_tmp where goods_name = '" + txtgoodsName.Text.Trim().ToUpper() + "' and version = '" + txtVersion.Text.Trim().ToUpper().ToUpper() + "'";
            string sql2            = "select count(*) from materials where name = '" + txtMNo.Text.Trim().ToUpper() + "'";
            string sql3            = "select count(*) from goods_chage_record where goods_name='" + txtgoodsName.Text.Trim().ToUpper() + "' and version = '" + txtVersion.Text.Trim().ToUpper().ToUpper() + "'";
            int    count           = Convert.ToInt32(s.ExecuteScalar(sql));
            int    count1          = Convert.ToInt32(s.ExecuteScalar(sql1));
            int    count2          = Convert.ToInt32(new SelectCommandBuilder().ExecuteScalar(sql2));
            int    count3          = Convert.ToInt32(s.ExecuteScalar(sql3));
            int    i = 0;

            if (count2 == 0)
            {
                Response.Write("<script>alert('材料编号不存在,请确认后再试!')</script>");
                txtMNo.BackColor = Color.Red;
                txtMNo.Focus();
                return;
            }
            if (count3 != 0)
            {
                Response.Write("<script>alert('该部品已经被发行!')</script>");
                return;
            }
            if (count1 == 0)
            {
                InsertData("goods_tmp", id);
                hifId.Value = id;
            }
            if (count != 0)
            {
                //UpdateData("goods_tran");
                new DeleteCommandBuilder(constr, "").ExecuteNonQuery("delete from goods_tran where goods_no = '" + txtgoodsName.Text.Trim().ToUpper() + "'");
                InsertData("goods_tran", hifId.Value.Trim());
            }
            else
            {
                InsertData("goods_tran", hifId.Value.Trim());
            }
            UpdateCommandBuilder u = new UpdateCommandBuilder(constr, "goods_tran");

            u.UpdateColumn("isConfirm", "Waiting");
            u.ConditionsColumn("goods_no", txtgoodsName.Text.Trim().ToUpper());
            u.getUpdateCommand();
            i = Convert.ToInt32(u.ExecuteNonQuery());
            if (i != 0)
            {
                InsertData("goods_chage_record", hifId.Value.Trim());
                new UpdateCommandBuilder(constr, "").ExecuteNonQuery("update goods_tmp set lb8_id = '1'");
                Response.Write("<script>alert('发行成功')</script>");
                dgvList.DataSource = getConfirmGoodsList(ViewState["id"].ToString());
                dgvList.DataBind();
                string _body = "部番:" + txtgoodsName.Text + " 版本:" + txtVersion.Text.Trim() + " 已发行成功," + "<a href='http://192.168.1.199:81/GoodsManager/Goods_Aprove.aspx'>点击此链接快速审核...</a>";
                SendMail.ExecuteSendMail(smtpIp, Port, fromUser, fromPwd, mailList, ccList, "部品发行成功通知", _body, "", "");
            }
            else
            {
                Response.Write("<script>alert('发行失败')</script>");
            }
        }
        protected void btnVerify_Click(object sender, EventArgs e)
        {
            try
            {
                List <CrushedMaterial> cmList  = new List <CrushedMaterial>();
                List <string>          sqlList = new List <string>();
                if (dgvList.Rows.Count != 0 && checkVerifyInput())
                {
                    for (int i = 0; i < dgvList.Rows.Count; i++)
                    {
                        if ((dgvList.Rows[i].Cells[0].FindControl("cboCheckItem") as CheckBox).Checked == true)
                        {
                            CrushedMaterial c = new CrushedMaterial()
                            {
                                id         = int.Parse((dgvList.Rows[i].Cells[0].FindControl("Hfid") as HiddenField).Value),
                                Name       = (dgvList.Rows[i].Cells[1].FindControl("Label1") as Label).Text,
                                MaterialNo = (dgvList.Rows[i].Cells[2].FindControl("Label2") as Label).Text,
                                Material   = (dgvList.Rows[i].Cells[3].FindControl("Label3") as Label).Text,
                                JigLeader  = (dgvList.Rows[i].Cells[4].FindControl("Label4") as Label).Text,
                                addtime    = (dgvList.Rows[i].Cells[5].FindControl("Label5") as Label).Text
                            };
                            cmList.Add(c);
                        }
                    }
                    if (cmList.Count == 0)
                    {
                        Response.Write("<script>alert('没有选择任何行!')</script>");
                        return;
                    }
                    string        body = "部番:";
                    List <string> bd   = new List <string>();
                    string        list = "";
                    for (int i = 0; i < cmList.Count; i++)
                    {
                        if (i != cmList.Count - 1)
                        {
                            body += cmList[i].Name + ",";
                            list += cmList[i].JigLeader + ";";
                        }
                        else
                        {
                            body += cmList[i].Name;
                            list += cmList[i].JigLeader;
                        }

                        UpdateCommandBuilder up = new UpdateCommandBuilder(ConnectionFactory.ConnectionString_hudsonwwwroot, "trymolde");
                        up.UpdateColumn("isApprove", ddlVerify.SelectedItem.Text);
                        up.UpdateColumn("ApprovedDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                        up.UpdateColumn("Reason", txtReason.Text.Trim());
                        if (string.IsNullOrEmpty(txtReason.Text.Trim()))
                        {
                            up.UpdateColumn("area1style", "Wait");
                            up.UpdateColumn("area2style", "Wait");
                            up.UpdateColumn("area3style", "Wait");
                            up.UpdateColumn("area4style", "Wait");
                        }
                        up.ConditionsColumn("id", cmList[i].id);
                        sqlList.Add(up.getUpdateCommand());
                    }
                    if (ddlVerify.SelectedItem.Text == "NG")
                    {
                        body    += "审核未通过,原因为:" + txtReason.Text;
                        mailList = getUserMailAddress(list);
                    }
                    else
                    {
                        bd.Add(body + "审核已通过!" + "   <a href='" + url + "?status=Wait&&area=1'>点击此链接开始进行粉碎...</a>");
                        bd.Add(body + "审核已通过!" + "   <a href='" + url + "?status=Wait&&area=2'>点击此链接开始进行粉碎...</a>");
                        bd.Add(body + "审核已通过!" + "   <a href='" + url + "?status=Wait&&area=3'>点击此链接开始进行粉碎...</a>");
                        bd.Add(body + "审核已通过!" + "   <a href='" + url + "?status=Wait&&area=4'>点击此链接开始进行粉碎...</a>");
                    }
                    InsertCommandBuilder ins = new InsertCommandBuilder(ConnectionFactory.ConnectionString_hudsonwwwroot, "trymolde");
                    int count = ins.ExcutTransaction(sqlList);
                    if (count != 0)
                    {
                        Response.Write("<script>alert('审核成功!')</script>");
                        if (mailList != "")
                        {
                            if (ddlVerify.SelectedItem.Text == "NG")
                            {
                                SendMail.ExecuteSendMail(smtpIp, Port, fromUser, fromPwd, mailList, "", "试作品粉碎审核通告(系统邮件,请勿回复!)", body, "", "");
                            }
                            else
                            {
                                for (int i = 0; i <= 3; i++)
                                {
                                    SendMail.ExecuteSendMail(smtpIp, Port, fromUser, fromPwd, ConfigurationManager.AppSettings["area" + (i + 1)].ToString(), "", "试作品粉碎审核通告(系统邮件,请勿回复!)", bd[i], "", "");
                                }
                            }
                        }

                        dgvList.DataSource = getAllCrushedMaterial();
                        dgvList.DataBind();
                        //Response.Write("<script>alert('" + s + "!')</script>");
                    }
                    else
                    {
                        Response.Write("<script>alert('审核失败!')</script>");
                    }
                }
            }
            catch (Exception ex)
            {
                Response.Write("<script>alert('" + ex.Message + "!')</script>");;
            }
        }