Пример #1
0
 private void AssignImageToGrid()
 {
     for (int i = 0; i <= gvDesign.Rows.Count - 1; i++)
     {
         DataGridViewImageCell         _IC   = gvDesign.Rows[i].Cells["StatusImage"] as DataGridViewImageCell;
         Atend.Base.Design.DDesignFile dfile = Atend.Base.Design.DDesignFile.SelectByDesignId(Convert.ToInt32(gvDesign.Rows[i].Cells["ID"].Value.ToString()));
         if (dfile.Id == -1)
         {
             _IC.Value = new Bitmap(Atend.Control.Common.fullPath + @"\Icon\Equip16.png");
             gvDesign.Refresh();
         }
         else
         {
             _IC.Value = new Bitmap(Atend.Control.Common.fullPath + @"\Icon\HaveFile.png");
             gvDesign.Refresh();
         }
     }
 }
Пример #2
0
        private void AssignImageToGrid()
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            for (int i = 0; i <= gvDesign1.Rows.Count - 1; i++)
            {
                DataGridViewImageCell         _IC1  = gvDesign1.Rows[i].Cells["imgFile"] as DataGridViewImageCell;
                DataGridViewImageCell         _IC2  = gvDesign1.Rows[i].Cells["imgBook"] as DataGridViewImageCell;
                DataGridViewImageCell         _IC3  = gvDesign1.Rows[i].Cells["imgDwf"] as DataGridViewImageCell;
                Atend.Base.Design.DDesignFile dfile = Atend.Base.Design.DDesignFile.SelectByDesignId(Convert.ToInt32(gvDesign1.Rows[i].Cells["ID"].Value.ToString()));
                //ed.WriteMessage("ID={0}\n", dfile.Id);

                if (dfile.Id == -1)
                {
                    //ed.WriteMessage("Have Not File\n");
                    _IC1.Value = new Bitmap(Atend.Control.Common.fullPath + @"\Icon\Equip16.png");
                    gvDesign1.Refresh();
                    _IC2.Value = new Bitmap(Atend.Control.Common.fullPath + @"\Icon\Equip16.png");
                    gvDesign1.Refresh();
                    _IC3.Value = new Bitmap(Atend.Control.Common.fullPath + @"\Icon\Equip16.png");
                    gvDesign1.Refresh();
                    gvDesign1.RefreshEdit();
                }
                else
                {
                    if (dfile.File.Length > 0)
                    {
                        _IC1.Value = new Bitmap(Atend.Control.Common.fullPath + @"\Icon\HaveFile.png");//file
                        //ed.WriteMessage("1\n");
                        gvDesign1.Refresh();
                    }
                    else
                    {
                        _IC1.Value = new Bitmap(Atend.Control.Common.fullPath + @"\Icon\Equip16.png");
                        //ed.WriteMessage("2\n");

                        gvDesign1.Refresh();
                    }

                    if (dfile.Book.Length > 0)
                    {
                        _IC2.Value = new Bitmap(Atend.Control.Common.fullPath + @"\Icon\PDF.jpg");//book
                        gvDesign1.Refresh();
                    }
                    else
                    {
                        _IC2.Value = new Bitmap(Atend.Control.Common.fullPath + @"\Icon\Equip16.png");
                        gvDesign1.Refresh();
                    }


                    if (dfile.Image.Length > 0)
                    {
                        _IC3.Value = new Bitmap(Atend.Control.Common.fullPath + @"\Icon\Excel.png");//dwf
                        gvDesign1.Refresh();
                    }
                    else
                    {
                        _IC3.Value = new Bitmap(Atend.Control.Common.fullPath + @"\Icon\Equip16.png");
                        gvDesign1.Refresh();
                    }
                    gvDesign1.Refresh();
                }
            }
            gvDesign1.RefreshEdit();
        }
Пример #3
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
        }
