Exemplo n.º 1
0
        public static bool Update(DOPhanHoi doPhanhoi)
        {
            DataSet ds = HelpDB.getDatabase().LoadDataSet(string.Format(@"SELECT *
                FROM YEU_CAU_TRA_LOI WHERE ID = {0}", doPhanhoi.ID));
                ds.Tables[0].TableName = "YEU_CAU_TRA_LOI";
                FWDBService db = HelpDB.getDBService();
                DbTransaction dbTrans = FWTransaction.BeginTrans(db);
                FWTransaction fwTrans = new FWTransaction(db, dbTrans);
                ds.Tables[0].Rows[0]["NOI_DUNG"] = doPhanhoi.NOI_DUNG;
                ds.Tables[0].Rows[0]["NGAY_GUI"] = doPhanhoi.NGAY_GUI;
                ds.Tables[0].Rows[0]["NGUOI_GUI_ID"] = doPhanhoi.NGUOI_GUI_ID;
                ds.Tables[0].Rows[0]["NGUOI_NHAN_ID"] = doPhanhoi.NGUOI_NHAN_ID;
                try
                {
                    if (db.UpdateTable(ds, "YEU_CAU_TRA_LOI", dbTrans) <= 0)
                        return false;
                    else
                    {
                        bool flag = false;
                        if (doPhanhoi.DSTapTinDinhKem != null && doPhanhoi.DSTapTinDinhKem.Tables.Count > 0)
                        {
                           //DataSet DsLuuTruTapTin = doPhanhoi.DSTapTinDinhKem.Copy();//không copy được
                            DataSet DsLuuTruTapTin = doPhanhoi.DSTapTinDinhKem;
                            DataRow[] rows = doPhanhoi.DSTapTinDinhKem.Tables[0].Select("ID is null", "", DataViewRowState.Added);
                            List<long> taptinIDs = db.GetID("G_NGHIEP_VU", dbTrans, rows.Length);
                            int i = 0;
                            foreach (DataRow row in DsLuuTruTapTin.Tables[0].Rows)
                            {
                                if (row.RowState == DataRowState.Deleted) continue;
                                row["OBJECT_ID"] = doPhanhoi.ID;
                                row["TYPE_ID"] = (Int32)10;
                                row["TIEU_DE"] = row["TEN_FILE"];
                                if (row["ID"] is DBNull)
                                {
                                    row["TAP_TIN_ID"] = taptinIDs[i];
                                    row["ID"] = row["TAP_TIN_ID"];
                                    i++;
                                }
                            }
                            DataSet DsObjectTapTin = DsLuuTruTapTin.Copy();
                            DsObjectTapTin.Tables[0].TableName = "OBJECT_TAP_TIN";

                            DataSet DsLuuTruTapTinSource = new DataSet();
                            string sqlTaptin = string.Format(@"SELECT LT.*
                            FROM LUU_TRU_TAP_TIN LT
                            INNER JOIN OBJECT_TAP_TIN OBJ ON OBJ.TAP_TIN_ID=LT.ID
                            AND OBJ.TYPE_ID=10 AND OBJ.OBJECT_ID={0}", doPhanhoi.ID);
                            if (fwTrans.LoadDataSet(DsLuuTruTapTinSource, sqlTaptin, "LUU_TRU_TAP_TIN") == false)
                            {
                                FWTransaction.Rollback(dbTrans);
                                return false;
                            }
                            HelpDataSet.MergeDataSet(new string[] { "ID" }, DsLuuTruTapTinSource, DsLuuTruTapTin, true);

                            DataSet DsObjectTapTinSource = new DataSet();
                            string sqlObj = string.Format(@"SELECT OBJ.*
                            FROM OBJECT_TAP_TIN OBJ WHERE OBJ.TYPE_ID=10 AND OBJ.OBJECT_ID={0}", doPhanhoi.ID);
                            if (fwTrans.LoadDataSet(DsObjectTapTinSource, sqlObj, "OBJECT_TAP_TIN") == false)
                            {
                                FWTransaction.Rollback(dbTrans);
                                return false;
                            }
                            HelpDataSet.MergeTable(new string[] { "TAP_TIN_ID" }, DsObjectTapTinSource.Tables[0], DsObjectTapTin.Tables[0], true, true);
                            flag = db.UpdateDataSet(DsLuuTruTapTinSource, dbTrans);
                            if (flag == true)
                            {
                                foreach (DataRow r in DsObjectTapTinSource.Tables[0].Rows)
                                {
                                    DbCommand cmd1 = null;
                                    if (r.RowState == DataRowState.Added)
                                    {
                                        cmd1 = db.GetSQLStringCommand(string.Format(@"INSERT INTO OBJECT_TAP_TIN(TAP_TIN_ID,OBJECT_ID,TYPE_ID) VALUES({0},{1},10)", r["TAP_TIN_ID"], r["OBJECT_ID"], r["TYPE_ID"]));
                                    }
                                    if (cmd1 != null)
                                    {
                                        if (db.ExecuteNonQuery(cmd1, dbTrans) <= 0)
                                        {
                                            FWTransaction.Rollback(dbTrans);
                                            return false;
                                        }
                                    }
                                }
                            }
                        }
                        if (flag)
                        {
                            FWTransaction.Commit(dbTrans);
                            return true;
                        }
                        else
                        {
                            FWTransaction.Rollback(dbTrans);
                            return false;
                        }
                    }
                }
                catch
                {
                    FWTransaction.Rollback(dbTrans);
                    return false;
                }
        }
Exemplo n.º 2
0
        public static bool Insert(DOPhanHoi doPhanhoi)
        {
            string strSQL = "insert into YEU_CAU_TRA_LOI values(@id,@yeu_cau_id, @nguoi_gui_id, @nguoi_nhan_id, @ngay_gui, @noi_dung, @nguoi_cap_nhat_id, @ngay_cap_nhat)";

                FWDBService db = HelpDB.getDBService();
                DbCommand cmd = db.GetSQLStringCommand(strSQL);
                DbTransaction dbTrans = FWTransaction.BeginTrans(db);
                FWTransaction fwTrans = new FWTransaction(db, dbTrans);

                doPhanhoi.ID = HelpGen.DT();
                db.AddInParameter(cmd, "@id", DbType.Int64, doPhanhoi.ID);
                db.AddInParameter(cmd, "@yeu_cau_id", DbType.Int64, doPhanhoi.YEU_CAU_ID);

                db.AddInParameter(cmd, "@nguoi_gui_id", DbType.Int64, doPhanhoi.NGUOI_GUI_ID);

                db.AddInParameter(cmd, "@nguoi_nhan_id", DbType.String, doPhanhoi.NGUOI_NHAN_ID);

                db.AddInParameter(cmd, "@ngay_gui", DbType.DateTime, doPhanhoi.NGAY_GUI);
                db.AddInParameter(cmd, "@noi_dung", DbType.Binary, doPhanhoi.NOI_DUNG);
                db.AddInParameter(cmd, "@nguoi_cap_nhat_id", DbType.Int64, doPhanhoi.NGUOI_CAP_NHAT_ID);
                db.AddInParameter(cmd, "@ngay_cap_nhat", DbType.DateTime, doPhanhoi.NGAY_CAP_NHAT);
                try
                {
                    bool flag = false;
                    if (db.ExecuteNonQuery(cmd,dbTrans) > 0)
                    {
                        if (doPhanhoi.DSTapTinDinhKem != null && doPhanhoi.DSTapTinDinhKem.Tables.Count > 0)
                        {
                            DataSet DsLuuTruTapTin = doPhanhoi.DSTapTinDinhKem.Copy();

                            DataRow[] rows = doPhanhoi.DSTapTinDinhKem.Tables[0].Select("ID is null", "", DataViewRowState.Added);

                            List<long> taptinIDs = db.GetID("G_NGHIEP_VU", dbTrans, rows.Length);

                            int i = 0;
                            foreach (DataRow row in DsLuuTruTapTin.Tables[0].Rows)
                            {
                                if (row.RowState == DataRowState.Deleted) continue;
                                row["OBJECT_ID"] = doPhanhoi.ID;
                                row["TYPE_ID"] = (Int32)10;
                                row["TIEU_DE"] = row["TEN_FILE"];
                                if (row["ID"] is DBNull)
                                {
                                    row["TAP_TIN_ID"] = taptinIDs[i];
                                    row["ID"] = row["TAP_TIN_ID"];
                                    i++;
                                }
                            }
                            DataSet DsObjectTapTin = DsLuuTruTapTin.Copy();
                            DsObjectTapTin.Tables[0].TableName = "OBJECT_TAP_TIN";
                            DataSet DsLuuTruTapTinSource = new DataSet();
                            string sqlTaptin = string.Format(@"SELECT LT.*
                            FROM LUU_TRU_TAP_TIN LT
                            INNER JOIN OBJECT_TAP_TIN OBJ ON OBJ.TAP_TIN_ID=LT.ID
                            AND OBJ.TYPE_ID=10 AND OBJ.OBJECT_ID={0}", doPhanhoi.ID);
                            if (fwTrans.LoadDataSet(DsLuuTruTapTinSource, sqlTaptin, "LUU_TRU_TAP_TIN") == false)
                            {
                                FWTransaction.Rollback(dbTrans);
                                return false;
                            }
                            HelpDataSet.MergeDataSet(new string[] { "ID" }, DsLuuTruTapTinSource, DsLuuTruTapTin, true);

                            DataSet DsObjectTapTinSource = new DataSet();
                            string sqlObj = string.Format(@"SELECT OBJ.*
                            FROM OBJECT_TAP_TIN OBJ WHERE OBJ.TYPE_ID=10 AND OBJ.OBJECT_ID={0}", doPhanhoi.ID);
                            if (fwTrans.LoadDataSet(DsObjectTapTinSource, sqlObj, "OBJECT_TAP_TIN") == false)
                            {
                                FWTransaction.Rollback(dbTrans);
                                return false;
                            }
                            HelpDataSet.MergeTable(new string[] { "TAP_TIN_ID" }, DsObjectTapTinSource.Tables[0], DsObjectTapTin.Tables[0], true, true);
                            flag = db.UpdateDataSet(DsLuuTruTapTinSource, dbTrans);
                            if (flag == true)
                            {
                                foreach (DataRow r in DsObjectTapTinSource.Tables[0].Rows)
                                {
                                    DbCommand cmd1 = null;
                                    if (r.RowState == DataRowState.Added)
                                    {
                                        cmd1 = db.GetSQLStringCommand(string.Format(@"INSERT INTO OBJECT_TAP_TIN(TAP_TIN_ID,OBJECT_ID,TYPE_ID) VALUES({0},{1},10)", r["TAP_TIN_ID"], r["OBJECT_ID"], r["TYPE_ID"]));
                                    }
                                    if (cmd1 != null)
                                    {
                                        if (db.ExecuteNonQuery(cmd1, dbTrans) <= 0)
                                        {
                                            FWTransaction.Rollback(dbTrans);
                                            return false;
                                        }
                                    }
                                }
                            }
                        }
                        if (flag)
                        {
                            FWTransaction.Commit(dbTrans);
                            return true;
                        }
                        else {
                            FWTransaction.Rollback(dbTrans);
                            return false;
                        }
                    }
                    return false;
                }
                catch
                {
                    FWTransaction.Rollback(dbTrans);
                    return false;
                }
        }
Exemplo n.º 3
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (IsValidate())
            {
                //try...catch dùng trong TH người dùng chọn định dạng giờ của hệ thống trong đó có chứa "t"(AM/PM)
                try
                {
                    System.Convert.ToDateTime(lblThoiGianGui.Text);
                }
                catch {
                    lblThoiGianGui.Text += "M";
                }

                List<long> lstUser = new List<long>(NguoiNhanEmail._SelectedIDs);
                DataTable dt = new DataTable();
                string title = "";
                //Thêm người hỗ trợ vào danh sách gửi mail trong trường hợp ko chọn
                foreach (long id in NguoiHoTro._SelectedIDs)
                    if (!lstUser.Contains(id))
                        lstUser.Add(id);
                //----------------------
                if (IsAdd == true && AfterAddReplySuccesfully == null)
                {
                    try
                    {
                        title = "Có yêu cầu hỗ trợ mới được cập nhật";
                        if (DAYeuCau.Insert(out _YEU_CAU_ID, FrameworkParams.currentUser.employee_id, System.Convert.ToDateTime(lblThoiGianGui.Text), NguoiHoTro._SelectedStrIDs, PLTinhtrang._getSelectedID(), PLLoaiYeuCau._getSelectedID(), PLMucuutien._getSelectedID()
                            , txtChude.Text, NoiDung._getValue(), plMultiChoiceFiles1._DataSource))
                            HelpXtraForm.CloseFormNoConfirm(this);
                    }
                    catch
                    {
                        ErrorMsg.ErrorSave(this);
                    }
                }
                //Save in case ReplySupport.
                else if (IsAdd == true && AfterAddReplySuccesfully != null)
                {
                    DateTime currentDate = HelpDB.getDatabase().GetSystemCurrentDateTime();
                    DOPhanHoi doPhanHoi = new DOPhanHoi(_YEU_CAU_ID, FrameworkParams.currentUser.employee_id,NguoiHoTro._SelectedStrIDs , currentDate, NoiDung._getValue(), FrameworkParams.currentUser.employee_id, currentDate);
                    doPhanHoi.DSTapTinDinhKem = plMultiChoiceFiles1._DataSource;
                    if (DAPhanHoi.Insert(doPhanHoi))
                    {
                        title = "Có phản hồi yêu cầu hỗ trợ mới được cập nhật";
                        HelpXtraForm.CloseFormNoConfirm(this);
                        AfterAddReplySuccesfully(doPhanHoi);
                        //Update status of Support
                        DAYeuCau.UpdateTinhTrangYeuCau(_YEU_CAU_ID, PLTinhtrang._getSelectedID());
                        if (AfterUpdateStatusOfSupport != null) AfterUpdateStatusOfSupport(PLTinhtrang._getSelectedID(), null);
                    }
                    else
                        ErrorMsg.ErrorSave(this);

                }
                else if (IsAdd == false)
                {
                    if (AfterAddReplySuccesfully == null && AfterUpdateReplySuccesfully == null)
                    {
                        title = "Có yêu cầu hỗ trợ mới được cập nhật";
                        DOYeuCau doYeuCau = new DOYeuCau(this._YEU_CAU_ID, FrameworkParams.currentUser.employee_id
                            , NguoiHoTro._SelectedStrIDs, PLLoaiYeuCau._getSelectedID()
                            , HelpNumber.ParseInt32(PLMucuutien._getSelectedID())
                            , txtChude.Text.ToString(), NoiDung._getValue(), System.Convert.ToDateTime(lblThoiGianGui.Text), FrameworkParams.currentUser.employee_id, DateTime.Now, HelpNumber.ParseInt32(PLTinhtrang._getSelectedID()));
                        if (DAYeuCau.Update(this._YEU_CAU_ID, NguoiHoTro._SelectedStrIDs, PLTinhtrang._getSelectedID(), PLLoaiYeuCau._getSelectedID(), PLMucuutien._getSelectedID(), txtChude.Text, NoiDung._getValue(), plMultiChoiceFiles1._DataSource))
                        {
                            if (this.RefreshAfterInsert != null) this.RefreshAfterInsert(doYeuCau);
                            if (AfterUpdateSupportSuccesfully != null) AfterUpdateSupportSuccesfully(doYeuCau);
                            if (AfterUpdateStatusOfSupport != null) AfterUpdateStatusOfSupport(PLTinhtrang._getSelectedID()
                                , new object[]{PLLoaiYeuCau._getSelectedID(),txtChude.Text
                                    ,PLMucuutien._getSelectedID(),NguoiHoTro._SelectedStrIDs,System.Convert.ToDateTime(lblThoiGianGui.Text)});
                            HelpXtraForm.CloseFormNoConfirm(this);
                        }
                        else ErrorMsg.ErrorSave(this);
                    }
                    else
                    {
                        DateTime currentDate = HelpDB.getDatabase().GetSystemCurrentDateTime();
                        DOPhanHoi doPhanHoi = new DOPhanHoi(_YEU_CAU_ID, FrameworkParams.currentUser.employee_id, NguoiHoTro._SelectedStrIDs, currentDate, NoiDung._getValue(), FrameworkParams.currentUser.employee_id, currentDate);
                        doPhanHoi.ID = _YEU_CAU_TL_ID;
                        doPhanHoi.DSTapTinDinhKem = plMultiChoiceFiles1._DataSource;
                        if (DAPhanHoi.Update(doPhanHoi))
                        {
                            title = "Có phản hồi yêu cầu hỗ trợ mới được cập nhật";
                            HelpXtraForm.CloseFormNoConfirm(this);
                            doPhanHoi.DSTapTinDinhKem = plMultiChoiceFiles1._DataSource;
                            if (AfterUpdateReplySuccesfully != null) AfterUpdateReplySuccesfully(doPhanHoi);
                            //Update status of Support
                            DAYeuCau.UpdateTinhTrangYeuCau(_YEU_CAU_ID, PLTinhtrang._getSelectedID());
                            if (AfterUpdateStatusOfSupport != null) AfterUpdateStatusOfSupport(PLTinhtrang._getSelectedID(), null);
                        }
                        else ErrorMsg.ErrorSave(this);
                    }
                }
                //Gửi mail
                if (lstUser.Count > 0 )
                {
                    AddressList To = new AddressList();

                    title = HelpStringBuilder.GetTitleMailNewPageper(title);
                    StringBuilder Subject = new StringBuilder();
                    IDataReader reader = FWDBService.LoadRecord("DM_LOAI_YEU_CAU", "ID", this.PLLoaiYeuCau._getSelectedID());
                    using (reader)
                    {
                        if (reader.Read())
                        {
                            Subject.Append(string.Format(PLConst.DES_MAIL_YCHT, txtChude.Text, reader["NAME"].ToString(), lblNguoiGui.Text, NoiDung.richEditControl.HtmlText));
                        }
                    }
                    if (!lstUser.Contains(FrameworkParams.currentUser.employee_id))
                        lstUser.Add(FrameworkParams.currentUser.employee_id);
                    To = HelpZPLOEmail.GetAddressList(lstUser.ToArray());
                    HelpZPLOEmail.SendSmartHost(
                        HelpAutoOpenForm.GeneratingCodeFromForm(this, _YEU_CAU_ID),
                        title, null, To, null, null, Subject.ToString(), "");
                }
                //-----------------------------------------
            }
        }