Пример #1
0
        //确认交班
        protected void Button1_Click(object sender, EventArgs e)
        {
            //将数据写入交班表里面
            Model.Shift_Exc model = new Model.Shift_Exc();
            // model.UserId = "";  登陆UserId
            if (ShiftDdl.SelectedIndex == 0)
            {
                MessageBox.Show(this, "请先选择交班班次");
                return;
            }

            //判断该天班次是否提交

            //string str = "where shift_id = '"+Convert.ToInt32(ShiftDdl.SelectedValue)+"'";

            string data = System.DateTime.Now.ToString("yyyy-MM-dd");

            /*and CONVERT(VARCHAR(100), shift_dateTime, 23) = '" + data + "'*/

            //userid 先写死
            string str = "where UserId = '" + UserNow.UserID + "' and shift_id = '" + Convert.ToInt32(ShiftDdl.SelectedValue) + "'";

            int count = seBll.GetRecordCount(str);

            if (count > 0)
            {
                MessageBox.Show(this, "当日班次已提交,请重新选择");
                return;
            }


            //从入账表里面获取该用户的所有收账记录,然后将记录循环新增到交班历史表中
            //获取Session["UserId"],先写死
            string strWhere = UserNow.UserID;
            //更新所有的账的是否交班状态
            DataSet ds = gaBll.GetSumInfo(strWhere);

            gaBll.Updatesis(strWhere);
            int Result = 0;

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                model.shift_id = Convert.ToInt32(ShiftDdl.SelectedValue);
                //model.shift_money = Convert.ToDecimal((Session["Sum"]));
                model.shift_state    = "已确认";
                model.shift_dateTime = System.DateTime.Now;
                model.ga_name        = row["ga_name"].ToString();
                model.ga_number      = row["ga_number"].ToString();
                model.ga_unit        = row["ga_unit"].ToString();
                if (row["ga_num"].ToString().Trim() == null || row["ga_num"].ToString().Trim() == "" || row["ga_num"].ToString().Trim() == " ")
                {
                    model.ga_num = 0;
                }
                else
                {
                    model.ga_num = Convert.ToInt32(row["ga_num"]);
                }
                if (row["ga_sum_price"] == null)
                {
                    model.ga_price = 0;
                }
                else
                {
                    model.ga_price = Convert.ToDecimal(row["ga_price"]);
                }
                model.ga_zffs_id = Convert.ToInt32(row["ga_zffs_id"]);
                model.ga_date    = Convert.ToDateTime(row["ga_date"]);
                model.ga_Type    = Convert.ToInt32(row["ga_Type"]);
                if (row["ga_sum_price"] == null)
                {
                    model.ga_sum_price = 0;
                }
                else
                {
                    model.ga_sum_price = Convert.ToDecimal(row["ga_sum_price"]);
                }
                model.ga_roomNumber = row["ga_roomNumber"].ToString();
                model.UserId        = Convert.ToInt32(UserNow.UserID);
                Result = seBll.Add(model);

                //修改是否交班状态
                int userid = Convert.ToInt32(Session["UserID"]);
                gaBll.Updatesis(userid.ToString());

                ////再删除入账表数据,再插入到历史表中

                //gaBll.ShiftDelete("1");
            }
            if (Result > 0)
            {
                // MessageBox.Show(this, "确认交班报表成功");
                ClientScript.RegisterStartupScript(GetType(), "message", "<script language='javascript'>alert('确认交班报表成功');</script>");
                isdis = 1;
            }

            MethPaySumDataBind();
            GridView2DataBind(pageSize, pageIndex);
        }