コード例 #1
0
        /// <summary>
        /// طرح پشتیبان
        /// </summary>
        private void PoshtibanDesign(OleDbConnection aConnection, OleDbTransaction aTransaction, SqlConnection sConnection, SqlTransaction sTransaction)
        {
            Autodesk.AutoCAD.EditorInput.Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            DataTable dtWorkOrder = Atend.Base.Design.DPackage.AccessWorkOrders(aTransaction, aConnection);

            Atend.Base.Design.DDesignProfile _DDesignProfile      = Atend.Base.Design.DDesignProfile.SelectByDesignID(sTransaction, sConnection, Atend.Control.Common.DesignId);
            Atend.Base.Design.DDesign        _DDesign             = Atend.Base.Design.DDesign.SelectByID(sTransaction, sConnection, Atend.Control.Common.DesignId);
            Atend.Base.Design.DDesignFile    _DDesignFile         = Atend.Base.Design.DDesignFile.SelectByDesignId(sTransaction, sConnection, Atend.Control.Common.DesignId);
            Atend.Base.Design.DDesignProfile currentDesignProfile = Atend.Base.Design.DDesignProfile.AccessSelect(aTransaction, aConnection);

            if (_DDesignProfile.Id != -1)
            {
                if (currentDesignProfile.DesignId != -1)
                {
                    if (!currentDesignProfile.UpdateByDesignId(sTransaction, sConnection))
                    {
                        throw new System.Exception("currentDesignProfile.Update 4");
                    }
                }
                else
                {
                    throw new System.Exception("DDesignProfile access record was not found");
                }
            }
            else
            {
                if (currentDesignProfile.DesignId != -1)
                {
                    if (!currentDesignProfile.Insert(sTransaction, sConnection))
                    {
                        throw new System.Exception("currentDesignProfile.Insert 5");
                    }
                }
            }

            #region design
            _DDesign.Region = Convert.ToByte(Atend.Base.Base.BRegion.SelectByCodeLoacal(currentDesignProfile.Zone).SecondCode);
            if (!_DDesign.Update(sTransaction, sConnection))
            {
                throw new System.Exception("_DDesign.Update ");
            }
            #endregion

            #region DesignFile
            _DDesignFile.DesignId = Atend.Control.Common.DesignId;
            _DDesignFile.File     = new byte[0];

            #region ATNX file
            FileStream fs;
            fs = new FileStream(string.Format(@"{0}\{1}", Atend.Control.Common.DesignFullAddress, Atend.Control.Common.DesignName.Replace(".DWG", ".ATNX")), FileMode.Open);
            BinaryReader br = new BinaryReader(fs);
            _DDesignFile.File = br.ReadBytes((Int32)br.BaseStream.Length);
            fs.Dispose();
            #endregion

            #region PDF file
            if (txtBookAddress.Text != string.Empty)
            {
                fs = new FileStream(txtBookAddress.Text, FileMode.Open);
                br = new BinaryReader(fs);
                _DDesignFile.Book = br.ReadBytes((Int32)br.BaseStream.Length);
                fs.Dispose();
            }
            else
            {
                _DDesignFile.Book = new byte[0];
            }
            #endregion

            #region DWF file
            if (txtBookAddress.Text != string.Empty)
            {
                fs = new FileStream(txtDWFAddress.Text, FileMode.Open);
                br = new BinaryReader(fs);
                _DDesignFile.Image = br.ReadBytes((Int32)br.BaseStream.Length);
                fs.Dispose();
            }
            else
            {
                _DDesignFile.Image = new byte[0];
            }
            #endregion


            if (_DDesignFile.Id != -1)
            {
                if (!_DDesignFile.Update(sTransaction, sConnection))
                {
                    throw new System.Exception("NewDesignFile.Insert 5");
                }
            }
            else
            {
                if (!_DDesignFile.Insert(sTransaction, sConnection))
                {
                    throw new System.Exception("CurrentDesignFile.Update 4");
                }
            }
            #endregion

            #region StatusReport
            Atend.Global.Utility.UOtherOutPut Output = new Atend.Global.Utility.UOtherOutPut();
            Atend.Report.dsSagAndTension      ds     = Output.FillStatusReport();
            Atend.Base.Design.DStatusReport.DeleteByDesignId(currentDesignProfile.DesignId);
            for (int i = 0; i < ds.Tables["StatusReport"].Rows.Count; i++)
            {
                Atend.Base.Design.DStatusReport STR = new Atend.Base.Design.DStatusReport();
                STR.DesignId = currentDesignProfile.DesignId;
                if (Atend.Control.NumericValidation.Int32Converter(ds.Tables["StatusReport"].Rows[i]["Code"].ToString()))
                {
                    STR.ProductCode = Convert.ToInt32(ds.Tables["StatusReport"].Rows[i]["Code"].ToString());
                }
                else
                {
                    STR.ProductCode = 0;
                }

                DataTable ExTbl = Atend.Base.Base.BEquipStatus.SelectAllX();
                STR.Existance = Convert.ToInt32(ExTbl.Select("Name = '" + ds.Tables["StatusReport"].Rows[i]["Exist"].ToString() + "'")[0]["ACode"].ToString());
                int pc = Convert.ToInt32(ds.Tables["StatusReport"].Rows[i]["ProjectCode"]);
                //int pc = Atend.Base.Base.BProjectCode.AccessSelectByCode(Convert.ToInt32(Table.Rows[i]["ProjectCode"].ToString())).AdditionalCode;
                STR.ProjectCode = pc;
                ds.Tables["StatusReport"].Rows[i]["ProjectCode"] = pc;
                ds.Tables["StatusReport"].Rows[i]["Count"]       = Math.Round(Convert.ToDouble(ds.Tables["StatusReport"].Rows[i]["Count"].ToString()), 2);
                STR.Count = Convert.ToDouble(ds.Tables["StatusReport"].Rows[i]["Count"].ToString());
                if (!STR.Insert(sTransaction, sConnection))
                {
                    ed.WriteMessage("\nError In D_StatusReport Insertion\n");
                }
            }
            #endregion

            #region WorkOrder
            if (Atend.Base.Design.DWorkOrder.Delete(Atend.Control.Common.DesignId, sTransaction, sConnection))
            {
                foreach (DataRow drWorkOrder in dtWorkOrder.Rows)
                {
                    Atend.Base.Design.DWorkOrder WO = new Atend.Base.Design.DWorkOrder();
                    WO.DesignID  = Atend.Control.Common.DesignId;;
                    WO.WorkOrder = Convert.ToInt32(drWorkOrder["WorkOrderCode"].ToString());
                    if (!WO.Insert(sTransaction, sConnection))
                    {
                        throw new System.Exception("WorkOrder.Insert Failed 5");
                    }
                }
            }
            #endregion
        }