Пример #4
0
        /// <summary>
        /// طرح جدید بدون پشتیبان
        /// </summary>
        private void NewDesignWithoutPoshtiban(OleDbConnection aConnection, OleDbTransaction aTransaction, SqlConnection sConnection, SqlTransaction sTransaction)
        {
            Autodesk.AutoCAD.EditorInput.Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            //طرح کد نداره و در پشتیبان طرحی نداره پی یک طرح جدید تولید می کنیم
            ed.WriteMessage("@@@@ 1\n");
            DataTable dtWorkOrder = Atend.Base.Design.DPackage.AccessWorkOrders(aTransaction, aConnection);

            Atend.Base.Design.DDesignProfile currentDesignProfile = Atend.Base.Design.DDesignProfile.AccessSelect(aTransaction, aConnection);
            Atend.Base.Design.DDesign        currentDesign        = new Atend.Base.Design.DDesign();
            currentDesign.Title     = currentDesignProfile.DesignName;
            currentDesign.ArchiveNo = currentDesignProfile.DesignCode;
            currentDesign.PRGCode   = 0;
            ed.WriteMessage("@@@@ 2\n");
            currentDesign.RequestType = 0;
            currentDesign.Region      = Convert.ToByte(Atend.Base.Base.BRegion.SelectByCodeLoacal(currentDesignProfile.Zone).SecondCode);
            currentDesign.IsAtend     = true;
            currentDesign.Address     = currentDesignProfile.Address;
            ed.WriteMessage("@@@@ 3\n");
            if (!currentDesign.Insert(sTransaction, sConnection))
            {
                ed.WriteMessage("@@@@ 4\n");
                throw new System.Exception("currentDesign.Insert 1");
            }
            ed.WriteMessage("@@@@ 5\n");
            foreach (DataRow drWorkOrder in dtWorkOrder.Rows)
            {
                Atend.Base.Design.DWorkOrder WO = new Atend.Base.Design.DWorkOrder();
                WO.DesignID  = currentDesign.Id;
                WO.WorkOrder = Convert.ToInt32(drWorkOrder["WorkOrderCode"].ToString());
                if (!WO.Insert(sTransaction, sConnection))
                {
                    throw new System.Exception("WorkOrder.Insert Failed 1");
                }
            }

            ed.WriteMessage("@@@@ 6\n");
            currentDesignProfile.DesignId = currentDesign.Id;
            if (!currentDesignProfile.AccessUpdate(aTransaction, aConnection))
            {
                throw new System.Exception("currentDesignProfile.AccessUpdate 1");
            }

            ed.WriteMessage("@@@@ 7\n");
            Atend.Base.Design.DDesignFile currentDesignFile = new Atend.Base.Design.DDesignFile();
            currentDesignFile.DesignId = currentDesign.Id;
            currentDesignFile.File     = new byte[0];


            ed.WriteMessage("@@@@ 8\n");
            #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);
            currentDesignFile.File = br.ReadBytes((Int32)br.BaseStream.Length);
            fs.Dispose();
            #endregion

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

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

            ed.WriteMessage("@@@@ 11\n");

            if (!currentDesignFile.Insert(sTransaction, sConnection))
            {
                throw new System.Exception("currentDesignFile.Insert 1");
            }
            ed.WriteMessage("@@@@ 12\n");
            if (!currentDesignProfile.Insert(sTransaction, sConnection))
            {
                throw new System.Exception("currentDesignProfile.Insert 1");
            }
            ed.WriteMessage("@@@@ 13\n");
            #region StatusReport
            Atend.Global.Utility.UOtherOutPut Output = new Atend.Global.Utility.UOtherOutPut();
            ed.WriteMessage("@@@@ 13.1\n");
            Atend.Report.dsSagAndTension ds = Output.FillStatusReport();
            ed.WriteMessage("@@@@ 13.2\n");
            Atend.Base.Design.DStatusReport.DeleteByDesignId(currentDesignProfile.DesignId);
            ed.WriteMessage("@@@@ 14,{0}\n", ds.Tables["StatusReport"].Rows.Count);
            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");
                }
                ed.WriteMessage("@@@@ 15\n");
            }
            #endregion
        }
Пример #5
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (Validation())
            {
                AllowToClose = true;
                long PRGCode = Atend.Base.Design.DDesign.SelectByID(Convert.ToInt32(gvDesign.Rows[gvDesign.CurrentRow.Index].Cells["Id"].Value.ToString())).PRGCode;
                int  ID      = Convert.ToInt32(gvDesign.Rows[gvDesign.CurrentRow.Index].Cells["Id"].Value.ToString());
                Atend.Control.Common.DesignId = ID;
                string Destination = "";
                if (txtFilePath.Text.LastIndexOf(@"\") == txtFilePath.Text.Length - 1)
                {
                    //Destination = string.Format(@"{0}{1}", txtFilePath.Text, ID);
                    Destination = string.Format(@"{0}{1}", txtFilePath.Text, PRGCode);
                }
                else
                {
                    //Destination = string.Format(@"{0}\{1}", txtFilePath.Text, ID);
                    Destination = string.Format(@"{0}\{1}", txtFilePath.Text, PRGCode);
                }
                Atend.Base.Design.DDesignFile df1 = Atend.Base.Design.DDesignFile.SelectByDesignId(ID);
                if (df1.Id != -1 && df1.File != null)
                {
                    //ed.WriteMessage("____OPEN\n");
                    try
                    {
                        //ed.WriteMessage("________3\n");
                        if (df1.File != null)
                        {
                            if (Directory.Exists(Destination))
                            {
                                Directory.Delete(Destination, true);
                            }

                            //Atend.Control.Common.DesignName = ID + ".DWG";
                            Atend.Control.Common.DesignName = PRGCode + ".DWG";

                            Atend.Control.Common.Edition = gvDesign.Rows[gvDesign.CurrentRow.Index].Cells[5].Value.ToString();
                            //Atend.Control.Common.DesignFullAddress = string.Format(@"{0}\{1}", txtFilePath.Text, ID);
                            Atend.Control.Common.DesignFullAddress = string.Format(@"{0}\{1}", txtFilePath.Text, PRGCode);
                            //Atend.Control.Common.AccessPath = string.Format(@"{0}\{1}", Atend.Control.Common.DesignFullAddress, ID + ".MDB");
                            Atend.Control.Common.AccessPath = string.Format(@"{0}\{1}", Atend.Control.Common.DesignFullAddress, PRGCode + ".MDB");

                            Directory.CreateDirectory(Destination);
                            Stream st = new MemoryStream();
                            //st = File.Create(string.Format(@"{0}\{1}.ATNX", Destination, ID));
                            st = File.Create(string.Format(@"{0}\{1}.ATNX", Destination, PRGCode));

                            BinaryWriter binWriter = new BinaryWriter(st);
                            binWriter.Write((byte[])df1.File);
                            binWriter.Close();
                        }
                    }
                    catch (System.Exception ex)
                    {
                        ed.WriteMessage("OPEN ERROR : {0} \n", ex.Message);
                    }
                }
                else
                {
                    //ed.WriteMessage("____NEW\n");
                    string DesignFile   = string.Format(@"{0}\DesignFile\AtendEmpty.dwg", Atend.Control.Common.fullPath);
                    string DatabaseFile = string.Format(@"{0}\DatabaseFile\AtendLocal.mdb", Atend.Control.Common.fullPath);
                    if (File.Exists(DesignFile) && File.Exists(DatabaseFile))
                    {
                        try
                        {
                            if (Directory.Exists(Destination))
                            {
                                Directory.Delete(Destination, true);
                            }
                            //string dis = Destination + string.Format(@"\{0}.ATNX", ID);
                            string dis = Destination + string.Format(@"\{0}.ATNX", PRGCode);

                            Directory.CreateDirectory(Destination);
                            //File.Copy(DesignFile, string.Format(@"{0}\{1}.DWG", Destination, ID));
                            //File.Copy(DatabaseFile, string.Format(@"{0}\{1}.MDB", Destination, ID));

                            File.Copy(DesignFile, string.Format(@"{0}\{1}.DWG", Destination, PRGCode));
                            File.Copy(DatabaseFile, string.Format(@"{0}\{1}.MDB", Destination, PRGCode));

                            Atend.Global.Acad.DrawinOperation dOperation = new Atend.Global.Acad.DrawinOperation();
                            //dOperation.AddFileToAtendFile(dis, string.Format(@"{0}\{1}.DWG", Destination, ID));
                            //dOperation.AddFileToAtendFile(dis, string.Format(@"{0}\{1}.MDB", Destination, ID));

                            dOperation.AddFileToAtendFile(dis, string.Format(@"{0}\{1}.DWG", Destination, PRGCode));
                            dOperation.AddFileToAtendFile(dis, string.Format(@"{0}\{1}.MDB", Destination, PRGCode));

                            //File.SetAttributes(string.Format(@"{0}\{1}.DWG", Destination, ID), FileAttributes.Normal);
                            File.SetAttributes(string.Format(@"{0}\{1}.DWG", Destination, PRGCode), FileAttributes.Normal);


                            //Atend.Control.Common.DesignName = ID + ".DWG";
                            Atend.Control.Common.DesignName = PRGCode + ".DWG";

                            Atend.Control.Common.Edition = gvDesign.Rows[gvDesign.CurrentRow.Index].Cells[5].Value.ToString();
                            //Atend.Control.Common.DesignFullAddress = string.Format(@"{0}\{1}", txtFilePath.Text, ID);
                            Atend.Control.Common.DesignFullAddress = string.Format(@"{0}\{1}", txtFilePath.Text, PRGCode);

                            //Atend.Control.Common.AccessPath = string.Format(@"{0}\{1}", Atend.Control.Common.DesignFullAddress, ID + ".MDB");
                            Atend.Control.Common.AccessPath = string.Format(@"{0}\{1}", Atend.Control.Common.DesignFullAddress, PRGCode + ".MDB");
                        }
                        catch (System.Exception ex)
                        {
                            ed.WriteMessage("NEW ERROR : {0} \n", ex.Message);
                        }
                    }
                }// end for new
            }
            else
            {
                AllowToClose = false;
            }
        }
Пример #6
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;
            }
        }