コード例 #2
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            Autodesk.AutoCAD.EditorInput.Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            if (Validation())
            {
                Atend.Base.Design.NodeTransaction _NodeTransaction = new Atend.Base.Design.NodeTransaction();

                SqlConnection  sConnection  = null;
                SqlTransaction sTransaction = null;

                OleDbTransaction aTransaction = null;
                OleDbConnection  aConnection  = null;

                try
                {
                    if (_NodeTransaction.CreateTransactionAndConnection(out sTransaction, out sConnection, out aTransaction, out aConnection, false))
                    {
                        Atend.Control.Common.DesignId = Atend.Base.Design.DDesignProfile.AccessSelect(aTransaction, aConnection).DesignId;
                        if (Atend.Control.Common.DesignId == 0)
                        {
                            if (MessageBox.Show("آیا طرح در پشتیبان تعریف شده است", "ذخیره سازی طرح", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                            {
                                //طرح کد نداره ولی در پشتیبان است  پس به پشتیبان اختصاص می دهیم
                                ed.WriteMessage("~~~ No design Id  and is Poshtiban file ~~~\n");
                                if (gvDesign.SelectedRows.Count > 0)
                                {
                                    if (chkIsComplement.Checked)
                                    {
                                        //Is Postiban and is complement
                                        ed.WriteMessage("~~~ is complement ~~~\n");
                                        Atend.Base.Design.DDesign currentDessign = Atend.Base.Design.DDesign.SelectByID(sTransaction, sConnection, Convert.ToInt32(gvDesign.SelectedRows[0].Cells["Id"].Value));
                                        if (currentDessign.Id != -1)
                                        {
                                            DataTable Designs = Atend.Base.Design.DDesign.SelectByCode(sTransaction, sConnection, currentDessign.Code);
                                            if (Designs.Rows.Count > 0)
                                            {
                                                DataView dv = new DataView(Designs);
                                                dv.Sort = "RequestType";
                                                Atend.Base.Design.DDesign NewDesign = Atend.Base.Design.DDesign.SelectByID(sTransaction, sConnection, Convert.ToInt32(dv.Table.Rows[0]["Id"].ToString()));
                                                if (NewDesign.Id != -1)
                                                {
                                                    NewDesign.RequestType++;
                                                    if (!NewDesign.Insert(sTransaction, sConnection))
                                                    {
                                                        throw new System.Exception("NewDesign.Insert 2");
                                                    }

                                                    Atend.Base.Design.DDesignProfile currentProfile = Atend.Base.Design.DDesignProfile.AccessSelect(aTransaction, aConnection);
                                                    if (currentProfile.DesignId != -1)
                                                    {
                                                        currentProfile.DesignId = NewDesign.Id;
                                                        if (!currentProfile.AccessUpdate(aTransaction, aConnection))
                                                        {
                                                            throw new System.Exception("currentProfile.AccessUpdate 2");
                                                        }

                                                        Atend.Base.Design.DDesignFile NewDesignFile = new Atend.Base.Design.DDesignFile();
                                                        NewDesignFile.DesignId = NewDesign.Id;
                                                        NewDesignFile.File     = null;
                                                        FileStream fs;
                                                        fs = new FileStream(string.Format(@"{0}\{1}", Atend.Control.Common.DesignFullAddress, Atend.Control.Common.DesignName.Replace(".DWG", ".ATNX")), FileMode.Open);
                                                        BinaryReader br = new BinaryReader(fs);
                                                        NewDesignFile.File = br.ReadBytes((Int32)br.BaseStream.Length);
                                                        fs.Dispose();
                                                        if (!NewDesignFile.Insert(sTransaction, sConnection))
                                                        {
                                                            throw new System.Exception("NewDesignFile.Insert 2");
                                                        }

                                                        if (!currentProfile.Insert(sTransaction, sConnection))
                                                        {
                                                            throw new System.Exception("currentProfile.Insert 2");
                                                        }
                                                        MessageBox.Show("Well done 2");
                                                    }
                                                }
                                            }
                                        }////////
                                    }
                                    else
                                    {
                                        //Is Poshtiban and is not complement
                                        ed.WriteMessage("~~~ is not complement ~~~\n");
                                        Atend.Base.Design.DDesignFile CurrentDesignFile = Atend.Base.Design.DDesignFile.SelectByDesignId(sTransaction, sConnection, Convert.ToInt32(gvDesign.SelectedRows[0].Cells["Id"].Value));
                                        if (CurrentDesignFile.Id != -1)
                                        {
                                            ed.WriteMessage("~~~  have file ~~~\n");
                                            Atend.Base.Design.DDesignProfile currentDesignProfile = Atend.Base.Design.DDesignProfile.AccessSelect(aTransaction, aConnection);
                                            if (currentDesignProfile.DesignId != -1)
                                            {
                                                currentDesignProfile.DesignId = Convert.ToInt32(gvDesign.SelectedRows[0].Cells["Id"].Value);
                                                if (!currentDesignProfile.AccessUpdate(aTransaction, aConnection))
                                                {
                                                    throw new System.Exception("currentDesignProfile.AccessUpdate 6");
                                                }

                                                CurrentDesignFile.File = null;
                                                FileStream fs;
                                                fs = new FileStream(string.Format(@"{0}\{1}", Atend.Control.Common.DesignFullAddress, Atend.Control.Common.DesignName.Replace(".DWG", ".ATNX")), FileMode.Open);
                                                BinaryReader br = new BinaryReader(fs);
                                                CurrentDesignFile.File = br.ReadBytes((Int32)br.BaseStream.Length);
                                                fs.Dispose();
                                                if (!CurrentDesignFile.Update(sTransaction, sConnection))
                                                {
                                                    throw new System.Exception("CurrentDesignFile.Update 6");
                                                }


                                                if (!currentDesignProfile.UpdateByDesignId(sTransaction, sConnection))
                                                {
                                                    throw new System.Exception("currentDesignProfile.Update 6");
                                                }
                                                MessageBox.Show("well done 6");
                                            }
                                        }
                                        else
                                        {
                                            ed.WriteMessage("~~~ does not have file ~~~\n");
                                            Atend.Base.Design.DDesignProfile currentDesignProfile = Atend.Base.Design.DDesignProfile.AccessSelect(aTransaction, aConnection);
                                            if (currentDesignProfile.DesignId != -1)
                                            {
                                                currentDesignProfile.DesignId = Convert.ToInt32(gvDesign.SelectedRows[0].Cells["Id"].Value);
                                                if (!currentDesignProfile.AccessUpdate(aTransaction, aConnection))
                                                {
                                                    throw new System.Exception("currentDesignProfile.AccessUpdate 5");
                                                }

                                                Atend.Base.Design.DDesignFile NewDesignFile = new Atend.Base.Design.DDesignFile();
                                                NewDesignFile.DesignId = Convert.ToInt32(gvDesign.SelectedRows[0].Cells["Id"].Value);
                                                NewDesignFile.File     = null;
                                                FileStream fs;
                                                fs = new FileStream(string.Format(@"{0}\{1}", Atend.Control.Common.DesignFullAddress, Atend.Control.Common.DesignName.Replace(".DWG", ".ATNX")), FileMode.Open);
                                                BinaryReader br = new BinaryReader(fs);
                                                NewDesignFile.File = br.ReadBytes((Int32)br.BaseStream.Length);
                                                fs.Dispose();
                                                if (!NewDesignFile.Insert(sTransaction, sConnection))
                                                {
                                                    throw new System.Exception("NewDesignFile.Insert 5");
                                                }


                                                if (!currentDesignProfile.Insert(sTransaction, sConnection))
                                                {
                                                    throw new System.Exception("currentDesignProfile.Insert 5");
                                                }

                                                MessageBox.Show("well done 5");
                                            }
                                        }
                                    }
                                }
                            }
                            else /////////////////////////////////////////////////////////////////////////////////
                            {
                                //طرح کد نداره و در پشتیبان طرحی نداره پی یک طرح جدید تولید می کنیم
                                ed.WriteMessage("~~~ No design Id  and is atend file ~~~\n");
                                Atend.Base.Design.DDesignProfile currentDesignProfile = Atend.Base.Design.DDesignProfile.AccessSelect(aTransaction, aConnection);
                                Atend.Base.Design.DDesign        currentDesign        = new Atend.Base.Design.DDesign();
                                currentDesign.Code           = 0;
                                currentDesign.Title          = currentDesignProfile.DesignName;
                                currentDesign.ArchiveNo      = currentDesignProfile.DesignCode;
                                currentDesign.PRGCode        = 0;
                                currentDesign.RequestType    = 0;
                                currentDesign.AdditionalCode = 0;
                                if (!currentDesign.Insert(sTransaction, sConnection))
                                {
                                    throw new System.Exception("currentDesign.Insert 1");
                                }

                                currentDesignProfile.DesignId = currentDesign.Id;
                                if (!currentDesignProfile.AccessUpdate(aTransaction, aConnection))
                                {
                                    throw new System.Exception("currentDesignProfile.AccessUpdate 1");
                                }

                                Atend.Base.Design.DDesignFile currentDesignFile = new Atend.Base.Design.DDesignFile();
                                currentDesignFile.DesignId = currentDesign.Id;
                                currentDesignFile.File     = null;
                                FileStream fs;
                                fs = new FileStream(string.Format(@"{0}\{1}", Atend.Control.Common.DesignFullAddress, Atend.Control.Common.DesignName.Replace(".DWG", ".ATNX")), FileMode.Open);
                                BinaryReader br = new BinaryReader(fs);
                                currentDesignFile.File = br.ReadBytes((Int32)br.BaseStream.Length);
                                fs.Dispose();
                                if (!currentDesignFile.Insert(sTransaction, sConnection))
                                {
                                    throw new System.Exception("currentDesignFile.Insert 1");
                                }

                                if (!currentDesignProfile.Insert(sTransaction, sConnection))
                                {
                                    throw new System.Exception("currentDesignProfile.Insert 1");
                                }

                                MessageBox.Show("Well Done 1");
                            }
                        }
                        else////////////////////////////////////// ALL DESIGN HAVE DESIGN ID ///////////////////////////////////////
                        {
                            //means Design has DesignId
                            MessageBox.Show(Atend.Control.Common.DesignId.ToString());
                            if (chkIsComplement.Checked)
                            {
                                //means design is complement
                                Atend.Base.Design.DDesign currentDessign = Atend.Base.Design.DDesign.SelectByID(sTransaction, sConnection, Atend.Control.Common.DesignId);
                                if (currentDessign.Id != -1)
                                {
                                    DataTable Designs = Atend.Base.Design.DDesign.SelectByCode(sTransaction, sConnection, currentDessign.Code);
                                    if (Designs.Rows.Count > 0)
                                    {
                                        DataView dv = new DataView(Designs);
                                        dv.Sort = "RequestType";
                                        Atend.Base.Design.DDesign NewDesign = Atend.Base.Design.DDesign.SelectByID(sTransaction, sConnection, Convert.ToInt32(dv.Table.Rows[0]["Id"].ToString()));
                                        if (NewDesign.Id != -1)
                                        {
                                            NewDesign.RequestType++;
                                            if (!NewDesign.Insert(sTransaction, sConnection))
                                            {
                                                throw new System.Exception("NewDesign.Insert 3");
                                            }

                                            Atend.Base.Design.DDesignProfile currentProfile = Atend.Base.Design.DDesignProfile.AccessSelect(aTransaction, aConnection);
                                            if (currentProfile.DesignId != -1)
                                            {
                                                currentProfile.DesignId = NewDesign.Id;
                                                if (!currentProfile.AccessUpdate(aTransaction, aConnection))
                                                {
                                                    throw new System.Exception("currentProfile.AccessUpdate 3");
                                                }

                                                Atend.Base.Design.DDesignFile NewDesignFile = new Atend.Base.Design.DDesignFile();
                                                NewDesignFile.DesignId = NewDesign.Id;
                                                NewDesignFile.File     = null;
                                                FileStream fs;
                                                fs = new FileStream(string.Format(@"{0}\{1}", Atend.Control.Common.DesignFullAddress, Atend.Control.Common.DesignName.Replace(".DWG", ".ATNX")), FileMode.Open);
                                                BinaryReader br = new BinaryReader(fs);
                                                NewDesignFile.File = br.ReadBytes((Int32)br.BaseStream.Length);
                                                fs.Dispose();
                                                if (!NewDesignFile.Insert(sTransaction, sConnection))
                                                {
                                                    throw new System.Exception("NewDesignFile.Insert 3");
                                                }

                                                if (!currentProfile.Insert(sTransaction, sConnection))
                                                {
                                                    throw new System.Exception("currentProfile.Insert 3");
                                                }
                                                MessageBox.Show("Well done 3");
                                            }
                                        }
                                    }
                                }////////
                            }
                            else
                            {
                                //means design is not complement
                                Atend.Base.Design.DDesignFile CurrentDesignFile = Atend.Base.Design.DDesignFile.SelectByDesignId(sTransaction, sConnection, Atend.Control.Common.DesignId);
                                if (CurrentDesignFile.Id != -1)
                                {
                                    ed.WriteMessage("~~~  have file ~~~\n");
                                    Atend.Base.Design.DDesignProfile currentDesignProfile = Atend.Base.Design.DDesignProfile.AccessSelect(aTransaction, aConnection);
                                    if (currentDesignProfile.DesignId != -1)
                                    {
                                        CurrentDesignFile.File = null;
                                        FileStream fs;
                                        fs = new FileStream(string.Format(@"{0}\{1}", Atend.Control.Common.DesignFullAddress, Atend.Control.Common.DesignName.Replace(".DWG", ".ATNX")), FileMode.Open);
                                        BinaryReader br = new BinaryReader(fs);
                                        CurrentDesignFile.File = br.ReadBytes((Int32)br.BaseStream.Length);
                                        fs.Dispose();
                                        if (!CurrentDesignFile.Update(sTransaction, sConnection))
                                        {
                                            throw new System.Exception("CurrentDesignFile.Update 4");
                                        }

                                        if (!currentDesignProfile.UpdateByDesignId(sTransaction, sConnection))
                                        {
                                            throw new System.Exception("currentDesignProfile.Update 4");
                                        }
                                        MessageBox.Show("well done 4");
                                    }
                                    else
                                    {
                                        throw new System.Exception("DDesignProfile access record was not found");
                                    }
                                }
                                else
                                {
                                    ed.WriteMessage("~~~ does not have file ~~~\n");
                                    Atend.Base.Design.DDesignProfile currentDesignProfile = Atend.Base.Design.DDesignProfile.AccessSelect(aTransaction, aConnection);
                                    if (currentDesignProfile.DesignId != -1)
                                    {
                                        Atend.Base.Design.DDesignFile NewDesignFile = new Atend.Base.Design.DDesignFile();
                                        NewDesignFile.DesignId = Atend.Control.Common.DesignId;
                                        NewDesignFile.File     = null;
                                        FileStream fs;
                                        fs = new FileStream(string.Format(@"{0}\{1}", Atend.Control.Common.DesignFullAddress, Atend.Control.Common.DesignName.Replace(".DWG", ".ATNX")), FileMode.Open);
                                        BinaryReader br = new BinaryReader(fs);
                                        NewDesignFile.File = br.ReadBytes((Int32)br.BaseStream.Length);
                                        fs.Dispose();
                                        if (!NewDesignFile.Insert(sTransaction, sConnection))
                                        {
                                            throw new System.Exception("NewDesignFile.Insert 5");
                                        }

                                        if (!currentDesignProfile.Insert(sTransaction, sConnection))
                                        {
                                            throw new System.Exception("currentDesignProfile.Insert 5");
                                        }

                                        MessageBox.Show("well done 4-2");
                                    }
                                }
                            }
                        }
                    }

                    aTransaction.Commit();
                    sTransaction.Commit();

                    aConnection.Close();
                    sConnection.Close();
                }
                catch
                {
                    aTransaction.Rollback();
                    sTransaction.Rollback();

                    aConnection.Close();
                    sConnection.Close();


                    ed.WriteMessage("ERROR WHILE SAVE FILE ON SERVER");
                    //AllowToClose = false;
                }
                DataTable dt = Atend.Base.Design.DDesign.SelectAll();
                gvDesign.AutoGenerateColumns = false;
                gvDesign.DataSource          = dt;
            }
            else
            {
                AllowToClose = false;
            }
        }